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.