Gridview error

P

Phuff

My Delete and select commands work like a charm, but Update won't
work!! Can someone help??

<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False" CellPadding="4"
DataSourceID="concept" ForeColor="#333333"
GridLines="None"
DataKeyNames="id,Description,unit,Quantity">
<FooterStyle BackColor="#990000" Font-Bold="True"
ForeColor="White" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="Quantity"
HeaderText="Quantity" SortExpression="Quantity" />
<asp:BoundField DataField="unit"
HeaderText="unit" SortExpression="unit" />
<asp:BoundField DataField="Description"
HeaderText="Description" SortExpression="Description" />
<asp:CommandField ButtonType="Button"
ShowDeleteButton="True" />
<asp:BoundField DataField="id" HeaderText="id"
HtmlEncode="False" InsertVisible="False"
ReadOnly="True" ShowHeader="False"
SortExpression="id" />
<asp:CommandField ButtonType="Button"
ShowEditButton="True" />
</Columns>
<RowStyle BackColor="#FFFBD6" ForeColor="#333333"
/>
<SelectedRowStyle BackColor="#FFCC66"
Font-Bold="True" ForeColor="Navy" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True"
ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="concept" runat="server"
ConnectionString="<%$ ConnectionStrings:Concept608ConnectionString %>"
SelectCommand="SELECT Quantity, unit, Description,
id FROM reportMatList WHERE (boxNumber = @boxNumber) AND (quoteNumber =
@quoteNumber) AND (unitNumber = @unitNumber)"
DeleteCommand="DELETE FROM reportMatList WHERE
(boxNumber = @boxNumber) AND (quoteNumber = @quoteNumber) AND
(unitNumber = @unitNumber) AND (id = @id)"
UpdateCommand="UPDATE reportMatList SET Quantity =
@Quantity, unit = @unit, Description = @Description WHERE id = @id">
<SelectParameters>
<asp:QueryStringParameter Name="boxNumber"
QueryStringField="txtBoxNumber" Type="String" />
<asp:QueryStringParameter Name="quoteNumber"
QueryStringField="txtQuoteNumber" Type="String" />
<asp:QueryStringParameter Name="unitNumber"
QueryStringField="txtUnitNumber" Type="String" />
</SelectParameters>
<DeleteParameters>
<asp:QueryStringParameter Name="boxNumber"
QueryStringField="txtBoxNumber" Type="String" />
<asp:QueryStringParameter Name="quoteNumber"
QueryStringField="txtQuoteNumber" Type="String" />
<asp:QueryStringParameter Name="unitNumber"
QueryStringField="txtUnitNumber" Type="String" />
<asp:ControlParameter Name="id"
ControlID="Gridview1" Type=Int32 />
</DeleteParameters>
<UpdateParameters>
<asp:ControlParameter Name="Quantity"
ControlID="Gridview1" Type=Int32 />
<asp:ControlParameter Name="unit"
ControlID="Gridview1" Type=string />
<asp:ControlParameter Name="Description"
ControlID="Gridview1" Type=string />
<asp:ControlParameter Name="id"
ControlID="Gridview1" Type=Int32 />
</UpdateParameters>
</asp:SqlDataSource>
 
V

Vlad Iliescu

You're using <asp:ControlParameter Name="id"
ControlID="Gridview1" Type=Int32 />. Basically, you tell your
SqlDataSource to search the GridView for a value, which is plain wrong
(you're not even specifying the PropertyName).

You should use something like <asp:parameter Name="id" Type=Int32 />.
This way, the SqlDataSource will try to use the "id" field of the
edited row as the parameter's value.
 

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,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top