472,985 Members | 2,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,985 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 2473
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...

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.