How do you read the chosen value from a RadComboBo

2019-09-06 12:23发布

Inside a RadGrid, I have a drop RadComboBox that is populated by a web service.

I am using an EditItemTemplate nested inside a GridTemplateColumn to hold it, as shown:

On the server side, how can I access the value chosen by the user from the RadComboBox?

<telerik:GridTemplateColumn UniqueName="UserCol" HeaderText="proto user" DataField="UserID">

                           <EditItemTemplate>
                               <telerik:RadComboBox ID="RadComboBox1" runat="server" AutoPostBack="false" CausesValidation="true"
                                            Width="240" MaxHeight="200px" OnItemsRequested="ddEmployee_ItemsRequested" AllowCustomText="true"
                                            EnableLoadOnDemand="true" ShowMoreResultsBox="true" EnableVirtualScrolling="true"
                                            MarkFirstMatch="false" >
                                </telerik:RadComboBox>
                           </EditItemTemplate>
                       </telerik:GridTemplateColumn>

1条回答
【Aperson】
2楼-- · 2019-09-06 12:32

It depends on what event you're handling.

You can set AutoPostBack="true" and handle the OnSelectedIndexChanged event of the RadComboBox. This is very straightforward as you can get the selected value either from the EventArgs or from the sender object which is the RadComboBox itself. Check this out: http://www.telerik.com/help/aspnet-ajax/combobox-server-side-selectedindexchanged.html

If you are handling a row operation event such as insert or update, you need to find the RadComboBox object from the GridItem (e.Item).

protected void RadGrid_RowOperation(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    // this will find the control 
    RadComboBox RadComboBox1 = (RadComboBox)(e.Item.FindControl("RadComboBox1"));

    // so you can get the selected value
    string value = RadComboBox1.SelectedValue;
}
查看更多
登录 后发表回答