Nell’ applicazione che ho appena terminato, ho dovuto rispolverare le nozioni base sulle GridView e su come inserire colonne "custom". In questo piccolo esempio, vediamo come inserire, per ogni riga, un controllo CheckBox.
<asp:GridView ID="GridView1" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkSeleziona" runat="server" Text=" " Width="18px" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="valore" HeaderText="IdDocumento" />
</Columns>
</asp:GridView>
Per recuperare tutti i "valori" selezionati:
protected void bntRecuperaId_Click(object sender, EventArgs e)
{
StringBuilder elencoValori = new StringBuilder();
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox objCheckBox = (CheckBox)GridView1.Rows[i].FindControl("chkSeleziona");
if (objCheckBox .Checked)
{
elencoValori .AppendFormat("{0},", GridView1.Rows[i].Cells[2].Text);
}
}
Response.Write(elencoIdDoc.ToString());
}




Settembre 17th, 2008 at 11:45
Have I got a gridview with a pagesize and when I going to the next page I lost the check and the value ?What Can I resolve it?
Thanks
Tom
Settembre 17th, 2008 at 12:27
Hi Tom, you can see this exsample: http://forums.asp.net/p/1256599/2342141.aspx
regards.
Settembre 17th, 2008 at 13:39
Thanks I have seen this code but I don’t uderstood How I put this your code with this
http://forums.asp.net/p/1256599/2342141.aspx
Because in your code I get the values but the other code is the trace for checkbox.
Please Could you have some example of full code ?
Sorry for my english
Thanks Tom
Settembre 17th, 2008 at 14:15
Sorry I have understood
Thanks
Settembre 17th, 2008 at 14:31
i’m sorry, i haven’t full code