Checkbox in Datagrid of ASP.NET

Hi I''m using the checkbox as a template column in datagrid. I was able to add the checkbox but I''m not able to retreive which checkbox have been clicked. I have gon through ur articles 25.71,25.76,25.77 but still not able to retrieve the checked value! Plz help by clearly stating how to use them! thanks and regards! Megha

4 Replies

AD Administrator Syncfusion Team February 23, 2006 01:08 PM UTC

Hi Megha, You can easily get the row of which row is clicked , There are a lot ways to do this. Eg. In the ButtonClickedevent in server try one of the following ( applies for all controls events not only for button you can use check box , I already have the sample for button click) [C#] Button btn = (Button)sender as Button; DataGridItem myItem =(DataGridItem) btn.NamingContainer; //This will return the selected rows index value starts from 0 myItem.ItemIndex; //also you can use to get some of the key field of that row with the following code //Here i assume first column will have a unique value so given Cells[0] and in which you can use for your changes in server side. string rowId; rowId = myItem.Cells[0].Text; I guess the above codings should give you some idea Regards, A.Sivakumar


MB Megha Bansal February 24, 2006 04:46 AM UTC

Hi SivaKumar. Thanks for ur reply! But I''m sorry it didnt work. It gave me error on line myitem.itemindex; saying only assignment,call,increment,decrement, and new obeject expressions can be used as a statement. plz check the error code and reply me back. Thanks and Regards! Megha >Hi Megha, > >You can easily get the row of which row is clicked , There are a lot ways to do this. > >Eg. >In the ButtonClickedevent in server try one of the following ( applies for all controls events not only for button you can use check box , I already have the sample for button click) > >[C#] > Button btn = (Button)sender as Button; > DataGridItem myItem =(DataGridItem) btn.NamingContainer; > >//This will return the selected rows index value starts from 0 > >myItem.ItemIndex; > >//also you can use to get some of the key field of that row with the following code > >//Here i assume first column will have a unique value so given Cells[0] and in which you can use for your changes in server side. > > string rowId; > rowId = myItem.Cells[0].Text; > > >I guess the above codings should give you some idea > >Regards, >A.Sivakumar >


AD Administrator Syncfusion Team February 24, 2006 08:55 AM UTC

> >Hi SivaKumar. > Hi Megha, As i said before , " this will return the value start from 0" . you can probably use int something=myItem.ItemIndex; and this something will be your rowindex Let me know if this helps Best Regards, A.Sivakumar //This will return the selected rows index value starts from 0 >> >>myItem.ItemIndex; >> >>//also you can use to get some of the key field of that row with the following code >> >>//Here i assume first column will have a unique value so given Cells[0] and in which you can use for your changes in server side. >> >> string rowId; >> rowId = myItem.Cells[0].Text; >> >> >>I guess the above codings should give you some idea >> >>Regards, >>A.Sivakumar >>


TY tyt March 3, 2006 11:40 AM UTC

>Hi > >I''m using the checkbox as a template column in datagrid. I was able to add the checkbox but I''m not able to retreive which checkbox have been clicked. >I have gon through ur articles 25.71,25.76,25.77 but still not able to retrieve the checked value! > >Plz help by clearly stating how to use them! > >thanks and regards! >Megha

Loader.
Up arrow icon