Hi all,
I have created a DataGrid and i have included a template field of checkboxes(i.e' a column is created consisring of checkboxes) now i want to know how to get the data from the row in the datagrid where checkbox is selected and assign that data to any variable?

Thanks in Advance
Amith A

hi,
use item created or item databound event to write the code u need for checkbox

first u have to create an object of Checkbox
then u have to find that checkbox in ur Datagrid using loop like
checkbox chk;
for(int i=0;i<=datagrid.rows.count-1;i++)
{
chk=(CheckBox)Datagrid1.Items.findcontrol("CheckboxName");
if(chk.Checked)
{
"Pick the value of that row...."
}
}

first u have to create an object of Checkbox
then u have to find that checkbox in ur Datagrid using loop like
checkbox chk;
for(int i=0;i<=datagrid.rows.count-1;i++)
{
chk=(CheckBox)Datagrid1.Items.findcontrol("CheckboxName");
if(chk.Checked)
{
"Pick the value of that row...."
}
}

-----------------------------------------------------------------------------

Thanks for your reply, this i hav done can u tell me how to pick the value of the row and put it into some variable?

int32 i=e.RowIndex(); // worked in RowDataBound event

That or if you wish to set your own value, you can set an attribute on your checkbox with any value you wish. Then when a checkbox is clicked, you pull it's value. Might work better than rowIndex depending on what you're doing on your application.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.