I have a gridview with edit and delete. When i click Edit, I donot get all the textboxes. I just get 1. on top of that, when I try to update anything in that textbox, I get object Reference not set to an instance of object.
Can anyone please help me with this?
my aspx for gridview is:
My .cs for edit is:
Can anyone please help me with this?
my aspx for gridview is:
Code:
<asp:GridView ID="grdItems" runat="server" AllowSorting="True"
BackColor="White" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px"
CellPadding="4" ForeColor="Black" GridLines="Vertical" width="670px" OnRowCancelingEdit="grdItems_RowCancelingEdit" OnRowEditing="grdItems_RowEditing" OnRowUpdating="grdItems_RowUpdating" DataKeyNames="rowid" AutoGenerateColumns="False" OnRowDeleting="grdItems_RowDeleting" Font-Size="Smaller" ShowFooter="True" OnRowCreated="grdItems_RowCreated">
<Columns>
<asp:TemplateField HeaderText="ROWID" SortExpression="rowid" Visible="False">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("rowid") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblRowID" runat="server" Text='<%# Bind("rowid") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle Font-Size="Small" HorizontalAlign="Center" />
<ItemStyle Font-Names="Arial" Font-Size="Smaller" />
</asp:TemplateField>
<asp:TemplateField SortExpression="invItemDesc" HeaderText="DESCRIPTION">
<HeaderTemplate>
<table cellpadding="0" cellspacing="0" width="100%">
<tr ><td colspan="4" align=center>DESCRIPTION</td></tr>
</table>
<table cellpadding="0" cellspacing="0" width="100%">
<tr><td width="25%">MTN NO.</td><td width="25%">ACCOUNT NO.</td><td width="25%">INVOICE NO.</td><td width="25%">AMOUNT</td> </tr>
</table>
</HeaderTemplate>
<EditItemTemplate>
<td width="25%"><asp:TextBox ID="txtMTN" runat="server" Text='<%# Eval("MTN") %>'></asp:TextBox></td>
</EditItemTemplate>
<EditItemTemplate>
<td width="25%"><asp:TextBox ID="txtcAccNum" runat="server" Text='<%# Eval("cAccNum") %>'></asp:TextBox></td>
</EditItemTemplate>
<EditItemTemplate>
<td width="25%"><asp:TextBox ID="txtinvNum" runat="server" Text='<%# Eval("summInvNum") %>'></asp:TextBox></td>
</EditItemTemplate>
<EditItemTemplate>
<td width="25%"><asp:TextBox ID="txtAmt" runat="server" Text='<%# Eval("invItemAmt") %>'></asp:TextBox></td>
</EditItemTemplate>
<ItemTemplate><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td width="25%"><%# Eval("MTN")%></td><td width="25%"><%# Eval("cAccNum")%></td><td width="25%"><%# Eval("summInvNum")%></td><td width="25%"><%# Eval("invItemAmt")%></td> </tr>
</table></ItemTemplate>
<FooterTemplate>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td width="25%"></td><td width="25%"></td><td width="25%"></td><td width="25%">Total for MTN:</td> </tr>
<tr><td width="25%"></td><td width="25%"></td><td width="25%"></td><td width="25%">Total Amt Due:</td> </tr>
</table>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Total Amount">
<ItemTemplate>
<asp:Literal ID = "AmountLiteral" runat="server"></asp:Literal>
</ItemTemplate>
<FooterTemplate> <table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><asp:Literal ID = "amountTotal" runat = "server"></asp:Literal></tr>
<tr><asp:Literal ID = "amountTotal1" runat = "server"></asp:Literal></tr>
</table>
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" ShowDeleteButton="True">
<HeaderStyle Font-Size="Small" HorizontalAlign="Center" />
<ItemStyle Font-Names="Arial" Font-Size="Smaller" />
</asp:CommandField>
</Columns>
<FooterStyle ForeColor="Black" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<EditRowStyle BorderColor="Black" BorderStyle="Solid" />
</asp:GridView>
Code:
protected void grdItems_RowEditing(object sender, GridViewEditEventArgs e)
{
grdItems.EditIndex = e.NewEditIndex;
populateItems();
TextBox txtMTN = (TextBox)grdItems.Rows[e.NewEditIndex].Cells[1].FindControl("txtMTN");
txtMTN.Width = Unit.Pixel(75);
TextBox txtAccNum = (TextBox)grdItems.Rows[e.NewEditIndex].Cells[2].FindControl("txtAccNum");
txtAccNum.Width = Unit.Pixel(75);
TextBox txtSummInvNo = (TextBox)grdItems.Rows[e.NewEditIndex].Cells[3].FindControl("txtSummInvNo");
txtSummInvNo.Width = Unit.Pixel(75);
TextBox txtAmt = (TextBox)grdItems.Rows[e.NewEditIndex].Cells[4].FindControl("txtAmt");
txtAmt.Width = Unit.Pixel(75);
}
Comment