Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
ashy_16in
Starting Member
16 Posts |
Posted - 2006-06-19 : 16:40:03
|
I am unable to preselect the correct text in the dropdown box in a datagrid. Eventhough the datatable has text 'No' and 'Removed' for certain rows, 'Yes' is getting preselected for all the rows in the edit mode in the drop down box. Any help in this regard would be greatly appreciated. This is the html code for the drop down box in the grid:<ItemTemplate><asp:Label id=Label4 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.trainedyn") %>'></asp:Label></ItemTemplate><EditItemTemplate><asp:DropDownList id="DropDownList2" runat="server" Width="106px"><asp:ListItem Value="Yes" Selected="True">Yes</asp:ListItem><asp:ListItem Value="No" Selected="True">No</asp:ListItem><asp:ListItem Value="Removed" Selected="True">Removed</asp:ListItem></asp:DropDownList></EditItemTemplate></asp:TemplateColumn>I need to preselect text ("Yes", "No" or "Removed") in the drop down box in the edit mode based on the text in the datatable. This is the code I have written for preselecting text in the dropdown box:Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound If e.Item.ItemType = ListItemType.EditItem Then Dim drvview As DataRowView = CType(e.Item.DataItem, DataRowView) Dim currentgenre As String = CType(drvview("trainedyn"), String) Dim ddl As DropDownList ddl = CType(e.Item.FindControl("DropDownList2"), DropDownList) ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByText(currentgenre))end sub |
|
dfiala
Posting Yak Master
116 Posts |
Posted - 2006-06-20 : 09:28:57
|
You have all your items with set selected="true".Replace <asp:ListItem Value="Yes" Selected="True">Yes</asp:ListItem><asp:ListItem Value="No" Selected="True">No</asp:ListItem><asp:ListItem Value="Removed" Selected="True">Removed</asp:ListItem>with<asp:ListItem Value="Yes" >Yes</asp:ListItem><asp:ListItem Value="No" >No</asp:ListItem><asp:ListItem Value="Removed" >Removed</asp:ListItem>Dean FialaVery Practical Software, IncNow with Blogging...http://www.vpsw.com/blogbabyMicrosoft MVP |
 |
|
|
|
|