我在GridView的ItemTemplet字段中設置了ispostback = true但仍然單選按鈕列表沒有觸發gridview的row_command事件的rdiobutton列表。如果我對按鈕做了同樣的操作那麼它工作正常。我已經編寫了綁定(!!IspostBack)中的網格代碼,但問題仍然是 那裏..我可以如何擺脫這些。gridview的行命令事件不是爲asp中的radiobuttinlist發射
這是我的網格代碼。
<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事件的代碼
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);
}
}
當您檢查任何無線電按鈕時,您在e.commandname中獲得了什麼。附上一個調試器並檢查值。 – ankur
我在grdSalesPerson_RowCommand事件的開始處設置了斷點,但它根本沒有觸發事件。但它的確會觸發回傳事件。 –
您是否手動創建了此事件。因爲您的活動未正確創建。使用智能標籤並再次創建事件。我認爲你有重複的問題已經http://stackoverflow.com/questions/8486368/gridview-is-not-firing-row-command-event-on-radiobutton-list-selection – ankur