I would like to set the first column in a Gridview to zero, but in doing so, I get the following error: System.Web.UI.WebControls.GridViewRow' is not accessible in this context because it is 'Friend'.
This is my Grid:
<asp:GridView ID="gvPurchaseOrderNum" runat="server" AutoGenerateColumns="False"
onrowdeleting="gvPurchaseOrderNum_RowDeleting" onrowediting="gvPurchaseOrderNum_RowEditing"
onrowupdating="gvPurchaseOrderNum_RowUpdating" onrowcommand="gvPurchaseOrderNum_RowCommand"
ShowFooter="True" Width="482px"
onrowcancelingedit="gvPurchaseOrderNum_RowCancelingEdit">
<Columns>
<asp:TemplateField HeaderText="Purchase Order ID" Visible="true">
<EditItemTemplate>
<asp:TextBox ID="txtPonumberID" runat="server" Text='<%# Bind("ponumberID") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtPonumberIDInsert" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblPonumberID" runat="server" Text='<%# Bind("PonumberID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Purchase Order Number">
<EditItemTemplate>
<asp:TextBox ID="txtPonumber" runat="server" Text='<%# Bind("poNumber") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtPoNumberInsert" runat="server"></asp:TextBox>
<%-- <asp:RequiredFieldValidator runat="server" ID="reqtxtPoNumberInsert" ControlToValidate="txtPoNumberInsert" ErrorMessage="Required Field" Display="Dynamic" />--%>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblPoNumber" runat="server" Text='<%# Bind("PoNumber") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True"
CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="btnInsert" runat="server" CommandName="insertXMLData">Insert</asp:LinkButton>
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit"></asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="120px" />
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" />
</Columns>
<emptydatatemplate>
<b>Enter Purchase Order Number(s)</b> <br />
<asp:TextBox ID="txtStartpoNumID" runat="server"></asp:TextBox><br />
<asp:TextBox ID="txtStartpoNum" runat="server"></asp:TextBox><br />
<%-- <asp:RequiredFieldValidator runat="server" ID="reqtxtStartpoNum" ControlToValidate="txtStartpoNum" ErrorMessage="Required Field" Display="Dynamic" />--%>
<asp:LinkButton ID="lnkpro" runat="server" OnClick="writeStartpoNum" Text="Add Part Description"></asp:LinkButton>
<p> </p>
</emptydatatemplate>
</asp:GridView>
and here is the code behind I'm implementing to execute the task:
Protected Sub gvPurchaseOrderNum_RowDataBound(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
' set the first column to zero
e.Row.Cells(0).Text = 0
End If
End Sub
...Could I please get some help as to what I'm doing wrong here? I Googled the error, but was unable to find a remedy to the problem.
Use the
FindControl()
method instead of theCells
collection, like this:Since you have potentially multiple controls within in a
TemplateField
it will be much easier to use theFindControl()
method to locate the exact item you want to change theText
property of, instead of depending upon getting the right cell by index.