Topaz Filer: if you use e-mail for business, we can save you money and decrease your risk.
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
Reply to this message...
Vote that this is a GOOD answer...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
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]

Reply to this message...
Vote that this is a GOOD answer...
 
Outlook interop - stopping user properties appearing on Outlook message print
Seriously, why is “cut and paste” majorly newsworthy???
 
    
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]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
suhas shinde
(Type your message here)

--------------------------------
From: suhas shinde
Reply to this message...
Vote that this is a GOOD answer...
 
Email Archiving and Email Filing - what’s the difference?
Web-based task/todo list management
 
    
viswa babu
(Type your message here)

--------------------------------
From: viswa babu
Reply to this message...
Vote that this is a GOOD answer...
 
Open source windows
The Law Society’s guidelines on e-mail management
 
 
System.Data.DataSet
System.String
System.Web.UI.WebControls.CheckBox
System.Web.UI.WebControls.DataGridItem
System.Web.UI.WebControls.TemplateColumn
System.Windows.Forms.CheckBox




Ad
BootFX
Reliable and powerful .NET application framework.
Recession Busting Bespoke Software
Get through the recession by investing in bespoke software to decrease costs and create commercial opportunities.
Other DN247 Network Sites
.NET 247
SQL Server Wins
Old Skool Developer
 
Copyright © AMX Software Ltd 2008-2009. Portions copyright © Matthew Baxter-Reynolds 2001-2009. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - .NET 247 is a member of the DN247 Network - 4.0.30129.1734