开发者

How to Bind a data member to Drop DownList when Using RadGrid control?

开发者 https://www.devze.com 2023-04-11 15:39 出处:网络
I have a RadGrid control and I\'m defining the Edit Form for it. I have added a text box to bind data to as below which works fine:

I have a RadGrid control and I'm defining the Edit Form for it.

I have added a text box to bind data to as below which works fine:

<asp:TextBox ID="tbAuthenticationMode" runat="server" Text='<%# Bind("AuthenticationMode") %>' CssClass="tbAuthenticationMode">
                                    </asp:开发者_运维问答TextBox>

Now, I'd like to remove this text box and replace it with a simple drop down list as below:

 <asp:DropDownList ID="ddlAuthenticationMode" runat="server">
                                    <asp:ListItem Text="Windows Authentication" Value="Windows"></asp:ListItem>
                                    <asp:ListItem Text="SQL Server Authentication" Value="SqlServer"></asp:ListItem>
                                    </asp:DropDownList>

What I'd like to happen is that the "AuthenticatioMode" value to be bound to this drop down list.

How would it be possible?

Thanks


You must first override the RadGrid's ItemCreated event. Then check if the event's item editable and en edit mode. Then you can bind data to it. Here's a code sample:

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
   if (e.Item is GridEditableItem && e.Item.IsInEditMode)
   {
      GridEditFormItem geiEditedItem = e.Item as GridEditFormItem;
      geiEditedItem.Visible = true;

      //Edit mode
      if (e.Item.DataItem is YourClass)
      {
         YourClass currentItem = (YourClass)e.Item.DataItem;

         DropDownList ddlAuthenticationMode= geiEditedItem.FindControl("ddlAuthenticationMode") as DropDownList;
         ddlAuthenticationMode.SelectedValue = currentItem.AuthenticatioMode.ToString();
      }
   }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号