Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

Passing command arguments to a checkbox

, 21 Jun 2010
Rate this:
Please Sign up or sign in to vote.
Add batch printing functionality to an application
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<CheckBox>("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);

License

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

Share

About the Author

e.bonavero-miller

United Kingdom United Kingdom
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 21 Jun 2010
Article Copyright 2010 by e.bonavero-miller
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid