GridView could not find control 'xxx' in controlparameter 'xxx'

G

Guest

I have a checkbox control in a GridView EditItemTemplate. My SqlDataAdapter
complains when I try and use UpdateCommand

Thanks on any binding clarification.

GridView:
<asp:TemplateField HeaderText="Active">
<ItemTemplate>
<asp:CheckBox ID="ActiveCheckBox" runat="server" Checked='<%#
Eval("Active") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox ID="ActiveCheckBox" runat="server" Checked='<%#
Bind("Active") %>' />
</EditItemTemplate>
</asp:TemplateField>


UpdateCommand="Update dbo.Vans set VendorVanNo=@VendorVanNo, ...
Active=@Active ... where VanId=@VanId">
<UpdateParameters>
<asp:parameter Name="VendorVanNo"/>
...
<asp:ControlParameter Name="ActiveCheckBox"
ControlId="ActiveCheckbox" PropertyName="Checked"/>
...
</UpdateParameters>
 
G

Guest

The way that databinding on the GridView works is that the ASP.NET passes an
IorderedDictionary containing the controls values extracted from the Bind
expression.

The updateparameters should not be referring to controls within the
templates because the checkbox “ActiveCheckbox†is not visible as indepdent
control, it only exists within the EditItemTemplate of the GridView. All you
needed to do within the updateparameters collection is list the fieldnames
(the same the ones you used in the Bind expressions) that have been databound
or that are DataKeys on the GridView, e.g.,

<UpdateParameters>
<asp:parameter Name="VendorVanNo" Type="Int32"/>
<asp:parameter Name="Active" Type="Boolean"/>
</UpdateParameters>
 
G

Guest

Aha, the fog is clearing! and the UpdateParameter uses the C# datatype, not
the SQL datatype as in boolean vs bit.

Thanks Phillip
 

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

Top