|
| Checkbox in Datagrid |
|
|
|
|
| Messages |
|
Related Types |
This message was discovered on microsoft.public.dotnet.distributed_apps.
| Anderson |
Hi all,
I've been trying to have a simple checkbox in my datagrid using C# and it's being a pain to get it to work. Here is the cenario.
I have a DataSet populated with a table "Employees" let's say. This table has fields such id, name, email. All I want to do is to display an extra column in my datagrid that will display a checkbox for each row. Note, there is no data associated with this checkbox. I just wanted the user to select some of the Employees from the datagrid by checking the checkbox. Then, when they click the button "Print", I will loop through the datagrid, get the selected ones and print.
Anyone can give me some instructions or example of how to do that? I've been looking some people examples that do something similar. But they don't really show how to add an extra column to the datagrid with a checkbox for each record of your already populated dataset.
Please, any help will be appreciated. Thanks to all.
Anderson
|
|
|
| |
|
| |
| |
| Tim Cleland |
In your Web Form (aspx page) add something like the following to your datagrid
<asp:datagrid id="dgEmployees" runat="server"... .... <asp:TemplateColumn HeaderText="Select"> <ItemTemplate> <asp:CheckBox id="chkEmployees" runat="server"></asp:CheckBox> </ItemTemplate> </asp:TemplateColumn> .... </asp:datagrid>
in your code behind on the "print" handler add the following:
DataGridItem dgItem = null; int iEmployeeId = 0; CheckBox chkBox = null;
for (int i=0; i < dgEmployees.Items.Count; i++) { dgItem = dgEmployees.Items[i]; chkBox = (CheckBox)dgItem.FindControl("chkEmployees"); if ((chkBox != null) && chkBox.Checked) { // Assuming you ID column is the first cell iEmployeeId = int.Parse(dgItem.Cells[0].Text); //Now run your print code here for this employee id
//Response.Write(String.Format("{0}<br>",iEmployeeId.ToString())); } }
Tim C timc[NOSpAmmY]@techie.com[REMOVE]
On Tue, 9 Apr 2002 04:13:27 -0700, "Anderson" <Click here to reveal e-mail address> wrote:
[Original message clipped]
|
|
|
| |
|
| |
|
| |
| Tim Cleland |
In your Web Form (aspx page) add something like the following to your datagrid
<asp:datagrid id="dgEmployees" runat="server"... .... <asp:TemplateColumn HeaderText="Select"> <ItemTemplate> <asp:CheckBox id="chkEmployees" runat="server"></asp:CheckBox> </ItemTemplate> </asp:TemplateColumn> .... </asp:datagrid>
in your code behind on the "print" handler add the following:
DataGridItem dgItem = null; int iEmployeeId = 0; CheckBox chkBox = null;
for (int i=0; i < dgEmployees.Items.Count; i++) { dgItem = dgEmployees.Items[i]; chkBox = (CheckBox)dgItem.FindControl("chkEmployees"); if ((chkBox != null) && chkBox.Checked) { // Assuming you ID column is the first cell iEmployeeId = int.Parse(dgItem.Cells[0].Text); //Now run your print code here for this employee id
//Response.Write(String.Format("{0}<br>",iEmployeeId.ToString())); } }
Tim Cleland timc[NOSpAmmY]@techie.com[REMOVE]
On Tue, 9 Apr 2002 04:13:27 -0700, "Anderson" <Click here to reveal e-mail address> wrote:
[Original message clipped]
|
|
|
| |
|
|
| |
|
| |
| suhas shinde |
(Type your message here)
-------------------------------- From: suhas shinde
|
|
|
| |
|
| |
|
| |
| viswa babu |
(Type your message here)
-------------------------------- From: viswa babu
|
|
|
| |
|
| |
|
|
|
|
|
|
|
|
BootFX
Reliable and powerful .NET application framework. |
|
|
|
|
|
|