我有一个网格视图
<asp:TemplateField HeaderText="Refrence No">
<ItemTemplate>
<asp:TextBox ID="RefrenceNo" runat="server" Width="50px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Projects">
<ItemTemplate>
<asp:DropDownList ID="Projects" AutoPostBack="true" OnSelectedIndexChanged ="onTextChange" runat="server" Width="100px"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
并在代码中
Protected Sub onTextChange(ByVal sender As Object, ByVal e As EventArgs)
Dim row As GridViewRow = GridView2.Rows(GridView2.EditIndex)
Dim ddlProjects As DropDownList = CType(row.FindControl("Projects"), DropDownList)
Dim txtProjects As TextBox = CType(row.FindControl("RefrenceNo"), TextBox)
txtProjects.Text = ddlProjects.Text
End Sub
我想用下拉列表更改值填充文本框但是在运行时错误来了
Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
参数名称:index
第68行:昏暗行作为GridViewRow = GridView2.Rows(GridView2.EditIndex)
请帮助
答案 0 :(得分:0)
我可以解释一下错误在说什么..
Dim row As GridViewRow = GridView2.Rows(GridView2.EditIndex)
检查GridView2.EditIndex
的值。具有该索引的特定Gridview中没有行。因此,您可以检查 EditIndex 的值。