Hi,
There are two dropdownlists in two EditItemTemplates of a gridview. They are
populated programmatically (see code below). This works.
But now, the selected value of the first ddl (dropdownlist1) takes always
the selected value of the second ddl (dropdownlist2) , and the new value
chosen for update in the first ddl is also always the value chosen (or
selectedvalue if not chosen) of the second ddl. It seems that the second ddl
overrules the first one. In normal mode, the values of both ddl are rendered
correctly.
I can't find any reason for that, and the only way i found is to populate
one of the ddl manually (in aspx file). But that is fastidious, isn't it?)
Thanks for help
Mark
Here the code in aspx file:
<asp:TemplateField HeaderText="min" SortExpression="min">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%#
Bind("min") %>'></asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("min") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="max" SortExpression="max">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" SelectedValue='<%#
Bind("max") %>'></asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("max") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
and here thet code-behind:
Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
If (e.Row.RowState And DataControlRowState.Edit) =
DataControlRowState.Edit Then
If e.Row.RowType = DataControlRowType.DataRow Then
Dim dd1, dd2 As DropDownList
Dim z As ListItem
Dim i As Integer
dd1 = e.Row.FindControl("dropdownlist1")
dd2 = e.Row.FindControl("dropdownlist2")
For i = 0 To 200
z = New ListItem(i, i)
dd1.Items.Add(z)
dd2.Items.Add(z)
Next
End If
End If
End Sub
Eliyahu Goldin - 30 Jul 2007 22:55 GMT
The problem is in 2 ddls sharing the same set of items. When you select an
item in the first ddl, the item becomes "Selected". "Selected" is an
attribute of the item itself and not of the ddl that contains the item.
This means that the item becomes "Selected" in all ddls it belongs to.
To solve the problem do
For i = 0 To 200
z1 = New ListItem(i, i)
z2 = New ListItem(i, i)
dd1.Items.Add(z1)
dd2.Items.Add(z2)
Next

Signature
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
> Hi,
>
[quoted text clipped - 55 lines]
> End If
> End Sub
Mark - 30 Jul 2007 23:44 GMT
Yes that's it.
Thanks a lot.
> The problem is in 2 ddls sharing the same set of items. When you select an
> item in the first ddl, the item becomes "Selected". "Selected" is an
[quoted text clipped - 76 lines]
>> End If
>> End Sub