从Radgrid中的服务器端读取editItemTemplate内的无线电输入

时间:2013-09-23 20:15:34

标签: telerik radgrid

我在网格中有一个编辑项目模板,如下面的代码所示:

<telerik:GridTemplateColumn HeaderText="<%$Resources:Resources,Sex  %>" UniqueName="EmpSex" DataField="sex"> <ItemTemplate> <asp:Label ID="EmpSexLb" runat="server" Text='<%# Eval("sex") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <input type="radio" name="Sexe" id="Radio1" checked="<%# Eval("sex").ToString()=="M"? "checked":"" %>"/> male  <input type="radio" name="Sexe" id="Radio2" checked="<%# Eval("sex").ToString()=="F"? "checked":"" %>"/> female </EditItemTemplate></telerik:GridTemplateColumn>

如何从radgrid的itemCommand事件中读取服务器端的无线电输入?

提前致谢

1 个答案:

答案 0 :(得分:1)

请尝试使用以下代码段。

ASPX

<telerik:GridTemplateColumn>
                    <EditItemTemplate>
                        <input type="radio" name="Sexe" id="Radio1" checked="true" runat="server" />
                        male 
                        <input type="radio" name="Sexe" id="Radio2" runat="server" />
                        female
                    </EditItemTemplate>
 </telerik:GridTemplateColumn>

ASPX.CS

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.UpdateCommandName)
    {
        GridEditableItem item = e.Item as GridEditableItem;
        System.Web.UI.HtmlControls.HtmlInputRadioButton Radio1 = (item.FindControl("Radio1") as System.Web.UI.HtmlControls.HtmlInputRadioButton);
        System.Web.UI.HtmlControls.HtmlInputRadioButton Radio2 = (item.FindControl("Radio2") as System.Web.UI.HtmlControls.HtmlInputRadioButton);
        //Access your radio button here
    }
}

如果有任何疑虑,请告诉我。