GridView: Update is just not working for me

B

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
 
B

beaudetious

Excellent! That's what was missing. Thanks.

Phillip Williams said:
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/li...ourceview.oldvaluesparameterformatstring.aspx

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


beaudetious said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top