Mehram
asked on
Specified argument was out of the range of valid values.
Dear Experts I am getting attached error against the below code: Please help me what I am doing wrong.
For index = 0 To gvDetail.Rows.Count - 1
Dim gvr As GridViewRow = gvDetail.Rows(index)
Dim av As TextBox = gvr.Cells(index).FindControl("txtAV")
lblMessage.Text = av.Text
Next
System.ArgumentOutOfRangeException was unhandled by user code
Message=Specified argument was out of the range of valid values.
Parameter name: index
ParamName=index
Source=System.Web
StackTrace:
at System.Web.UI.ControlCollection.get_Item(Int32 index)
at System.Web.UI.WebControls.TableCellCollection.get_Item(Int32 index)
at Admin_Imp_CustomAssessement.ReadGridView() in D:\Imp_App\Admin\Imp_CustomAssessment.aspx.vb:line 42
at Admin_Imp_CustomAssessement.lnkApply_Click(Object sender, EventArgs e) in D:\Imp_App\Admin\Imp_CustomAssessment.aspx.vb:line 104
at System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e)
at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:
ASKER
Can you change my code for my guidance please
what is the cell number you are searching for the textbox?
replace the bold part with the actual cell index.
For index = 0 To gvDetail.Rows.Count - 1
Dim gvr As GridViewRow = gvDetail.Rows(index)
Dim av As TextBox = gvr.Cells(index).FindControl("txtAV")
lblMessage.Text = av.Text
Next
replace the bold part with the actual cell index.
For index = 0 To gvDetail.Rows.Count - 1
Dim gvr As GridViewRow = gvDetail.Rows(index)
Dim av As TextBox = gvr.Cells(index).FindControl("txtAV")
lblMessage.Text = av.Text
Next
ASKER
changed
Dim av As TextBox = gvr.Cells(6).FindControl(" txtAV")
but same error.
My aspx code is:-
Dim av As TextBox = gvr.Cells(6).FindControl("
but same error.
My aspx code is:-
<asp:GridView ID="gvDetail" runat="server" AllowPaging="false" AllowSorting="true" GridLines="Both"
CssClass="display" AutoGenerateColumns="false" DataKeyNames="Id,JobNo" Width="99%" ShowHeader="false">
<Columns>
<asp:TemplateField HeaderText="ID" Visible="true">
<ItemTemplate>
<table width="100%">
<tr>
<td>
<table width="100%">
<tr>
<th>ID</th>
<th>Item Code</th>
<th>Item Description</th>
<th style="text-align:right;">Quantity</th>
<th style="text-align:right;">Net Weight</th>
<th>DV</th>
</tr>
<tr>
<td><%# Eval("Id") %></td>
<td><%# Eval("ItemCode")%></td>
<td><%# Eval("ItemDiscription")%></td>
<td style="text-align:right;"><%# Eval("Qty")%></td>
<td style="text-align:right;"<%# Eval("NetWeight")%></td>
<td><%# Eval("DV")%></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<th>AV</th>
<th>AVPKR</th>
<th>CD</th>
<th>ST</th>
<th>AST</th>
<th>IT</th>
<th>FED/KG</th>
<th>FED %</th>
<th>PSQCA</th>
<th>Quarantine</th>
</tr>
<tr>
<td>
<asp:TextBox ID="txtAV" runat="server" CssClass="textbox" Text='<%# Eval("AV","{0:F2}") %>' Width="45px" style="text-align:right;"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtAVPKR" runat="server" CssClass="textbox" Text='<%# Eval("AVPKR","{0:F2}") %>' Width="45px" style="text-align:right;"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtCD" runat="server" CssClass="textbox" Text='<%# Eval("CD","{0:F2}") %>' Width="45px" style="text-align:right;"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtST" runat="server" CssClass="textbox" Text='<%# Eval("ST","{0:F2}") %>' Width="45px" style="text-align:right;"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtAST" runat="server" CssClass="textbox" Text='<%# Eval("AST", "{0:F2}")%>' Width="45px" style="text-align:right;"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtIT" runat="server" CssClass="textbox" Text='<%# Eval("IT", "{0:F2}")%>' Width="45px" style="text-align:right;"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server" CssClass="textbox" Text='<%# Eval("FEDPerKG", "{0:F2}")%>' Width="45px" style="text-align:right;"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" CssClass="textbox" Text='<%# Eval("FEDPercentage", "{0:F2}")%>' Width="45px" style="text-align:right;"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox3" runat="server" CssClass="textbox" Text='<%# Eval("PSQCA", "{0:F2}")%>' Width="45px" style="text-align:right;"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox4" runat="server" CssClass="textbox" Text='<%# Eval("Quarantine", "{0:F2}")%>' Width="45px" style="text-align:right;"></asp:TextBox>
</td>
</tr>
</table>
</td>
</tr>
<tr><td style="border-bottom:1px solid #666;"></td></tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you are using same variable index for both row and column index.
if you have more rows than the cells in the gridview you will get indexoutofrange error.
replace index in the above line with the cell index you want to search.