How do you read the chosen value from a RadComboBox?

烈酒焚心 提交于 2019-12-11 14:48:43

问题


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:


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;
}


来源:https://stackoverflow.com/questions/28753472/how-do-you-read-the-chosen-value-from-a-radcombobox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!