I know this question has been asked before, but I've tried the solutions in those posts and nothing is working.
I have a gridview that is populated from, and is meant to update, an XML file. Because of the purpose of the page in which this gridview is located, the databinding happens on the page_load event. Also, I'm using TemplateFields to control the layout of the gridview.
Here's my code. First, the Gridview:
<asp:GridView ID="fileGrid" runat="server" EnableViewState="true" AutoGenerateColumns="False" Width="315px" BorderStyle="None"
OnRowDeleting="fileGrid_RowDeleting" OnRowEditing="fileGrid_RowEditing"
OnRowCancelingEdit="fileGrid_RowCancelingEdit" OnRowUpdating="fileGrid_RowUpdating"
OnRowDataBound="fileGrid_RowDataBound">
<Columns>
<asp:BoundField DataField="name" HeaderText="Uploaded Files" SortExpression="name" ReadOnly="true">
<ItemStyle CssClass="fileName" />
</asp:BoundField>
<asp:TemplateField HeaderText="Description">
<ItemStyle CssClass="desc-cell" />
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("desc") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="descTb" runat="server" Text='<%# Bind("desc") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemStyle CssClass="cmdCell" />
<ItemTemplate>
<asp:LinkButton ID="lnkEdit" runat="server" CommandName="Edit">Edit</asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="lnkUpdate" runat="server" CommandName="Update">Update</asp:LinkButton>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemStyle CssClass="cmdCell" />
<ItemTemplate>
<asp:LinkButton ID="lnkDelete" runat="server" CommandName="Delete">Delete</asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="lnkCancel" runat="server" CommandName="Cancel">Cancel</asp:LinkButton>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
And my OnRowUpdating function. This is where the problem occurs:
protected void fileGrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int eRow = e.RowIndex;
GridViewRow row = fileGrid.Rows[eRow];
string name = row.Cells[0].Text;
string desc = ((TextBox)(row.Cells[1].FindControl("descTb"))).Text;
// Update XML via Linq-to-XML here
}
However, I can't capture the value entered into the descTb textbox for anything; "desc" always comes back null. I'm aware that page_load fires before RowUpdating, but I can't wrap the code that populates my gridview in a PostBack check, because then my gridview comes back blank (and I still don't get that bloody textbox value.) Saving the initial, pre-edit grid view data in Session memory and updating that in the RowUpdating event doesn't work. Setting EnableViewState on the textbox control to "true", and removing the <%# Bind() %> in the text property, doesn't work.
Does anyone have any ideas?