我試圖讓一個會話選擇GridView
行的值通過一個按鈕場,但其給我一個Index out of range
錯誤的:索引超出範圍,同時在GridView GridView的獲得所選行的值在會話
GridViewRow row = AdminSearchGridView.Rows[index]
注意:GridView中只有一行我想從中選擇我想要的值。爲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>
和代碼背後,是...
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;
}
}
我檢查了e.CommandArgument
將返回一個int值0,但 我不能找出因爲AdminSearchGridView.Rows[0]
是有意義的,因爲在第e GridView然後爲什麼索引超出範圍?
對不起作者的東西在那裏,但它不是問題的一部分。 – hilbiazhar
看到http://stackoverflow.com/questions/13285918/row-index-in-gridview-rowcommand –
我看到你已經定義了gridview的列,但沒有行。 –