c# - Index out of range while getting Gridview selected row value in Session -
c# - Index out of range while getting Gridview selected row value in Session -
i'm trying values of gridview
selected row in sessions through button field in gridview giving me index out of range
error at:
gridviewrow row = adminsearchgridview.rows[index]
note: there 1 row in gridview want select values want.
code gridview:
<asp:gridview id="adminsearchgridview" runat="server" autogeneratecolumns="false" style="color: #333333; border-collapse: collapse; font-size: 14px; text-align: center; width: 1530px; margin-left: 0px; margin-top: 0px" cellpadding="4" forecolor="#333333" autogeneratedeletebutton="true" datakeynames="id" onrowdeleting="adminsearchgridview_rowdeleting" onrowcommand="adminsearchgridview_rowcommand"> <alternatingrowstyle backcolor="white" /> <columns> <asp:buttonfield buttontype="button" text="issue" commandname="issue" /> <asp:boundfield datafield="issuestatus" headertext="issue status" /> <asp:boundfield datafield="accessionno" headertext="accession number" /> <asp:boundfield datafield="callno" headertext="call number" /> <asp:boundfield datafield="title" headertext="title" /> </columns> </asp:gridview>
, code behind is...
protected void adminsearchgridview_rowcommand(object sender, gridviewcommandeventargs e) { if(e.commandname == "issue") { int index = convert.toint32(e.commandargument); gridviewrow row = adminsearchgridview.rows[index]; // index out of range error occurs here string accessno = adminsearchgridview.rows[index].cells[3].text; string title = adminsearchgridview.rows[index].cells[5].text; string author = adminsearchgridview.rows[index].cells[6].text; session["accessno"] = accessno; session["title"] = title; session["author"] = author; } }
i checked e.commandargument
returning int value 0 cannot figure out going wrong since adminsearchgridview.rows[0]
makes sense there row in gridview why index out of range?
your problem seems index out of range error not coming line have marked. coming next line
string author = adminsearchgridview.rows[index].cells[6].text;
by looking @ aspx code, there 5 columns declared , there autogeneratedeletebutton="true" adds 1 more column. means there total 6 columns, adminsearchgridview.rows[index].cells[6].text must give index out of bound exception. can comment line , check if solves problem?
c# asp.net aspxgridview
Comments
Post a Comment