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

Set focus in edit mode

I have a GridGroupingControl with some text columns and Edit, Delete columns.
The FormEditMode is not set so it uses the default inline editing.

When I click the Edit link button on a row, I want to set the focus on the first text box that shows up.

How do I do that?

I tried the following but it didn't work

void UserGrid_RowDataBound(object sender, RowDataBoundEventArgs e)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
if (((GridCell)(e.Row.Cells[i])).ColumnDescriptor != null)
{

if (((GridCell)(e.Row.Cells[i])).ColumnDescriptor.Name == "FirstName")
{
if (e.Element.GetRowIndex() == SelectedRowIndex)
{
if (e.Row.Cells[i].Controls.Count > 0)
{
Control c = e.Row.Cells[i].Controls[0];
if (c != null)
{
c.Focus();
}
}
}
}
}
}
}




3 Replies

SN Sridhar N Syncfusion Team December 31, 2010 07:17 AM UTC

Hi Sorin,

Thanks for using Syncfusion Products.

Your requirement of setting focus to textbox on clicking EditLinkButtton can be achieved by setting Focus to corresponding cell.

Please refer the below code snippet.

[Codebehind - C#]


void GridGroupingControl1_RowDataBound(object sender, Syncfusion.Web.UI.WebControls.Grid.Grouping.RowDataBoundEventArgs e)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
if (((GridCell)(e.Row.Cells[i])).ColumnDescriptor != null)
{
if (((GridCell)(e.Row.Cells[i])).ColumnDescriptor.Name == "ID")
{
if (e.Element.GetRowIndex() == selectedrowindex )
{
e.Row.Cells[i].Focus();
}
}
}
}
}


For your convenience, we have created a sample and the same can be downloaded from the following link.

Sample1-1661924861.zip

Could you please try the above sample and get back to us with more information that whether your using EditItemTemplate or not? The information provided would be of great help in resolving the issue.

Please let us know your concerns.

Regards,
Sridhar.N





SR Sorin Rojea January 4, 2011 02:09 PM UTC

It worked, thank you!



SN Sridhar N Syncfusion Team January 5, 2011 02:34 PM UTC

Hi Sorin,

We are happy to hear that your issue is solved.Thanks for your reply.

Regards,
Sridhar.N


Loader.
Live Chat Icon For mobile
Up arrow icon