Gridview, checkbox et button
Bonjour,
Je suis debutant en ASP.net et C#.
J'ai rencontré plusieurs problemes.
J'ai crée un gridview ou je récupere des données de ma table. J'ai ajouté dans mon gridview une colonne, des checkbox que j'ai mis dans une templatefield. Ce checkbox est checké si la valeur dans la table est 1 sinon il n'est pas checker. Jusque là tout se passe bien.
Mon probleme est le suivant:
Quand le gridview est affiché j'ai besoin de checker d'autres checkbox de quelques autres lignes. Je suis arrivé a récupéré le id de la ligne checké grace à un hiddenfield et grace a la fontion suivante
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| public String ValeursCochees()
{
string strValRet = "";
for (int i = 0; i < GridView1.Rows.Count; i++)
{
GridViewRow row = GridView1.Rows[i];
bool isChecked = ((CheckBox)row.FindControl("CheckBox1")).Checked;
if (isChecked)
{
strValRet += ((HiddenField)row.FindControl("hidden")).Value;
ArrayList a = new ArrayList();
a.Add(strValRet);
}
}
return strValRet;
} |
J'ai mis un button save pour sauvegarder le changement que j'ai fait sur mes checkbox et la je suis bloqué. J'arrive pas a updater ma table dans la base de données.
Voici ma page aspx
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
| <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Billing.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>APPLICATIONS</title>
<style type="text/css">
.marge { margin: 1em 2em 1em 2em;
width: 985px;
}
</style>
<script language="c#" runat="server">
public String ValeursCochees()
{
string strValRet = "";
for (int i = 0; i < GridView1.Rows.Count; i++)
{
GridViewRow row = GridView1.Rows[i];
bool isChecked = ((CheckBox)row.FindControl("CheckBox1")).Checked;
if (isChecked)
{
strValRet += ((HiddenField)row.FindControl("hidden")).Value;
ArrayList a = new ArrayList();
a.Add(strValRet);
}
}
return strValRet;
}
</script>
</head>
<body>
<div align="center" >
<form id="form1" runat="server">
<table align="center" border="1" width="80%">
<tr>
<td colspan="3">
<asp:Image id="Image1" imageurl="imagesiteairarabia/banniere.png"
runat="server" />
</td>
</tr>
<tr>
<td colspan="3" align="center" bgcolor="gray">
<font face="Georgia" size="2" color="#FFFFFF" >
<asp:HyperLink ID="HyperLink9" NavigateUrl="~/Default.aspx" Text='<font face="Georgia" size="2" color="#FFFFFF" >Home</font>' runat="server" Font-Underline="false"/> | <asp:HyperLink ID="HyperLink6" NavigateUrl="~/appliactions.aspx" Text='<font face="Georgia" size="2" color="#FFFFFF" >Applications</font>' runat="server" Font-Underline="false"/> | <asp:HyperLink ID="HyperLink7" NavigateUrl="~/Forms.aspx" Text='<font face="Georgia" size="2" color="#FFFFFF" >Forms</font>' runat="server" Font-Underline="false"/> | <asp:HyperLink ID="HyperLink8" NavigateUrl="~/Presentations.aspx" Text='<font face="Georgia" size="2" color="#FFFFFF" >Presentations</font>' runat="server" Font-Underline="false"/> | <asp:HyperLink ID="HyperLink10" NavigateUrl="~/Manual.aspx" Text='<font face="Georgia" size="2" color="#FFFFFF" >Manuals</font>' runat="server" Font-Underline="false"/> | <asp:HyperLink ID="HyperLink11" NavigateUrl="~/Policies.aspx" Text='<font face="Georgia" size="2" color="#FFFFFF" >Policies</font>' runat="server" Font-Underline="false"/>
</font>
</td>
</tr>
<tr>
<td colspan="3" align="center">
<asp:Label ID="Label1" runat="server" Text="Numéro"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="NUMERO"
DataValueField="NUMERO" AutoPostBack="True">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:intraConnectionString2 %>"
SelectCommand="SELECT [NUMERO] FROM [TELEPHONE] WHERE ([MATRICULE] = @MATRICULE)">
<SelectParameters>
<asp:Parameter DefaultValue="123" Name="MATRICULE" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td colspan="3" align="center">
<asp:Label ID="Label2" runat="server" Text="Year"></asp:Label>
<asp:DropDownList ID="DropDownList3" runat="server"
DataSourceID="SqlDataSource3" DataTextField="ANNEE" DataValueField="ANNEE"
AutoPostBack="True">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:intraConnectionString2 %>"
SelectCommand="SELECT [ANNEE] FROM [APPEL] WHERE ([NUMERO] = @NUMERO)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="NUMERO"
PropertyName="SelectedValue" Type="Decimal" />
</SelectParameters>
</asp:SqlDataSource>
<asp:Label ID="Label3" runat="server" Text="Month"></asp:Label>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource2" DataTextField="MOIS" DataValueField="MOIS">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:intraConnectionString2 %>"
SelectCommand="SELECT [MOIS] FROM [APPEL] WHERE (([NUMERO] = @NUMERO) AND ([ANNEE] = @ANNEE))">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="NUMERO"
PropertyName="SelectedValue" Type="Decimal" />
<asp:ControlParameter ControlID="DropDownList3" Name="ANNEE"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td colspan="3" align="center" bgcolor="#333333">
<font face="Georgia" size="2" color="#FFFFFF" >
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource4" DataKeyNames="ID_APPEL,MOIS,ANNEE">
<Columns>
<asp:BoundField DataField="NUM_FACTURE" HeaderText="Numéro Facture"
SortExpression="NUM_FACTURE" />
<asp:BoundField DataField="DATE_APPEL" HeaderText="Date Appel"
SortExpression="DATE_APPEL" />
<asp:BoundField DataField="TYPE_APPEL" HeaderText="Type Appel "
SortExpression="TYPE_APPEL" />
<asp:BoundField DataField="DESTINATION" HeaderText="Destination"
SortExpression="DESTINATION" />
<asp:BoundField DataField="MONTANT_APPEL" HeaderText="Montant Appel"
SortExpression="MONTANT_APPEL" />
<asp:BoundField DataField="DUREE_APPEL" HeaderText="Durée Appel"
SortExpression="DUREE_APPEL" />
<asp:BoundField DataField="HEURE" HeaderText="Heure Appel"
SortExpression="HEURE" />
<asp:BoundField DataField="NUM_APPELE" HeaderText="Numéro Appelé"
SortExpression="NUM_APPELE" />
<asp:TemplateField HeaderText="Appel personnel" SortExpression="appel_pers">
<EditItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server"
Checked='<%# Bind("APPEL_PERS") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# DataBinder.Eval(Container.DataItem, "APPEL_PERS").ToString() =="1" %>'
Enabled="true" AutoPostBack="true" />
<asp:HiddenField id="hidden" runat="server" Value='<%# Bind("ID_APPEL") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<%=ValeursCochees()%>
<asp:SqlDataSource ID="SqlDataSource4" runat="server"
ConnectionString="<%$ ConnectionStrings:intraConnectionString2 %>"
SelectCommand="SELECT * FROM [APPEL] WHERE (([ANNEE] = @ANNEE) AND ([NUMERO] = @NUMERO) AND ([MOIS] = @MOIS))">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList3" Name="ANNEE"
PropertyName="SelectedValue" Type="Int32" />
<asp:ControlParameter ControlID="DropDownList1" Name="NUMERO"
PropertyName="SelectedValue" Type="Decimal" />
<asp:ControlParameter ControlID="DropDownList2" Name="MOIS"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</font>
</td>
</tr>
<tr>
<td colspan="3" align="center" >
<asp:Button ID="Button1" Text="Save" runat="server" BackColor="#333333"
ForeColor="White" Font-Bold="False" Font-Names="Georgia"
onclick="Button1_Click1"/>
<asp:Button ID="Button2" runat="server" Text="Save and Confirmed" BackColor="#333333"
ForeColor="White" Font-Names="Georgia" />
</td>
</tr>
</table>
</form>
</body>
</html> |
Pourriez vous m'aider a resoudre ce probleme s'il vous plait ?
Merci.