GridView UpdateParameters

  • Thread starter Thread starter Mike P
  • Start date Start date
M

Mike P

I must be missing something regarding update parameters. I have tried
using <asp:Parameter> to specify my update parameters, and
<asp:ControlParameter> when <asp:Parameter> didn't work for a particular
parameter. Here is my code :

<

asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

SelectCommand="GetOppsTypeList" SelectCommandType="StoredProcedure"

UpdateCommand="UpdateOpportunity" UpdateCommandType="StoredProcedure">

<SelectParameters>

<asp:QueryStringParameter Name="CompanyKey"
QueryStringField="CompanyKey" Type="Int64" />

<asp:QueryStringParameter Name="OppsType" QueryStringField="OppsType"
Type="Int32" />

</SelectParameters>

<UpdateParameters>

<asp:Parameter Name="ProductTypeID" Type="Int32" />

<asp:Parameter Name="OpportunityTypeID" Type="Int32" />

<asp:Parameter Name="MonetaryValue" Type="Decimal" /> (first attempt)
(error : Cannot insert the value NULL into column 'MonetaryValue', table
'Canon.dbo.Opportunity'; column does not allow nulls. UPDATE fails.The
statement has been terminated. )
<

asp:ControlParameter ControlID="txtValue" Name="MonetaryValue"
PropertyName="Text" /> (second attempt) (error : Could not find control
'txtValue' in ControlParameter 'MonetaryValue'.)

<asp:Parameter Name="OpportunityID" Type="Int32" />

</UpdateParameters>

</asp:SqlDataSource>
<

asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"

DataKeyNames="OpportunityID" AllowSorting="True"
HeaderStyle-Height="24px"

AutoGenerateColumns="False">

<Columns>

<asp:TemplateField HeaderText="Product Type"
SortExpression="ProductType">

<ItemTemplate>

<asp:Label ID="lblProductType" Text='<%# Eval("ProductType") %>'
Runat="Server" />

</ItemTemplate>

<EditItemTemplate>

<asp:DropDownList ID="ddlProductType" runat="server"
DataSourceID="SqlDataSource2"

DataTextField="ProductType" DataValueField="ProductTypeID"

SelectedValue='<%# Bind("ProductTypeID") %>'></asp:DropDownList>

</EditItemTemplate>

<ControlStyle Width="80px" />

<ItemStyle Height="24px" Width="80px" />

</asp:TemplateField>

<asp:TemplateField HeaderText="Opportunity Type"
SortExpression="OpportunityType">

<ItemTemplate>

<asp:Label ID="lblOpportunityType" Text='<%# Eval("OpportunityType") %>'
Runat="Server" />

</ItemTemplate>

<EditItemTemplate>

<asp:DropDownList id="ddlOpportunityType" DataSourceID="SqlDataSource3"
Runat="Server"

DataTextField="OpportunityType" DataValueField="OpportunityTypeID"
SelectedValue='<%# Bind("OpportunityTypeID") %>'/>

</EditItemTemplate>

<ControlStyle Width="120px" />

<ItemStyle Height="24px" Width="120px" />

</asp:TemplateField>


<asp:TemplateField HeaderText="Value (£)"
SortExpression="MonetaryValue">

<ItemTemplate>

<asp:Label ID="lblValue" Text='<%# Eval("MonetaryValue") %>'
Runat="Server" />

</ItemTemplate>

<EditItemTemplate>

<asp:TextBox ID="txtValue" Text='<%# Eval("MonetaryValue") %>'
runat="server"></asp:TextBox>

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"

ControlToValidate="txtValue" Display="None" ErrorMessage="Please enter a
Value" />

<asp:RangeValidator ID="RangeValidator1" runat="server"

ControlToValidate="txtValue" Type="Double" MaximumValue="4000000"

MinimumValue="0" Display="None" ErrorMessage="Value must be numeric" />

</EditItemTemplate>

<ControlStyle Width="80px" />

<ItemStyle Height="24px" Width="80px" />

</asp:TemplateField>

<asp:CommandField ShowEditButton="True" ButtonType="Image"
EditImageUrl="~/Images/btnEdit.jpg"

CancelImageUrl="~/Images/btnCancel.jpg"
UpdateImageUrl="~/Images/btnUpdate.jpg"/>

</Columns>

</asp:GridView>


Can anybody tell me what I am doing wrong here?



Cheers,

Mike
 
Don't add the parameter in any way, if you simply replace

<asp:TextBox ID="txtValue" Text='<%# Eval("MonetaryValue") %>'
runat="server"></asp:TextBox>

With

<asp:TextBox ID="txtValue" Text='<%# Bind("MonetaryValue") %>'
runat="server"></asp:TextBox>

So long as the parameter within the stored procedure is called MonetaryValue
the update will work.
 
Thanks very much...what is the difference between Eval and Bind by the
way?


Cheers,

Mike
 

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

Back
Top