Link to home
Start Free TrialLog in
Avatar of Gaiala
GaialaFlag for Germany

asked on

set Focus on a programmatically created GridView

Hello,

how can I set a focus on a programmatically created gridview?
for example in gridview3 line 7?
Avatar of Velio
Velio
Flag of South Africa image

Hi Gaiala,

what do you mean by "set focus"? Set focus to the control as in calling the Focus() method, or select a row, as in setting the SelectedIndex property (seeing as how you want line 7)?
The fact that it's programatically created doesn't seem relevant to me.
Avatar of Jeeva Subburaj
yes. you have focus() method for every control which you can use it.

if you use 1.1 framework , you can create your own method and use it.

Focus myFocus = new Focus();
myFocus.SetFocus(this.Button1,this);

1    public class Focus
2    {
3    
4        public void SetFocus(Control controlToFocus, Page webPageInstance)
5        {
6    
7    
8            StringBuilder scriptFunction = new StringBuilder();
9    
10           string scriptClientId;
11           scriptClientId = controlToFocus.ClientID;
12  
13           scriptFunction.Append(
14  
15           "<script language='javascript'>");
16           scriptFunction.Append(
17  
18           "document.getElementById('");
19           scriptFunction.Append(scriptClientId);
20  
21           scriptFunction.Append(
22  
23           "').focus();");
24           scriptFunction.Append(
25  
26           "</script>");
27           webPageInstance.ClientScript.RegisterStartupScript(GetType(),"SetFocusScript",scriptFunction.ToString()
28  
29           );
30  
31       }
32  
33   }

refer here
http://forums.asp.net/t/987325.aspx
Avatar of Gaiala

ASKER

yes I mean
Set focus to the control as in calling the Focus() method

The fact that it's programatically created doesn't seem relevant to me.
ok but how can I get the Gridview I want to set the Focus?
ASKER CERTIFIED SOLUTION
Avatar of Velio
Velio
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Gaiala

ASKER

thanks