Click to See Complete Forum and Search --> : parameters problem in .net 2005


jabbarsb
December 11th, 2006, 08:16 AM
hi friends,
i am facing a problem in vs 2005 i am using gridview control and sqldatasource bounded to it
in the update command of the sqldatasource i am passing a query

UPDATE aspnet_UsersInRoles SET RoleId = @RoleId WHERE UserId =@userid

the gridview is having three columns userid,username and roleid among which userid is hidden

if i make this column visible then the above query is working fine but when i make it visible=false then i am getting an
error : Must declare a variable @userid

also i want to know if i place a dropdownlist in gridview how to access its selectedvalues as a parameter

can anybody help me

regards jabbar

jasonli
December 11th, 2006, 08:42 AM
I think you could change a certain BoundField to TemplateField and then add a hidden control into that TemplateField, like:
<asp:TemplateField HeaderText="Material">
<ItemTemplate>
<asp:Label ID="lblMat" runat="server" Text='<%# Bind("Mat") %>'></asp:Label>
<input type="hidden" runat="server" id="hidID" value='<%# Bind("UserID") %>' />
</ItemTemplate>
</asp:TemplateField>

When you want to get value, CType(GridView1.Rows(index).FindControl("hidID"), HtmlInputHidden).Value

For the dropdownlist, you could do the same thing.

Charu0306
December 14th, 2006, 06:29 PM
Also, if Userid is the first column bound in that gridviwe, then you can use Gridview1.selectedvalue.Tostring to get the id. It always better to make it first column and hidden if its just one unique primary key you are looking into.