We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Accessing control in current row


Lets say a user selected a row and entered edit mode.
A dropdown was loaded with certain values and a certain value was selected, now i would like to get to another dropdown in the same row and fill it with data.
In asp.net GridView it was something like this:

this.GridView1.Rows[this.GridView1.EditIndex].FindControl("someContorlId") as DropDownList

1 Reply

RP Rekha P Syncfusion Team July 6, 2009 05:52 AM UTC

Hi Eran,

Thank you for your interest in Syncfusion Products.

The embedded controls (EditItemTemplate) in a Grid row can be accessed by iterating through Grid top level row. Please refer a code snippet below to achieve this using DataSourceControlRowUpdating event.

void GridGroupingControl1_DataSourceControlRowUpdating(object sender, GridDataSourceControlRowUpdateEventArgs e)
{
Label1.Text = "";

DropDownList dropdown = null;
foreach (TableRow row in this.GridGroupingControl1.TopLevelTable.Rows)
{
if (row is GridRow)
{
GridRow gridRow = row as GridRow;

if (gridRow.Record != null)
{
foreach (GridCell gridCell in gridRow.Cells)
{
if (gridCell.ColumnDescriptor.Name == "Country")
{
foreach (Control cntl in gridCell.Controls[0].Controls)
{
if (cntl is DropDownList)
{
dropdown = cntl as DropDownList;
GridCellTemplated grid = (GridCellTemplated)dropdown.Parent.Parent;
GridRow gridrow1 = grid.Row;

Label1.Text += gridrow1.Record.GetValue("EmployeeID") + "--" + gridrow1.Record.GetValue("FirstName") + "--" + dropdown.SelectedItem.Text + "
";
gridRow.Record.SetValue("Country", dropdown.SelectedItem.Text);
}
}
}
}
}
}
}
}


The steps followed here are,
- Get the TableRow in the TopLevelTable
- Check if that Row is GridRow if so Iterate the Gridcells
- Find the TemplatedControl and the value.

Refer a sample illustrating the above.
http://files.syncfusion.com/support/GGC.Web/7.2.0.20/F82642_1/Sample.zip

Thanks,
Rekha

Loader.
Live Chat Icon For mobile
Up arrow icon