Remplacer Select par DropDownList
bonjour
voici un bout de code qui fonctionne correctement
le code vb
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| <%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<script language="VB" runat="server">
Sub Agent_Click(Sender As Object, E As EventArgs)
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter
Dim SelectCommand As String = "select * from agent where structure= @structure"
MyConnection = New SqlConnection("Server=(local); Initial Catalog='mission';" _
& " Trusted_Connection=True;")
MyCommand = New SqlDataAdapter(SelectCommand, MyConnection)
MyCommand.SelectCommand.Parameters.Add(New SqlParameter("@structure", SqlDbType.VarChar, 2))
MyCommand.SelectCommand.Parameters("@structure").Value = MySelect.Value
DS = new DataSet()
MyCommand.Fill(DS, "agent")
MyDataGrid.DataSource = DS.Tables("agent").DefaultView
MyDataGrid.DataBind()
End Sub
</script> |
et la partie asp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| <body style="font: 10pt verdana">
<form id="Form1" runat="server">
<h3><font face="Verdana">Afficher vers un contrôle</font></h3>
Sélectionnez un état :
<select id="MySelect" runat="server">
<option>DI</option>
<option>II</option>
<option>KO</option>
<option>KK</option>
<option>MI</option>
<option>OR</option>
<option>TN</option>
<option>UT</option>
</select>
<input id="Submit1" type="submit" OnServerClick="Agent_Click" Value="Obtenir les auteurs" runat="server"/><p>
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="700"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Names="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
EnableViewState="false"
/>
</form>
</body>
</html> |
ce code permet d'afficher le contenu d'une table à partir d'une valeur sélectionnez dans le "select".
Seulement j'aimerai le remplacer par un dropdownlist afin qu'il ne s'affiche que la(les) valeur(s) stockées dans la base
Merci pour vos suggestions!