Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECTED in dropdownlist inside a itemtemplate ina datagrid

Status
Not open for further replies.

gcastillo

Programmer
Jun 9, 2000
127
0
0
MX
Hello. I have a page that restores data from a previously saved "draft". In the page I have several datagrids with textboxes and labels. In one datagrid I have a dropdownlist in the follow form:

<asp:TemplateColumn HeaderText="Official Reference">
<ItemTemplate>
<asp:dropdownlist id="ddlReferenceFQ" runat="server" >
<asp:ListItem value="YY" selected>Select.....</asp:ListItem>
<asp:ListItem value="NOM">NOM</asp:ListItem>
<asp:ListItem value="CODEX Alimentarius">CODEX Alimentarius</asp:ListItem>
<asp:ListItem value="BAM">BAM</asp:ListItem>
<asp:ListItem value="AOAC">AOAC</asp:ListItem>
</asp:dropdownlist>
</ItemTemplate>
</asp:TemplateColumn>


The data is binded very simple:
Dim ddlSelect As DropDownList
SQLProyecto = "SELECT * FROM libdds.IN_FISQU WHERE num_Proy = " & numProject
conCuestionario_Open()
commCuestionario.Connection = conCuestionario
commCuestionario.CommandText = SQLProyecto
dataReaderCuestionario = commCuestionario.ExecuteReader()
dgFisicoquimicos.DataSource = dataReaderCuestionario
dgFisicoquimicos.DataBind()
dataReaderCuestionario.Close()
conCuestionario.Close()

All the data is loaded and displayed in their textboxes as should be, BUT how can I select the data value for the dropdownlist? If I have "NOM" in the database, I need to select "NOM" in the dropdownlist when the page is loaded, with all the list... any ideas? =(
Thank you in advance
 
ItemDataBound event..
Code:
If e.Item.ItemType = ListItemType.EditItem Or e.Item.ItemType = ListItemType.AlternatingItem Then
   Dim ddl As DropDownList = e.Item.FindControl("ddlReferenceFQ")
   ddl.Items.FindByValue("NOM").Selected = True

End If
 
i wasn't sure if he was saying he needed to select his records based on NOM from the DB..


If I have "NOM" in the database, I need to select "NOM" in the dropdownlist when the page is loaded

 
Hello and thanx. No, I don't need to select alwas "NOM", but the data stored in the database is the "selected" in the dropdownlist. If I have "BAM", then "BAM" should be the selected in the ddl when the page is loaded...
Thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top