select control in a repeater control

Hi

I have a repeater control which data are selected that way: 

 Strsql = "SELECT T_PRODUIT.NO_PRODUIT, T_PRODUIT.UNITE, T_PRODUIT.NO_CATEGORIE, T_PRODUIT.NO_CSBE,T_PRODUIT.NOUVEAU,T_PRODUIT.ID_PRODUIT, " & _
              "CASE WHEN IMAGE IS NULL THEN 'Aucun.gif' ELSE IMAGE END AS IMAGE1, T_PRODUIT.NOM, " & _
              "T_PRODUIT.DESCR, T_PRODUIT.DETAIL,T_FOURNISSEUR_PRODUIT.NO_FOURNISSEUR_PRODUIT, T_FOURNISSEUR_PRODUIT.PRIX, T_FOURNISSEUR_PRODUIT.PRIX_LISTE, " & _
              "T_FOURNISSEUR.NOM as FNOM, T_FOURNISSEUR.NO_FOURNISSEUR, " & _
              "T_CATEGORIE.DESCR as CATDESC " & _
              "FROM T_PRODUIT " & _
              "INNER JOIN T_FOURNISSEUR_PRODUIT ON T_PRODUIT.NO_PRODUIT = T_FOURNISSEUR_PRODUIT.NO_PRODUIT " & _
              "INNER JOIN T_CATEGORIE ON T_PRODUIT.NO_CATEGORIE = T_CATEGORIE.NO_CATEGORIE " & _
              "INNER JOIN T_FOURNISSEUR ON T_FOURNISSEUR_PRODUIT.NO_FOURNISSEUR = T_FOURNISSEUR.NO_FOURNISSEUR " & _
              "WHERE T_PRODUIT.ETAT='a' AND T_PRODUIT.NO_PRODUIT =" & Request.QueryString("No_Produit")

 This is working fine.

Now I would like to have a select control with this sql selection

"SELECT NO_ETAB FROM T_ETAB_PB WHERE NO_ETAB ='" & Session("NO_ETAB") & "'"

How can I do that?

0
myriam_giroux
6/19/2008 6:48:33 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

5 Replies
953 Views

Similar Articles

[PageSpeed] 37

You can create an SQLDataSource control.

Here is an example midified from MSDN sample: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sessionparameter.aspx

<asp:SqlDataSource id="SQLDataSource1" runat="server"

ConnectionString="<%$ ConnectionStrings:myConnectionString %>" SelectCommand="SELECT NO_ETAB FROM T_ETAB_PB WHERE NO_ETAB =@NO_ETAB ">
          <SelectParameters>
              <asp:SessionParameter Name="NO_ETAB" SessionField="NO_ETAB" />
          </SelectParameters>
      </asp:SqlDataSource>


Limno

0
limno
6/19/2008 6:57:35 PM

Do I put this code in the repeater control?

0
myriam_giroux
6/19/2008 7:20:02 PM

Sorry, I forgot to say that I want my dropdownlist in the repeater control...

Sorry about that

0
myriam_giroux
6/19/2008 7:35:35 PM

ok here is the code in the aspx.vb page

StrsqlEtab = "SELECT NO_ETAB FROM T_ETABLISSEMENT" ' WHERE No_ETAB = '" & Session("No_Etab") & "' ORDER BY NO_POSTE_B_1"

cmdEtab = New SqlCommand(StrsqlEtab, Conn)myDAEtab = New SqlDataAdapter(cmdEtab)

Conn.Open()

myDAEtab.Fill(DsEtab)

Bud_1.DataSource = DsEtab

Bud_1.DataBind()

Bud_1.DataTextField = "NO_ETAB"

Bud_1.SelectedIndex = 1

Response.Write(Bud_1.Items.Count)  //this display the number of records that I have in my table T_ETABLISSEMENT

 

Here is the code in html

<asp:Repeater id="RepeaterAjoutPanier" runat="server">
 <ItemTemplate>
  <table align=center width=90% bgcolor="#FAFAFA"> 
   <tr>
    <td>
     <table align=center width=100% >     
      <tr class="Texte13N" bgcolor="#F5F5F5">
       <td align="center" valign="middle"><br>&nbsp;<b>
        <asp:DropDownList runat="server" ID="Bud_1" DataTextField="NO_ETAB" DataValueField="NO_ETAB" AutoPostBack="true" Width="10%" />-
       </td>
      </tr>
      
     </table> 
    </td>
   </tr>
  </table>
 </ItemTemplate>
</asp:Repeater>

The dropdownlist has 102 record as I can see with the line: Response.Write(Bud_1.Items.Count)  //this display the number of records that I have in my table T_ETABLISSEMENT

But I see only blank records in my dropdownlist.

Am I missing something?

0
myriam_giroux
6/19/2008 7:55:02 PM

Hi myriam_giroux,

You can bind DropDownList in ItemDataBound event in Repeater by getting its reference and binding it.

Protected Sub RepeaterAjoutPanier_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
    'Here are some sql commands as you did above to return a dataset .
    Dim ddl As DropDownList = DirectCast(e.Item.FindControl("Bud_1"), DropDownList)
    ddl.DataSource = DsEtab 
    ddl.DataBind()
End Sub

Thanks,


Qin Dian Tang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Qin
6/24/2008 5:20:20 AM
Reply: