grid.net的行命令事件未在asp.net中为radiobuttinlist触发

时间:2012-01-23 05:43:51

标签: asp.net aspxgridview rowcommand

我在gridview的ItemTemplet字段中有rdiobutton列表,设置为ispostback = true但仍然radiobutton列表没有为gridview触发row_command事件。如果我对按钮执行相同操作,那么它可以正常工作。我已编写代码来绑定(!IspostBack)中的网格,但问题仍然存在 那......我怎么能摆脱这些。

这是我网格的代码。

<asp:GridView ID="grdSalesPerson" runat="server" AutoGenerateColumns="False" BackColor="#DEBA84" OnRowCommand="grdSalesPerson_RowCommand">
                    <Columns>
                        <asp:BoundField DataField="SalesPersonID" HeaderText="SalesPersonID" />
                        <asp:BoundField DataField="FirstName" HeaderText="First Name" />
                        <asp:BoundField DataField="LastName" HeaderText="Last Name" />
                        <asp:BoundField DataField="UserName" HeaderText="User Name" />
                        <asp:BoundField DataField="StateName" HeaderText="State Name" />
                        <asp:BoundField DataField="CityName" HeaderText="City Name" />

                        <asp:TemplateField HeaderText="Is Active">
                            <ItemTemplate>
                                <asp:RadioButtonList ID="rbActive" runat="server" CommandName="IsAct" AutoPostBack="true">
                                    <asp:ListItem>Yes</asp:ListItem>
                                    <asp:ListItem>No</asp:ListItem>
                                </asp:RadioButtonList>
                            </ItemTemplate>
                        </asp:TemplateField>  
                    </Columns>
                </asp:GridView>

这是Row_Command Event

的代码
protected void grdSalesPerson_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
{
    if (e.CommandName == "IsAct")
    {
        //  GridViewRow row = (GridViewRow) (((Button)grdSalesPerson.FindControl("btnIsActive")).NamingContainer);
        GridViewRow row = (GridViewRow)(((RadioButton)e.CommandSource).NamingContainer);
        int i = Convert.ToInt32(row.Cells[0].Text);
    }
}

2 个答案:

答案 0 :(得分:1)

请查看以下链接,这可能会对您有所帮助 Radiobutton checked change event not firing in gridview

答案 1 :(得分:0)

您还可以在此处查看:(i)  (ii) (iii) (iv) (v) (vi) 希望有所帮助