protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e){
GridView1.EditIndex = e.NewEditIndex; // turn to edit mode
BindGridView(); // Rebind GridView to show the data in edit mode
//Just changed the index of cells to where you start the focus on edit mode
TextBox tb = (TextBox)GridView1.Rows[e.NewEditIndex].Cells[2].Controls[0];
tb.Focus();
}
Ravi kant jh...
Participant
1180 Points
316 Posts
set focus at Text Box when Edit command fire in Grid View control
Feb 01, 2013 10:51 AM|LINK
I find a TextBox control from Gridview EditItemTemplate for set a focus when edit command fire.
Now i want to Focus should be from right OR all text should be selected where user can easily start typing.
Thanks In advance
Software Engineer
A good programmer is someone who looks both side before crossing a one way street.
mnmhemaj
Member
197 Points
165 Posts
Re: set focus at Text Box when Edit command fire in Grid View control
Feb 01, 2013 10:54 AM|LINK
try this
Page.RegisterStartupScript("SetFocus", "<script language=""Jscript"" > document.getElementById(""Textbox1"").focus(); </Script>")
goel.ankit
Contributor
2531 Points
513 Posts
Re: set focus at Text Box when Edit command fire in Grid View control
Feb 01, 2013 10:55 AM|LINK
you can use select() method of javascript and attach to text box
this should be of some help ->
http://www.4guysfromrolla.com/articles/021611-1.aspx
http://forums.asp.net/t/1324192.aspx/1
Ankit
(Please select 'Mark as Answer' if my response has helped you.)
Ravi kant jh...
Participant
1180 Points
316 Posts
Re: set focus at Text Box when Edit command fire in Grid View control
Feb 01, 2013 10:57 AM|LINK
.
where i write this code...? give me proper solution
and please note that i am doing this task on RowDataBound Event.
Software Engineer
A good programmer is someone who looks both side before crossing a one way street.
vinz
All-Star
127026 Points
17936 Posts
MVP
Re: set focus at Text Box when Edit command fire in Grid View control
Feb 01, 2013 11:07 AM|LINK
Try:
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e){ GridView1.EditIndex = e.NewEditIndex; // turn to edit mode BindGridView(); // Rebind GridView to show the data in edit mode //Just changed the index of cells to where you start the focus on edit mode TextBox tb = (TextBox)GridView1.Rows[e.NewEditIndex].Cells[2].Controls[0]; tb.Focus(); }MessageBox Controls for WebForms | Blog | Twitter | Linkedin
Ravi kant jh...
Participant
1180 Points
316 Posts
Re: set focus at Text Box when Edit command fire in Grid View control
Feb 01, 2013 11:15 AM|LINK
Dear Vinz,
Frist i cant find the TextBox Control (which is in EditItemTemplate) in GridView1_RowEditing event.
Second i dont want to fix the cell for focus, user any select any cell in Gridview.
Please read carefully my question.
Software Engineer
A good programmer is someone who looks both side before crossing a one way street.
vinz
All-Star
127026 Points
17936 Posts
MVP
Re: set focus at Text Box when Edit command fire in Grid View control
Feb 01, 2013 11:48 AM|LINK
My apology if I didn't follow your question correctly. I'm not on my dev machine right now so I never tested on this but you can try like this:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e){ if ((e.Row.RowState & DataControlRowState.Edit) > 0) { //e.Row.Cells[1].Controls[0].Focus(); //Or to a specific control in TemplateField // e.Row.FindControl("YourTextBoxID").Focus(); TextBox tb = (TextBox)e.Row.FindControl("YourTextBoxID"); string theScript = "document.getElementById('" + tb.ClientID + "').select();" ClientScript.RegisterClientScriptBlock(this.GetType(), "onload", "window.onload = function() { " + theScript + " }", true); } }MessageBox Controls for WebForms | Blog | Twitter | Linkedin