Gridview Update Troubles

T

troyblakely

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.
 

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,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top