473,323 Members | 1,550 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,323 software developers and data experts.

Lookup values and DDL in datagrid

Vik
How can I display the lookup values in a datagrid?
E.g., the datagrid displays a table that contains a ProductID field. I want
to display a Product description from a Product table in that datagrid.
Currently I use a join between the main table and the lookup table to get
the Product description.
Is it possible to use a dropdownlist in the datagrid to display and select
(in Edit mode) the lookup values?

Thank you.
Nov 18 '05 #1
4 2521
Hi, Vik

You can try use TemplateColumn to create a dropdown for your products

<asp:TemplateColumn HeaderText="Product"><ItemTemplate><asp:dropdownli st ID="ddlProduct" Runat="Server"></asp:dropdownlist></ItemTemplate></asp:TemplateColumn

In ItemDataBound Event of the datagrid, provide data for the list

Dim ctl As Control = e.Item.Cells(0).FindControl("ddlProduct"
If Not ctl Is Nothing The
Dim ddl As DropDownList = CType(ctl, DropDownList
With dd
.DataSource = ds 'ds is a dataset created from tblProduc
.DataTextField = "ProductID
.DataValueField = "ProductDescription
.DataBind(
End Wit
End I

Bin Song, MC

----- Vik wrote: ----

How can I display the lookup values in a datagrid
E.g., the datagrid displays a table that contains a ProductID field. I wan
to display a Product description from a Product table in that datagrid
Currently I use a join between the main table and the lookup table to ge
the Product description
Is it possible to use a dropdownlist in the datagrid to display and selec
(in Edit mode) the lookup values

Thank you

Nov 18 '05 #2
Vik
Thank you, Bin.

I already created TemplateColumn and placed the dropdownlists in
ItemTemplate and EditItemTemplate and set up ddls' properties in design
view. I also set up SelectedValue='<% DataBinder.Eval(Container,
"DataItem.ProductID") %>'.
The datagrid displays correct products, but when trying to edit the
datagrid, I get an error "Specified argument was out of the range of valid
values. Parameter name: value" in dg_EditCommand sub.
If I remove SelectedValue binding, the error doesn't appear, but datagrid,
of course, doesn't display correct values. And in Edit mode ddl is empty.
I tried your code (with an addition of DataMember property) but ddl still is
empty in Edit mode.

Vik

"Bin Song, MCP" <an*******@discussions.microsoft.com> wrote in message
news:FE**********************************@microsof t.com...
Hi, Vik,

You can try use TemplateColumn to create a dropdown for your products:

<asp:TemplateColumn HeaderText="Product"><ItemTemplate><asp:dropdownli st ID="ddlProduct"
Runat="Server"></asp:dropdownlist></ItemTemplate></asp:TemplateColumn>
In ItemDataBound Event of the datagrid, provide data for the list:

Dim ctl As Control = e.Item.Cells(0).FindControl("ddlProduct")
If Not ctl Is Nothing Then
Dim ddl As DropDownList = CType(ctl, DropDownList)
With ddl
.DataSource = ds 'ds is a dataset created from tblProduct
.DataTextField = "ProductID"
.DataValueField = "ProductDescription"
.DataBind()
End With
End If

Bin Song, MCP

----- Vik wrote: -----

How can I display the lookup values in a datagrid?
E.g., the datagrid displays a table that contains a ProductID field. I want to display a Product description from a Product table in that datagrid. Currently I use a join between the main table and the lookup table to get the Product description.
Is it possible to use a dropdownlist in the datagrid to display and select (in Edit mode) the lookup values?

Thank you.

Nov 18 '05 #3
Hi Vik

You can not just simply bind the value to the selected value of dropdownlist.
Remove the binding code and in itemdatabound event, add the following code

ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByValue(DataBinder .Eval(Container,"DataItem.ProductID"))

Bin Song, MCP
Nov 18 '05 #4
Vik
Bin,

If I place this statement in code, I get an error "Name 'Container' is not
declared".

Vik

"Bin Song, MCP" <an*******@discussions.microsoft.com> wrote in message
news:3D**********************************@microsof t.com...
Hi Vik,

You can not just simply bind the value to the selected value of dropdownlist. Remove the binding code and in itemdatabound event, add the following code:
ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByValue(DataBinder .Eval(Container,"DataItem.
ProductID")))
Bin Song, MCP

Nov 18 '05 #5

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

Similar topics

3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
4
by: Vik | last post by:
How can I display the lookup values in a datagrid? E.g., the datagrid displays a table that contains a ProductID field. I want to display a Product description from a Product table in that...
1
by: Big Dave | last post by:
Good morning. This group has been a great help so far, and it is much appreciated. Here's my new question. I want to be able to create a datagrid at runtime, which will have template columns...
1
by: Demetri | last post by:
Hello, I have a page with a datagrid. The datagrid has a column called Employee Name. This column is for display purposes. However, in edit mode (including making additions) the user will need...
4
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box...
0
by: dbuchanan | last post by:
Hello, For my datagrid I added a datagrid table style to include columns from my lookup tables. These display the values in the lookup tables rather than just the integer key value stored in the...
3
by: dbuchanan | last post by:
Hello, (Windows forms - SQL Server) I fill my datagrid with a stored procedure that includes relationships to lookup tables so that users can see the values of the combobox selections rather...
11
by: Paul H | last post by:
Suppose I have a table called tblPeople and I want a field to illustrate whether each person prefers cats or dogs. I could do it one of three ways. 1. A plain text field Create a text field in...
1
by: tommy.tashjian | last post by:
Hi, I have a datagrid with a textbox column that needs a lookup table. Now, I was going to just use a dropdownlist instead of the textbox, but that won't fly here. So, what I need to know, is it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...

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.