473,769 Members | 1,994 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

bind dropdown field in GridView EditItemTemplat e?

I have two tables I'm editing in a Gridview. The VANS table contains a key to
the other LESSOR table. I would like to use a dropdown list to select the
LessorId value while displaying the Lessor table's "Company" field as text.
When I commit the edit I get error:Must declare the scalar variable
"@LessorId" .

Also as a bonus question ;) I don't know how to set the selectedindex value
in the dropdown list based on the LessorId value in the Vans table.

Any ideas would be appreciated!

Thanks.

Here's my templatefield:
<asp:TemplateFi eld HeaderText="Com pany" >
<ItemTemplate >
<asp:literal ID="Literal1" runat="server" Text='<%# Eval("Company") %>' />
</ItemTemplate>
<EditItemTempla te>
<asp:DropDownLi st ID="ddlCompany " runat="server"
DataSourceID="s dsLessors" DataTextField=" Company" DataValueField= "LessorId">
</asp:DropDownLis t>
</EditItemTemplat e>
</asp:TemplateFie ld>

Gridview's SqlDataSource:
<asp:SqlDataSou rce ID="sdsVans" runat="server"
ProviderName="S ystem.Data.SqlC lient"
ConnectionStrin g="<%$ ConnectionStrin gs:myDB %>"
SelectCommand=" SELECT v.VanNo, v.LessorId, v.Status, v.Active,
l.Company, l.Account FROM dbo.Van v join dbo.Lessors l ON
v.LessorId=l.Le ssorId order by VanNo"
UpdateCommand=" Update dbo.Vans set VanNo=@VanNo, LessorId=@Lesso rId,
Status=@Status, Active=@Active where LessorId=@Lesso rId" >
</asp:SqlDataSour ce>

DropDownList's SqlDataSource:
<asp:SqlDataSou rce ID="sdsLessors " runat="server"
ProviderName="S ystem.Data.SqlC lient"
ConnectionStrin g="<%$ ConnectionStrin gs:myDB %>"
SelectCommand=" SELECT LessorId, Company, Account FROM dbo.Lessors
order by Company">
</asp:SqlDataSour ce>
Mar 21 '06 #1
4 29538
Super Green! Thanks!

"Phillip Williams" wrote:
The GridView will pass the LessorID as a parameter (in the NewValues
collection) if you create a 2-way databind on the dropdownlist:

<asp:DropDownLi st ID="ddlCompany " runat="server"
DataSourceID="s dsLessors" DataTextField=" Company" DataValueField= "LessorId"
SelectedValue=' <%# Bind("LessorID" ) %>'>
</asp:DropDownLis t>

In addition, for good programming style, you should define an
<UpdateParamete rs> collection within the markup of the SqlDatasource that
updates the GridView.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Dabbler" wrote:
I have two tables I'm editing in a Gridview. The VANS table contains a key to
the other LESSOR table. I would like to use a dropdown list to select the
LessorId value while displaying the Lessor table's "Company" field as text.
When I commit the edit I get error:Must declare the scalar variable
"@LessorId" .

Also as a bonus question ;) I don't know how to set the selectedindex value
in the dropdown list based on the LessorId value in the Vans table.

Any ideas would be appreciated!

Thanks.

Here's my templatefield:
<asp:TemplateFi eld HeaderText="Com pany" >
<ItemTemplate >
<asp:literal ID="Literal1" runat="server" Text='<%# Eval("Company") %>' />
</ItemTemplate>
<EditItemTempla te>
<asp:DropDownLi st ID="ddlCompany " runat="server"
DataSourceID="s dsLessors" DataTextField=" Company" DataValueField= "LessorId">
</asp:DropDownLis t>
</EditItemTemplat e>
</asp:TemplateFie ld>

Gridview's SqlDataSource:
<asp:SqlDataSou rce ID="sdsVans" runat="server"
ProviderName="S ystem.Data.SqlC lient"
ConnectionStrin g="<%$ ConnectionStrin gs:myDB %>"
SelectCommand=" SELECT v.VanNo, v.LessorId, v.Status, v.Active,
l.Company, l.Account FROM dbo.Van v join dbo.Lessors l ON
v.LessorId=l.Le ssorId order by VanNo"
UpdateCommand=" Update dbo.Vans set VanNo=@VanNo, LessorId=@Lesso rId,
Status=@Status, Active=@Active where LessorId=@Lesso rId" >
</asp:SqlDataSour ce>

DropDownList's SqlDataSource:
<asp:SqlDataSou rce ID="sdsLessors " runat="server"
ProviderName="S ystem.Data.SqlC lient"
ConnectionStrin g="<%$ ConnectionStrin gs:myDB %>"
SelectCommand=" SELECT LessorId, Company, Account FROM dbo.Lessors
order by Company">
</asp:SqlDataSour ce>

Mar 21 '06 #2
You solution worked but in an effort to practice "good programming" I tried
to add InsertParameter s. I'm a little puzzled here.. I tried creating
InsertParameter for my InsertCommand for the drop down list as in:
InsertCommand=" INSERT INTO dbo.Vans(... VendorCode) VALUES (... @VendorCode)">

<InsertParamete rs>
<asp:ControlPar ameter ControlID="Vend orsDropDownList " Name="VendorCod e"
PropertyName="S electedValue" />
</InsertParameter s>
but when I try and insert a row I get an error:
cannot find control "VendorsDropDow nList" in controlparamete r "VendorCode "
Just would like to understand this binding better.

Thanks for listening ;)

"Phillip Williams" wrote:
The GridView will pass the LessorID as a parameter (in the NewValues
collection) if you create a 2-way databind on the dropdownlist:

<asp:DropDownLi st ID="ddlCompany " runat="server"
DataSourceID="s dsLessors" DataTextField=" Company" DataValueField= "LessorId"
SelectedValue=' <%# Bind("LessorID" ) %>'>
</asp:DropDownLis t>

In addition, for good programming style, you should define an
<UpdateParamete rs> collection within the markup of the SqlDatasource that
updates the GridView.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Dabbler" wrote:
I have two tables I'm editing in a Gridview. The VANS table contains a key to
the other LESSOR table. I would like to use a dropdown list to select the
LessorId value while displaying the Lessor table's "Company" field as text.
When I commit the edit I get error:Must declare the scalar variable
"@LessorId" .

Also as a bonus question ;) I don't know how to set the selectedindex value
in the dropdown list based on the LessorId value in the Vans table.

Any ideas would be appreciated!

Thanks.

Here's my templatefield:
<asp:TemplateFi eld HeaderText="Com pany" >
<ItemTemplate >
<asp:literal ID="Literal1" runat="server" Text='<%# Eval("Company") %>' />
</ItemTemplate>
<EditItemTempla te>
<asp:DropDownLi st ID="ddlCompany " runat="server"
DataSourceID="s dsLessors" DataTextField=" Company" DataValueField= "LessorId">
</asp:DropDownLis t>
</EditItemTemplat e>
</asp:TemplateFie ld>

Gridview's SqlDataSource:
<asp:SqlDataSou rce ID="sdsVans" runat="server"
ProviderName="S ystem.Data.SqlC lient"
ConnectionStrin g="<%$ ConnectionStrin gs:myDB %>"
SelectCommand=" SELECT v.VanNo, v.LessorId, v.Status, v.Active,
l.Company, l.Account FROM dbo.Van v join dbo.Lessors l ON
v.LessorId=l.Le ssorId order by VanNo"
UpdateCommand=" Update dbo.Vans set VanNo=@VanNo, LessorId=@Lesso rId,
Status=@Status, Active=@Active where LessorId=@Lesso rId" >
</asp:SqlDataSour ce>

DropDownList's SqlDataSource:
<asp:SqlDataSou rce ID="sdsLessors " runat="server"
ProviderName="S ystem.Data.SqlC lient"
ConnectionStrin g="<%$ ConnectionStrin gs:myDB %>"
SelectCommand=" SELECT LessorId, Company, Account FROM dbo.Lessors
order by Company">
</asp:SqlDataSour ce>

Mar 22 '06 #3
What is the VendorsDropDown List? How are you using it? In your earlier
question you only explained a dropdownlist named ddlCompany?
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Dabbler" wrote:
You solution worked but in an effort to practice "good programming" I tried
to add InsertParameter s. I'm a little puzzled here.. I tried creating
InsertParameter for my InsertCommand for the drop down list as in:
InsertCommand=" INSERT INTO dbo.Vans(... VendorCode) VALUES (... @VendorCode)">

<InsertParamete rs>
<asp:ControlPar ameter ControlID="Vend orsDropDownList " Name="VendorCod e"
PropertyName="S electedValue" />
</InsertParameter s>
but when I try and insert a row I get an error:
cannot find control "VendorsDropDow nList" in controlparamete r "VendorCode "
Just would like to understand this binding better.

Thanks for listening ;)

"Phillip Williams" wrote:
The GridView will pass the LessorID as a parameter (in the NewValues
collection) if you create a 2-way databind on the dropdownlist:

<asp:DropDownLi st ID="ddlCompany " runat="server"
DataSourceID="s dsLessors" DataTextField=" Company" DataValueField= "LessorId"
SelectedValue=' <%# Bind("LessorID" ) %>'>
</asp:DropDownLis t>

In addition, for good programming style, you should define an
<UpdateParamete rs> collection within the markup of the SqlDatasource that
updates the GridView.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Dabbler" wrote:
I have two tables I'm editing in a Gridview. The VANS table contains a key to
the other LESSOR table. I would like to use a dropdown list to select the
LessorId value while displaying the Lessor table's "Company" field as text.
When I commit the edit I get error:Must declare the scalar variable
"@LessorId" .

Also as a bonus question ;) I don't know how to set the selectedindex value
in the dropdown list based on the LessorId value in the Vans table.

Any ideas would be appreciated!

Thanks.

Here's my templatefield:
<asp:TemplateFi eld HeaderText="Com pany" >
<ItemTemplate >
<asp:literal ID="Literal1" runat="server" Text='<%# Eval("Company") %>' />
</ItemTemplate>
<EditItemTempla te>
<asp:DropDownLi st ID="ddlCompany " runat="server"
DataSourceID="s dsLessors" DataTextField=" Company" DataValueField= "LessorId">
</asp:DropDownLis t>
</EditItemTemplat e>
</asp:TemplateFie ld>

Gridview's SqlDataSource:
<asp:SqlDataSou rce ID="sdsVans" runat="server"
ProviderName="S ystem.Data.SqlC lient"
ConnectionStrin g="<%$ ConnectionStrin gs:myDB %>"
SelectCommand=" SELECT v.VanNo, v.LessorId, v.Status, v.Active,
l.Company, l.Account FROM dbo.Van v join dbo.Lessors l ON
v.LessorId=l.Le ssorId order by VanNo"
UpdateCommand=" Update dbo.Vans set VanNo=@VanNo, LessorId=@Lesso rId,
Status=@Status, Active=@Active where LessorId=@Lesso rId" >
</asp:SqlDataSour ce>

DropDownList's SqlDataSource:
<asp:SqlDataSou rce ID="sdsLessors " runat="server"
ProviderName="S ystem.Data.SqlC lient"
ConnectionStrin g="<%$ ConnectionStrin gs:myDB %>"
SelectCommand=" SELECT LessorId, Company, Account FROM dbo.Lessors
order by Company">
</asp:SqlDataSour ce>

Mar 22 '06 #4
If you still have not solved this issue, review this article to an indepth
explanation of how the datasource creates paramters for databound fields:
http://msdn2.microsoft.com/en-us/lib...51(VS.80).aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Dabbler" wrote:
You solution worked but in an effort to practice "good programming" I tried
to add InsertParameter s. I'm a little puzzled here.. I tried creating
InsertParameter for my InsertCommand for the drop down list as in:
InsertCommand=" INSERT INTO dbo.Vans(... VendorCode) VALUES (... @VendorCode)">

<InsertParamete rs>
<asp:ControlPar ameter ControlID="Vend orsDropDownList " Name="VendorCod e"
PropertyName="S electedValue" />
</InsertParameter s>
but when I try and insert a row I get an error:
cannot find control "VendorsDropDow nList" in controlparamete r "VendorCode "
Just would like to understand this binding better.

Thanks for listening ;)

"Phillip Williams" wrote:
The GridView will pass the LessorID as a parameter (in the NewValues
collection) if you create a 2-way databind on the dropdownlist:

<asp:DropDownLi st ID="ddlCompany " runat="server"
DataSourceID="s dsLessors" DataTextField=" Company" DataValueField= "LessorId"
SelectedValue=' <%# Bind("LessorID" ) %>'>
</asp:DropDownLis t>

In addition, for good programming style, you should define an
<UpdateParamete rs> collection within the markup of the SqlDatasource that
updates the GridView.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Dabbler" wrote:
I have two tables I'm editing in a Gridview. The VANS table contains a key to
the other LESSOR table. I would like to use a dropdown list to select the
LessorId value while displaying the Lessor table's "Company" field as text.
When I commit the edit I get error:Must declare the scalar variable
"@LessorId" .

Also as a bonus question ;) I don't know how to set the selectedindex value
in the dropdown list based on the LessorId value in the Vans table.

Any ideas would be appreciated!

Thanks.

Here's my templatefield:
<asp:TemplateFi eld HeaderText="Com pany" >
<ItemTemplate >
<asp:literal ID="Literal1" runat="server" Text='<%# Eval("Company") %>' />
</ItemTemplate>
<EditItemTempla te>
<asp:DropDownLi st ID="ddlCompany " runat="server"
DataSourceID="s dsLessors" DataTextField=" Company" DataValueField= "LessorId">
</asp:DropDownLis t>
</EditItemTemplat e>
</asp:TemplateFie ld>

Gridview's SqlDataSource:
<asp:SqlDataSou rce ID="sdsVans" runat="server"
ProviderName="S ystem.Data.SqlC lient"
ConnectionStrin g="<%$ ConnectionStrin gs:myDB %>"
SelectCommand=" SELECT v.VanNo, v.LessorId, v.Status, v.Active,
l.Company, l.Account FROM dbo.Van v join dbo.Lessors l ON
v.LessorId=l.Le ssorId order by VanNo"
UpdateCommand=" Update dbo.Vans set VanNo=@VanNo, LessorId=@Lesso rId,
Status=@Status, Active=@Active where LessorId=@Lesso rId" >
</asp:SqlDataSour ce>

DropDownList's SqlDataSource:
<asp:SqlDataSou rce ID="sdsLessors " runat="server"
ProviderName="S ystem.Data.SqlC lient"
ConnectionStrin g="<%$ ConnectionStrin gs:myDB %>"
SelectCommand=" SELECT LessorId, Company, Account FROM dbo.Lessors
order by Company">
</asp:SqlDataSour ce>

Mar 23 '06 #5

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

Similar topics

7
2161
by: ibiza | last post by:
Hi everybody, Is there a way to convert a value with Bind()? I have a decimal(5,4) data that I retrieve from DB, which represents a percent. For example, 50% is represented as 0.5000. When I bind the data to a gridview, I'd like to see this value as "50", because what I do is a templatefield : <edititemtemplate> <asp:textbox text='<%#Bind("value")' runat="server" /> </edititemtemplate>
0
1724
by: teclioness | last post by:
Hi, I am using gridview for the user to update rows. In a row, there sre two columns, which need to be updated. When the gridview is to be shown, the row should show the values from database. When user clicks on edit link, should display the windows loginId in one column and in second column, show the current datetime. When user clicks on update link, should save these two column values to database as well as other updated field values....
3
2112
by: Advertis | last post by:
Is there a way to populate a dropdown in a GridView with the next x years? I am using a GridView to display data from a SQL table One of the fields is a Year. I want to have the dropdown list not only the year in the db field, but also the current year to the next x years. Any ideas?
3
1144
by: Savas Ates | last post by:
It is in my <EditItemTemplateTag.. <asp:DropDownList Runat=server ID="CIdeefixeSatis" SelectedIndex='<%# SelectMyIndex(DataBinder.Eval(Container, "DataItem.ideefixesatis")) %>' <asp:ListItem Value="True">Stokta Var</asp:ListItem>
0
2436
by: landesjoe | last post by:
Hi, here's my problem in short: Text boxes in gridview don't seem to hold their value if the column's .Visible property is changed back and forth. I've got a form with a gridview populated from a data view (which in turn is loaded from a manually setup DataTable for testing purposes). One of the columns in the grid is a checkbox that's tied to an event handler that'll change the .Visible property of a column with a text box. That text...
0
1969
by: ganesh22 | last post by:
Hi... Iam using GridView in asp.net(2.0) .My requirement is user can add,update,delete in gridview I written the code for add & update but can u help adding rows in grid view My code: <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="3" Height="237px" Style="z-index: 100; left: 155px; position: absolute; top: 132px" Width="688px" BackColor="White" BorderColor="#CCCCCC"...
0
1427
by: progman417 | last post by:
I have a gridview with a dropdown list in an EditItemTemplate. I haven't set a width for the columns, so that they dynamically size according to the data displayed. When it goes into edit mode I want to make the dropdown lists a bit wider to allow for the width of the arrow, and widen the column accordingly. If I set the width of the dropdown list to a fixed unit such as 300px; then it widens the column accordingly. But if I...
2
3249
by: DC | last post by:
Hi, I am using a GridView to present data in a DataTable, which I store only in ViewState and when the user hits the "OK" button the rows in the DataTable will be used to execute transactions. I need the ability to insert new rows (which is easily done with DataTable.Rows.Add(newRow) and rebinding) and then present a row with different TemplateFields for those rows (I need multiple rows in this insert state).
5
3677
by: sandhyascs | last post by:
Hi everyone I’m using the GridView in asp.net and populating the grid dynamically using c#.net.To edit the rows i i m using GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e). Now if I run the application and click the “Edit” Button then the complete row is generating the textboxes to edit the data in that particular row and also the “Update” and “Cancel” buttons are generated.When I change the data in any of the textboxes...
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9851
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.