Home All Groups Group Topic Archive Search About

GridView: Update is just not working for me

Author
22 Dec 2005 8:23 PM
beaudetious
Can an eagle eye help me fix whatever is causing me pain here?  When I click
the update command button, the page refreshes but the new values do not make
it to the database or back into the gridview.

I'm getting the dreaded "Must declare the variable @original_RoleId"
exception message.  My source code looks like this:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False"
DataKeyNames="RoleID" DataSourceID="SqlDataSource1"
OnRowDataBound="GridView1_RowDataBound"
OnRowUpdating="GridView1_RowUpdating">

<Columns>
<asp:BoundField DataField="RoleName" HeaderText="RoleName"
SortExpression="RoleName" />
<asp:BoundField DataField="Description" HeaderText="Description"
SortExpression="Description" />
<asp:TemplateField HeaderText="Users In Role">
<ItemTemplate>
<asp:Label ID="lblUserCount" runat="server" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Columns>
</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:AAWSqlConnectionString %>"
SelectCommand="SELECT RoleId, RoleName, LoweredRoleName, Description FROM
aspnet_Roles"
UpdateCommand="UPDATE aspnet_Roles SET [RoleName]=@RoleName,
[Description]=@Description WHERE RoleId = @original_RoleID">
</asp:SqlDataSource>

Any suggestions here?

beaudetious

Author
22 Dec 2005 8:52 PM
Phillip Williams
Add within the ObjectDatasource definition the following attribute:
OldValuesParameterFormatString="original_{0}"

This article woulde explain the usage of this attribute: http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasourceview.oldvaluesparameterformatstring.aspx

Show quoteHide quote
"beaudetious" wrote:

> Can an eagle eye help me fix whatever is causing me pain here?  When I click
> the update command button, the page refreshes but the new values do not make
> it to the database or back into the gridview.
>
> I'm getting the dreaded "Must declare the variable @original_RoleId"
> exception message.  My source code looks like this:
>
> <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
> AllowSorting="True" AutoGenerateColumns="False"
> DataKeyNames="RoleID" DataSourceID="SqlDataSource1"
> OnRowDataBound="GridView1_RowDataBound"
> OnRowUpdating="GridView1_RowUpdating">
>
> <Columns>
> <asp:BoundField DataField="RoleName" HeaderText="RoleName"
> SortExpression="RoleName" />
> <asp:BoundField DataField="Description" HeaderText="Description"
> SortExpression="Description" />
> <asp:TemplateField HeaderText="Users In Role">
> <ItemTemplate>
> <asp:Label ID="lblUserCount" runat="server" />
> </ItemTemplate>
> <ItemStyle HorizontalAlign="Center" />
> </asp:TemplateField>
> <asp:CommandField ShowEditButton="True" />
> </Columns>
> </asp:GridView>
>
> <asp:SqlDataSource ID="SqlDataSource1" runat="server"
> ConnectionString="<%$ ConnectionStrings:AAWSqlConnectionString %>"
> SelectCommand="SELECT RoleId, RoleName, LoweredRoleName, Description FROM
> aspnet_Roles"
> UpdateCommand="UPDATE aspnet_Roles SET [RoleName]=@RoleName,
> [Description]=@Description WHERE RoleId = @original_RoleID">
> </asp:SqlDataSource>
>
> Any suggestions here?
>
> beaudetious
Author
22 Dec 2005 9:06 PM
beaudetious
Excellent!  That's what was missing.  Thanks.

Show quoteHide quote
"Phillip Williams" wrote:

> Add within the ObjectDatasource definition the following attribute:
> OldValuesParameterFormatString="original_{0}"
>
> This article woulde explain the usage of this attribute:
> http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasourceview.oldvaluesparameterformatstring.aspx
>
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "beaudetious" wrote:
>
> > Can an eagle eye help me fix whatever is causing me pain here?  When I click
> > the update command button, the page refreshes but the new values do not make
> > it to the database or back into the gridview.
> >
> > I'm getting the dreaded "Must declare the variable @original_RoleId"
> > exception message.  My source code looks like this:
> >
> > <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
> > AllowSorting="True" AutoGenerateColumns="False"
> > DataKeyNames="RoleID" DataSourceID="SqlDataSource1"
> > OnRowDataBound="GridView1_RowDataBound"
> > OnRowUpdating="GridView1_RowUpdating">
> >
> > <Columns>
> > <asp:BoundField DataField="RoleName" HeaderText="RoleName"
> > SortExpression="RoleName" />
> > <asp:BoundField DataField="Description" HeaderText="Description"
> > SortExpression="Description" />
> > <asp:TemplateField HeaderText="Users In Role">
> > <ItemTemplate>
> > <asp:Label ID="lblUserCount" runat="server" />
> > </ItemTemplate>
> > <ItemStyle HorizontalAlign="Center" />
> > </asp:TemplateField>
> > <asp:CommandField ShowEditButton="True" />
> > </Columns>
> > </asp:GridView>
> >
> > <asp:SqlDataSource ID="SqlDataSource1" runat="server"
> > ConnectionString="<%$ ConnectionStrings:AAWSqlConnectionString %>"
> > SelectCommand="SELECT RoleId, RoleName, LoweredRoleName, Description FROM
> > aspnet_Roles"
> > UpdateCommand="UPDATE aspnet_Roles SET [RoleName]=@RoleName,
> > [Description]=@Description WHERE RoleId = @original_RoleID">
> > </asp:SqlDataSource>
> >
> > Any suggestions here?
> >
> > beaudetious