By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,458 Members | 1,215 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,458 IT Pros & Developers. It's quick & easy.

Gridview Update Troubles

P: n/a
I have a gridview which is pulling data from a SqlDataSource, the
select command queries a view and the update command is a stored
procedure. I'm using a stored procedure because several tables need to
be updated based on the data in the gridview.

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:slightsInventoryConnectionString %>"
SelectCommand="SELECT * FROM [vDetailsWithKeys]"
UpdateCommand="upd_Inventory" UpdateCommandType="StoredProcedure">
<UpdateParameters>
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="Street" Type="String" />
<asp:Parameter Name="CrossStreet" Type="String" />
<asp:Parameter Name="PoleType" Type="Int32" />
<asp:Parameter Name="PoleLength" Type="Int32" />
<asp:Parameter Name="PolePaint" Type="Boolean" />
<asp:Parameter Name="PoleUse" Type="Int32" />
<asp:Parameter Name="Foundation" Type="Int32" />
<asp:Parameter Name="TransformerBase" Type="Boolean" />
<asp:Parameter Name="Metered" Type="Boolean" />
<asp:Parameter Name="PoleNumber" Type="String" />
<asp:Parameter Name="FixtureQty" Type="Int32" />
<asp:Parameter Name="Comments" Type="String" />
<asp:Parameter Name="Incomplete" Type="Boolean" />
<asp:Parameter Name="ServiceLength" Type="Int32" />
<asp:Parameter Name="NotOnMap" Type="Boolean" />
<asp:Parameter Name="NotInCity" Type="Boolean" />
<asp:Parameter Name="MapPoleNum" Type="String" />
<asp:Parameter Name="PoleID" Type="Int32" />
<asp:Parameter Name="LampType" Type="Int32" />
<asp:Parameter Name="Circuit" Type="Int32" />
<asp:Parameter Name="Service" Type="Int32" />
<asp:Parameter Name="FixtureType" Type="Int32" />
<asp:Parameter Name="FixtureManufacturer" Type="Int32"
/>
<asp:Parameter Name="SuspensionType" Type="Int32" />
</UpdateParameters>
The gridview has several columns which display a dropdownlist when in
edit mode. I have included a sample:
<asp:TemplateField HeaderText="PoleType"
SortExpression="PoleTypeDescription">
<EditItemTemplate>
<asp:DropDownList ID="ddlPoleType"
runat="server"
DataSourceID="sdsPoleType"
DataTextField="PoleTypeDescription"
DataValueField="PoleTypeID"
SelectedValue='<%# Bind("PoleTypeID") %>' >
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1"
runat="server"
Text='<%# Bind("PoleTypeDescription") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

Everything looks great until I hit the update button.The row converts
itself to edit mode perfectly and all the dropdownlists fill correctly
and have the correct selectedvalue. When I hit Update, I get an error
message that "Procedure or function upd_Inventory has too many
arguments specified". I looked at the contents of the update statement
using SqlProfiler and it seems that the gridview update command is
sending a parameter value to the stored procedure for every column in
the gridview. Several columns in the gridview (some hidden/some not)
hold key values or other fields that I don't need/want to update.
Furthermore, all the parameters representing the dropdownlist columns
had null values. So, I decided to try handling everything in the
codebehind (using the RowUpdating event handler), which seems to mostly
work, except that the gridview still tries to do the update as well.
So, I took out the update command from the SqlDataSource and now I get
an error message that says:"Updating is not supported by data source
'SqlDataSource1' unless UpdateCommand is specified"

I feel like a fool because all this is supposed to be "easy" but I've
been unable to make this work. Thanks in advance for your help.

Nov 16 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.