Passing command arguments to a checkbox - xfgr.com Click here to Skip to main content
 

Passing command arguments to a checkbox

Add batch printing functionality to an application
Sign Up to vote for this article
Add a reason or comment to your vote: x
0
answers
3.0/5
1 vote
395
views
Tags: C#, ASP.NET

I needed to add batch printing functionality to an application.

I added a Gridview to a page and handled the GridView OnRowDataBound event.
I added a TemplateField ItemTemplate to the Columns collection with a checkbox (to include in batch printing job).
I added a batch print button and handled the OnClick event:

protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (DataBinder.Eval(e.Row.DataItem, "ApplicantId") != System.DBNull.Value)
{
int applicantId = System.Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "ApplicantId"));
int applicationId = System.Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "ApplicationId"));
CheckBox cbPrint = e.Row.FindControlRecursive("cbPrint");
cbPrint.Attributes["CommandArgument"] = string.Format("{0},{1}", applicationId, applicantId);
}
}
}

In the batch print OnClick event, I added:

string args = checkbox.Attributes["CommandArgument"].Split(',');
if (args.Length == 2)
{
int applicationId, applicantId;
int.TryParse(args[0], out applicationId);
int.TryParse(args[1], out applicantId);
RAM.OLSA.Services.ApplicationService applicationService = new RAM.OLSA.Services.ApplicationService();
RAM.OLSA.Entities.Application application = applicationService.GetByApplicationIdApplicantId(applicationId, applicantId);
Posted 17 Jun '10 2:45 AM
Edited 21 Jun '10 3:40 AM
Revision 2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Hint: For improved responsiveness use Internet Explorer 4, Firefox or above. Ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
FAQ FAQ   
Noise Tolerance  Layout  Per page   
  (Refresh) 
-- There are no messages in this forum --

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Last Updated 26 Mar 2009
Web21 2.3.0027 Advertise Privacy