jai une dropdownlist rempli avec des elements et quand je selectionne un element , et quand je clique sur le bouton rechercher , il doit m afficher dans un gridview ...
merci a vous
Version imprimable
jai une dropdownlist rempli avec des elements et quand je selectionne un element , et quand je clique sur le bouton rechercher , il doit m afficher dans un gridview ...
merci a vous
et quel est ton problème ?? car là tu ne donnes pas beaucoup d'informations ...
Je ne comprends rien, soit plus clair et en francais !!!
en fait je dois faire une recherche avec une combo et doit afficher le resultat dans un gridview en asp.net 2.0...
le probleme est qu'il me dit nom de colonne non valide...
voici le code :
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 protected void btnRech_Click1(object sender, EventArgs e) { string dbConnectionString = string.Empty; dbConnectionString = ConfigurationManager.ConnectionStrings["DORMEUIL_TESTConnectionString"].ConnectionString; SqlConnection cnx = new SqlConnection(dbConnectionString); SqlCommand cmd = cnx.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT * FROM Product WHERE composition = " + DropDownList1.SelectedItem.Text; try { cnx.Open(); SqlDataReader reader = cmd.ExecuteReader(); GridView1.DataSource = reader.ToString(); GridView1.DataBind(); } catch (Exception ex) { Label1.Text = ex.Message.ToString(); } finally { cnx.Close(); }
montre nous ta gridview mais a mon avis tu fais reference a un nom de colonne dans ta gridview qui n 'existe pas dans le retour de ta requete sql.
voici mon gridview :
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2" DataTextField="composition" DataValueField="ProductID"> </asp:DropDownList> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:DORMEUIL_TESTConnectionString %>" SelectCommand="SELECT [ProductID],[composition] FROM [Product]"> </asp:SqlDataSource> <br/> <asp:Button ID="btnRech" runat="server" Text="Rechercher" OnClick="btnRech_Click1" /><br /> <asp:GridView PageSize="10" Width="100%" OnRowCommand="list_ItemCommand" DataKeyNames="ProductID" ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None"> <Columns> <asp:BoundField DataField="composition" HeaderText="composition" SortExpression="composition" /> <asp:BoundField DataField="Poids" HeaderText="Poids" SortExpression="Poids" /> <asp:ImageField DataImageUrlField="Image1Prod" HeaderStyle-Font-Size="Small" HeaderText="Particularités" AlternateText="Particularités" ></asp:ImageField> </Columns>
jai maintenant cette erreur : DataBinding : 'System.Char' ne comporte pas de propriété appelée 'ProductID'
quelq u un a t il une idee sur lerrerur .?
es tu sure que ta requete fonctionne deja ? et retourne bien un jeu d'enregistrement