How to Pass Checkbox to the datagrid data in C#.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neehakale
    New Member
    • Aug 2007
    • 46

    How to Pass Checkbox to the datagrid data in C#.net

    I am doing an application where i need to select some data from the grid,to select the data from the grid ,each and every row and column data should come with some selection control..m using checkbox here..so can ny body of u know how to pass checkboxes to the datagrid,so that we can select tha data from the grid....its urgent pls rp soon
  • aliasruel
    New Member
    • Sep 2007
    • 73

    #2
    Hi neehakale,

    To add a checkbox control in your datagrid.
    1. Right click on your datagrid
    2. Go to property builder
    3. Select columns
    4. In the Available columns box, select Template Column
    5. After adding, click Ok Button.
    6. Right click again on your datagrid but this time select Edit template
    7. You will see that there is column(0).
    8. In the item template, drag and drop a check box control.
    9. after adding the check box control. right click again then select End Template Editing.
    10. Your done adding a checkbox.
    11. if you want to go back.. just follow the same procedure.


    assuming the name of your checkbox control is CheckBox1
    and your datagrid name is DataGrid1
    please create a button named btnCheckedItems ..
    in the click event of this button.. you place the code below
    this program will identify if there are checked items and perform any action.

    private void btnCheckedItems _Click(object sender, System.EventArg s e)
    {
    //identify if there are checked items here
    int NoOfCheckedItem s=0;

    foreach (DataGridItem i in DataGrid1.Items )
    {
    CheckBox ItemsChecked = (CheckBox) i.FindControl ("CheckBox1" );
    if (ItemsChecked.C hecked)
    {
    NoOfCheckedItem s +=1;
    //retrieve/check the current value of the selected item
    Response.Write( i.Cells[1].Text);
    }
    }
    Response.Write( NoOfCheckedItem s);
    }

    I hope this will help you.

    Best Regards,
    Ruel
    YM ID:uelskies@yah oo.com




    Originally posted by neehakale
    I am doing an application where i need to select some data from the grid,to select the data from the grid ,each and every row and column data should come with some selection control..m using checkbox here..so can ny body of u know how to pass checkboxes to the datagrid,so that we can select tha data from the grid....its urgent pls rp soon

    Comment

    • neehakale
      New Member
      • Aug 2007
      • 46

      #3
      M not getting this column field in the property builder.....M usinf .net framework 1.1 visual studdio.net 2003....

      Comment

      • santuvssantu
        New Member
        • Jun 2007
        • 12

        #4
        Hi,
        You can create a template column for checkbox. Please go through below one.
        Hope this helps.
        http://www.xmlfox.com/CSsamples.htm

        Comment

        • aliasruel
          New Member
          • Sep 2007
          • 73

          #5
          Hi neehakale]M,

          Is it for Web or Windows Apps?
          Because what I sent to you is for the web application (framework 1.1)
          tnx.

          Ruel



          Originally posted by neehakale
          M not getting this column field in the property builder.....M usinf .net framework 1.1 visual studdio.net 2003....

          Comment

          • neehakale
            New Member
            • Aug 2007
            • 46

            #6
            It is for Windows application.... .pls help me

            Comment

            Working...