asp.net - Get the checkbox or radio in the GridView -
all, added checkbox
every row of gridview
. in trouble find checkbox
gridview
when postback.
here code have done. please review it. thanks.
protected void gridviewthiract_rowdatabound(object sender, gridviewroweventargs e) { if (e.row.rowtype == datacontrolrowtype.datarow) { someobject mapitem = (someobject)e.row.dataitem; string itemid = mapitem.itemid; literal lit = e.row.findcontrol("selectbuttonmarkup") literal; if (isthirdseriesmultipleselect) { lit.text = string.format("<input type='checkbox' name='finalactivity' id='rowselector{0}' value='{1}'", e.row.rowindex, itemid); } else { lit.text = string.format("<input type='radio' name='finalactivity' id='rowselector{0}' value='{1}'", e.row.rowindex, itemid); } lit.text += " />"; } }
the code in aspx
below.
<asp:gridview id="gridviewthiract" runat="server" autogeneratecolumns="false" width="100%" onrowcreated="gridviewthiract_rowcreated" onrowdatabound="gridviewthiract_rowdatabound"> <columns> <asp:templatefield itemstyle-width="5%"> <itemtemplate> <asp:literal id="selectbuttonmarkup" runat="server"></asp:literal> </itemtemplate> </asp:templatefield> <asp:boundfield datafield="itemvalue" headertext="activity name" itemstyle-width="80%" /> <asp:boundfield datafield="itemid" headertext="id" itemstyle-width="15%" /> </columns> </asp:gridview> <asp:linkbutton id="btnok" runat="server" onclick="btnok_click"></asp:linkbutton>
i want select values in button click event. thanks.
i have used request.form["finalactivity"]
make .but thinking there other ways retrieve checkbox
control iterate rows
of gridview
? have tried code this.gridviewthiract.rows[i].cells[0].findcontrol(controlid)
, doesn't work. thanks.
try it:
.aspx
<asp:gridview id="grdfoodlist" autogeneratecolumns="false" runat="server"> <columns> <asp:templatefield> <headertemplate> select </headertemplate> <itemtemplate> <asp:checkbox runat="server" id="selectfood" /> </itemtemplate> </asp:templatefield>
code behind:
for (int rows = 0; rows < grdfoodlist.rows.count; rows++) { if (((checkbox) grdfoodlist.rows[rows].cells[0].findcontrol("selectfood")).checked) { //your code } }
Comments
Post a Comment