0

单击编辑按钮时,我想获取文字文本。我已经编写了代码来执行此操作,但是当我运行程序时出现此异常

"Specified argument was out of the range of valid values. Parameter name: index"

.aspx 代码:

<gridview id="gridview3" onrowediting="edit>
    <coulmn>

        <asp:TemplateField HeaderText="description" Visible="true">
            <ItemTemplate>
             <asp:Literal ID="id6" runat="server" Text='<%#Eval("description") %>' >
             </asp:Literal>
            </ItemTemplate>
             <EditItemTemplate>
                 <asp:TextBox ID="TextBox1" Text='<%#Eval("description") %>'  
 runat="server" ></asp:TextBox>

            </EditItemTemplate>
            <FooterTemplate>

            <asp:TextBox ID="TextBox3"  runat="server" ></asp:TextBox>

            </FooterTemplate>
        </asp:TemplateField>

        <asp:TemplateField HeaderText="Agree" Visible="true">
            <ItemTemplate>

             <asp:Literal ID="id5" runat="server" Text='<%#Eval("option1") %>' >
             </asp:Literal>
            </ItemTemplate>
             <EditItemTemplate>
                 <asp:TextBox ID="TextBox11" Text='<%#Eval("option1") %>' 
              runat="server" ></asp:TextBox>

            </EditItemTemplate>
            <FooterTemplate>

            <asp:TextBox ID="TextBox4"  runat="server" ></asp:TextBox>    

            </FooterTemplate>
        </asp:TemplateField>
          <asp:TemplateField HeaderText="Disagree" Visible="true">
            <ItemTemplate>

             <asp:Literal ID="id4" runat="server" Text='<%#Eval("option2") %>' >
             </asp:Literal>
            </ItemTemplate>
             <EditItemTemplate>
                 <asp:TextBox ID="TextBox5" Text='<%#Eval("option2") %>' runat="server">         
                 </asp:TextBox>
            </EditItemTemplate>
            <FooterTemplate>

            <asp:TextBox ID="TextBox6"  runat="server" ></asp:Text>

            </FooterTemplate>
        </asp:TemplateField>

        <asp:TemplateField HeaderText="Action" Visible="true">
            <ItemTemplate>
                <asp:LinkButton ID="LinkButton5" Text="Edit" CommandName="edit" 

           runat="server"></asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
    </coulmn>
</gridview>

**code behind:**

protected void edit(object sender, GridViewEditEventArgs e)
{
    Literal l = GridView2.Rows[0].Cells[3].Controls[1] as Literal;
    Label5.Text = l.Text;

    gridview3.EditIndex = e.NewEditIndex; 
}
4

1 回答 1

0

请试试这个

Literal l = GridView2.Rows[e.NewEditIndex].FindControl("id6") as Literal;
Label5.Text = l.Text;
于 2012-06-08T17:58:54.297 回答