|
Bonjour les amis,
voilà je voudrai savoir comment peut-on lier un detailsview avec un Gridview mais sans utiliser un datasource.
je m'explique:
j'ai un Gridview que je viens de remplir par une recherche et ce en utilisant une requette SQL et biensûr un datareader (donc pas de Datasource utilisé).
après j'ai rajouter une collone "Select" et là je voudrai faire afficher le détail de chaque ligne de mon Gridview sur un Detailsview qui lui aussi comporte une liste de boutons "Edit/Update/Cancel et Delete" pour faire les mises à jour sur ma table de BDD.
champs de ma table TBLTEST
ID: Int
Nom: String
Prenom: String
Utilisateur: SessionWindows
- Comment puis-je afficher avec programmation mon Detailsview en selectionnant une ligne de mon Gridview.?
- Comment programmer les evennement "Edit", "Update", "Cancel" et "Delete" pour que je puisse interragir selon mon choix sur la mise à jour utilisant une requête SQL. (tout celà parceque je voudrai capter le nom de la session de l'utilisateur et l'enregistrer sur ma table SQL et ça je ne vois pas comment le faire en utilisant un Datasource).
merci de m'aider là-dessus
(un bout de code bien commenter ça serait super)
ci-desous les deux bouts de code que j'ai pu faire à savoir le peuplage de mon Gridview "Gvtest" sans utiliser de Datasource, ainsi que mon DetailsView "DetailsView1" qui lui attend toujours comment le lier par programmation pour faire par la suite les mises à jour necessaires incluant la collonne "Utilisateur":
la BDD : TWEM
la Table: TBLTEST
les champs:
ID ---- Int
Nom ---- String
Prenom ---- string
Utilisateur ---- String (session windows de chaque utilisateur).
mon codes:
---------------
C#
---------------
protected void BtnRecherche_Click(object sender, EventArgs e) { SqlConnection connection = new SqlConnection("Data Source=Server;Initial Catalog=TWEM;Persist Security Info=True;User ID=user;Password=passw"); try { connection.Open(); } catch (Exception ex) { resultatlbl.Text = ex.Message; } try { string sSql; sSql = "SELECT * From TBLTEST Where Nom Like '" + TxtBoxRecherche1.Text + "%' AND Prenom Like '" + TxtBoxRecherche2.Text + "%'"; SqlCommand cmd = new SqlCommand(sSql, connection); SqlDataReader reader = cmd.ExecuteReader(); Gvtest.DataSource = reader; Gvtest.DataBind(); reader.Close(); } catch (Exception ex) { resultatlbl.Text = ex.Message; } finally { connection.Close(); } }
----------------
ASP.NET
----------------
<body> <form id="form1" runat="server"> <div> <table width="100%"> <tr> <td style="width: 221px; height: 33px"> </td> <td style="text-align: left; height: 33px;" colspan="2"> <span style="font-size: 16pt"> Rechercher un Enregistrement ...</span></td> <td style="width: 213px; height: 33px;"> </td> </tr> <tr> <td style="width: 221px"> </td> <td style="width: 200px"> Par Raison Sociale :</td> <td> <asp:TextBox ID="TxtBoxRecherche1" runat="server" Width="195px"></asp:TextBox> et / ou</td> <td style="width: 213px"> </td> </tr> <tr> <td style="width: 221px"> </td> <td style="width: 200px"> Par N° Client :</td> <td> <asp:TextBox ID="TxtBoxRecherche2" runat="server" Width="195px"></asp:TextBox></td> <td style="width: 213px"> </td> </tr> <tr> <td style="width: 221px"> </td> <td align="right"> <asp:Button ID="BtnRecherche" runat="server" Text="Rechercher ..." OnClick="BtnRecherche_Click" /></td> <td> <asp:Button ID="BtnEffacer" runat="server" Text="Effacer" Width="105px" /></td> <td style="width: 213px"> </td> </tr> <tr> <td style="width: 221px; height: 21px"> </td> <td style="width: 200px; height: 21px;"> </td> <td style="width: 268px; height: 21px;"> </td> <td style="width: 213px; height: 21px;"> </td> </tr> <tr> <td style="width: 221px; height: 185px"> </td> <td colspan="2" style="height: 185px"> <asp:Panel ID="Panel1" runat="server" Height="170px" ScrollBars="Auto" Width="470px"> <asp:GridView ID="Gvtest" runat="server" CellPadding="4" ForeColor="#333333" Width="576px" AutoGenerateColumns="False" Font-Bold="True" Font-Names="Arabic Transparent" HorizontalAlign="Left" DataKeyNames="ID" EmptyDataText = "Aucun résultat Trouvé" > <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /> <RowStyle BackColor="#E3EAEB" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" /> <EditRowStyle BackColor="#7C6F57" /> <SelectedRowStyle BackColor="Gold" Font-Bold="True" ForeColor="#333333" Font-Italic="False" Font-Underline="False" /> <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" /> <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" Font-Size="16pt" /> <AlternatingRowStyle BackColor="White" /> <Columns> <asp:CommandField ShowSelectButton="True" /> <asp:BoundField DataField="ID" HeaderText="ID" Visible="False" /> <asp:BoundField DataField="Nom" HeaderText="Le Nom" /> <asp:BoundField DataField="Prenom" HeaderText="Le Prenom" /> </Columns> </asp:GridView> </asp:Panel> </td> <td style="width: 213px; height: 185px"> </td> </tr> <tr> <td style="width: 221px; height: 31px"> </td> <td style="height: 31px;" align="center" colspan="2"> <asp:Label ID="resultatlbl" runat="server" Font-Size="Larger" ForeColor="#C00000"></asp:Label></td> <td style="width: 213px; height: 31px;"> </td> </tr> </table> </div> <br /> <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" CellPadding="4" ForeColor="#333333" GridLines="None" Height="50px" Width="296px" > <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" /> <EditRowStyle BackColor="#2461BF" /> <RowStyle BackColor="#EFF3FB" /> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> <Fields> <asp:BoundField DataField="ID" HeaderText="le ID" ReadOnly="True" SortExpression="ID" /> <asp:BoundField DataField="Nom" HeaderText="Le Nom" SortExpression="Nom" /> <asp:BoundField DataField="Prenom" HeaderText="Le Prenom" SortExpression="Prenom" /> <asp:CommandField ShowEditButton="True" /> </Fields> <FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" /> <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <AlternatingRowStyle BackColor="White" /> </asp:DetailsView> <br /> <br /> <br /> </form> </body>
--------
merci à vous les amis :)
|