Reputation: 27
That's my code
<EditFormSettings PopUpSettings-Width="500" EditFormType="Template">
<FormTemplate>
<asp:DropDownList ID="Status" DataSourceID="TerminalStatusDTS" DataValueField="STATUS_ID" DataTextField="STATUS_NAME" runat="server" Width="175px" ></asp:DropDownList>
</FormTemplate>
My question is how can I make Status
invisible in the e.commandName=RadGrid.InitInsertCommandName onItemCommand
event ?
Upvotes: 1
Views: 1324
Reputation: 464
EditForm is different for each row of RadGrid. First you have to get the row index of the row being edited and get a reference to the Edit form. Then you can findControl inside the edit form. A sample code could be the following:
if (e.CommandName == RadGrid.InitInsertCommandName)
{
RadGrid radgrid = (RadGrid)sender;
int rowindex = e.Item.RowIndex;
GridEditFormItem item = radgrid.MasterTableView.GetItems(GridItemType.EditFormItem)[rowindex] as GridEditFormItem;
DropDownList statusDropDownList = (DropDownList)item.FindControl("Status");
statusDropDownList.Visible = false;
}
But, it is possible that this is not exactly what you need. I mean when the page is having a postback on the ItemCommand the status dropdownlist would be visible and I think you just need to hide the control when you click the Insert command (Different behavour on Update and Insert).
So you can access the DropDownList and hide it on ItemCreated event or ItemDataBound event.
For example:
void rad_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditFormInsertItem)
{
DropDownList statusDropDownList = (DropDownList)e.Item.FindControl("Status");
statusDropDownList.Visible = false;
}
}
Upvotes: 1