指数超出范围。必须是非负参数:索引

时间:2014-06-19 17:17:42

标签: c# asp.net

我真的陷入了这个问题。我无法弄清楚出了什么问题。

我的代码在

下面

.CS

protected void AdminSearchGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Select")
    {
        int index = Convert.ToInt32(e.CommandArgument);

        GridViewRow selectedRow = AdminSearchGridView.Rows[index]; //error occurs here
        char accessno = Convert.ToChar(AdminSearchGridView.Rows[index].Cells[1].Text);                        
        string title = AdminSearchGridView.Rows[index].Cells[3].Text;                        
        string author = AdminSearchGridView.Rows[index].Cells[4].Text;

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: 45px" CellPadding="4" ForeColor="#333333"
        AutoGenerateDeleteButton="True" DataKeyNames="ID"
            OnRowDeleting="AdminSearchGridView_RowDeleting" 
            onrowcommand="AdminSearchGridView_RowCommand">
        <AlternatingRowStyle BackColor="White" />
        <Columns>
            <asp:ButtonField ButtonType="Button" CommandName="Select"
                Text="Issue" />
            <asp:BoundField DataField="IssueStatus" HeaderText="Issue Status" />                
            <asp:BoundField DataField="ID" HeaderText="ID" />
            <asp:BoundField DataField="AccessionNo" HeaderText="Accession Number" />
            <asp:BoundField DataField="CallNo" HeaderText="Call Number" />
            <asp:BoundField DataField="Title" HeaderText="Title" />
            <asp:BoundField DataField="Author" HeaderText="Author" />
            <asp:BoundField DataField="CoAuthor" HeaderText="Co-Author" />
            <asp:BoundField DataField="AInitial" HeaderText="Author Initial" />
            <asp:BoundField DataField="PublisherName" HeaderText="Publisher Name" />
            <asp:BoundField DataField="PublishDate" HeaderText="Publish Date" DataFormatString="{0:dd/MM/yyyy}" />
            <asp:BoundField DataField="Volume" HeaderText="Volume" />
            <asp:BoundField DataField="Category" HeaderText="Category" />
            <asp:BoundField DataField="ISSN" HeaderText="ISSN" />
            <asp:BoundField DataField="NoOfPages" HeaderText="No Of Pages" />
            <asp:BoundField DataField="TypeOfBook" HeaderText="Type Of Book" />
            <asp:BoundField DataField="Price" HeaderText="Price" />

        </Columns>

0 个答案:

没有答案