473,378 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

GridView UpdateParameters

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


*** Sent via Developersdex http://www.developersdex.com ***
Apr 25 '06 #1
3 8726
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.
"Mike P" wrote:
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


*** Sent via Developersdex http://www.developersdex.com ***

Apr 25 '06 #2
Thanks very much...what is the difference between Eval and Bind by the
way?
Cheers,

Mike

*** Sent via Developersdex http://www.developersdex.com ***
Apr 25 '06 #3
Bind is two way, whereas Eval just returns a value.

"Mike P" wrote:
Thanks very much...what is the difference between Eval and Bind by the
way?
Cheers,

Mike

*** Sent via Developersdex http://www.developersdex.com ***

Apr 25 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dabbler | last post by:
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...
2
by: dba123 | last post by:
How do I take my GridView and create a function that will update -all- checkbox values for the submit button's OnClick event? I have posted both my SQLDataSource and my GridView below: ...
0
by: Mike P | last post by:
Where exactly are the updateparameters of a gridview picked up from? I have created 2 very similar gridviews and given the updateparameters the same names as in my edititemtemplates. Yet this...
0
by: Mike P | last post by:
How do you get access to the values you have entered under edit mode in a gridview? I only seem to be able to access the values prior to them being edited. protected void...
3
by: Jon Paal | last post by:
this text keeps showing up in my gridview dropdownlist "System.Data.DataRowView" How do I prevent this problem ?
0
by: Deepak Palkar | last post by:
Hi I have Gridview and DetailView both on one page. I am showing the list in the Gridview and the particular record in DetailView. the problem is When i EDIT on the DetailView and try to UPDATE...
4
by: mohaaron | last post by:
This seems like it should be simple to do but for some reason I have been unable to make it work. I would like to databind a SqlDataSource to a GridView during the click event of a button. This...
0
by: KeesH | last post by:
Hi, I am quite desperate now because I made a nice webshop with a gridview where the customer is able to update the amount of products (Hostas in my situation) or delete the row. The problem is...
2
by: William LaMartin | last post by:
On webform, I am populating a GridView from a SQLDatasource based on a MySQL table named PIB. There is no vb code involved. Everything is done in the source for the aspx page, provided below. ...
2
by: xMetalDetectorx | last post by:
Hi Everyone, I have a very simple web app that uses .Net 2.0 login control to authenticate users and allow access to an "admin" folder. Inside that admin folder I have one page that has a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.