我在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);
}
}