Please help me with writing a RowUpdating function in C#, I don't know how to grab the current field's value and also get the old value for one of keys (which is ProjectName for editing) of the selected row. I've tried:
e.Keys.Count, e.OldValues.Cou nt, e.NewValues.Cou nt -----------> all give zero
Some said if TemplateField is used, e.Keys and Oldvalues, NewValues are all empty. Then what suppose to be used in such case?
Thanks for any inputs.
Here is the code for GridView
There're seven columns, here's a block of code for one column.
e.Keys.Count, e.OldValues.Cou nt, e.NewValues.Cou nt -----------> all give zero
Some said if TemplateField is used, e.Keys and Oldvalues, NewValues are all empty. Then what suppose to be used in such case?
Thanks for any inputs.
Here is the code for GridView
Code:
<asp:GridView ID="gvStudentsAndProjects" runat="server" AutoGenerateColumns="False" DataKeyNames="StudentID,ProjectName" AllowSorting="True" Cellpadding="4" CssClass="gridview" GridLines="None" ShowFooter="True" EnableViewState=false OnRowCommand="gvStudentsAndProjects_RowCommand" OnRowCancelingEdit="gvStudentsAndProjects_RowCancelingEdit" OnRowEditing ="gvStudentsAndProjects_RowEditing" OnRowUpdating="gvStudentsAndProjects_RowUpdating">
Code:
<asp:TemplateField HeaderText="ProjectName" SortExpression="ProjectName"> <EditItemTemplate> <asp:TextBox ID="tbProjectName" runat="server" Text='<%# Bind("ProjectName") %>' Width="100%" Rows="2" TextMode="MultiLine"></asp:TextBox> <asp:RequiredFieldValidator ID="rfvProjectName" runat ="server" ControlToValidate ="tbProjectName" Display="Dynamic" Text="*Please input a project name" ErrorMessage="ProjectName Cannot be empty" ValidationGroup="EditValidationControls"></asp:RequiredFieldValidator> </EditItemTemplate> <ItemTemplate> <asp:Label ID="lbProjectName" runat="server" Text='<%# Bind("ProjectName") %>'></asp:Label> </ItemTemplate> <FooterTemplate> <asp:TextBox ID="tbNewProjectName" runat="server" Rows="2" TextMode="MultiLine" Width="100%"></asp:TextBox> <asp:RequiredFieldValidator ID="rfvNewProjectName" runat ="server" ControlToValidate ="tbNewProjectName" Display="Dynamic" Text="*Please input a project name" ErrorMessage="ProjectName Cannot be empty" ValidationGroup="InsertValidationControls"></asp:RequiredFieldValidator> </FooterTemplate> <FooterStyle Wrap =True /> </asp:TemplateField>
Comment