473,395 Members | 2,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

setting focus to datagrid subcontrol

Hi
I've got an ASP.NET datagrid control, and in the footer, there is a series
of controls for typing in new values to add an item.
e.g.
<asp:DataGrid runat="Server".... >
<Columns>
...
<asp:TemplateColumn HeaderText="Name">
...
<FooterTemplate>
<asp:TextBox ID="txtNameAdd" Runat="server" Width="100%"
Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>' />
</FooterTemplate>
</asp:TemplateColumn>
<asp:DataGrid>

I'm using the following C# code to try to cause this to be selected, but it
is not working.
private void dg1_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
Control txtNameAdd = e.Item.FindControl("txtNameAdd");
if(txtNameAdd == null) Debug.WriteLine("txtNameAdd is null");
else
{
string js = string.Format("<script
language=\"javascript\">document.getElementById('{ 0}').select();
document.getElementById('{0}').focus();</script>",txtNameAdd.UniqueID);
Debug.WriteLine(js);
this.RegisterStartupScript("FocusNameAdd", js);
}
}

Any ideas as to what I can do to get it working?
Nov 18 '05 #1
1 1593
Try using txtNameAdd.ClientId instead of the txtNameAdd.UniqueID. I did
a similar thing meant specifically for IE (client requirement, not mine)
and aside from that we pretty much have the same code going on.

Have A Better One!

John M Deal, MCP
Necessity Software

Bonj wrote:
Hi
I've got an ASP.NET datagrid control, and in the footer, there is a series
of controls for typing in new values to add an item.
e.g.
<asp:DataGrid runat="Server".... >
<Columns>
...
<asp:TemplateColumn HeaderText="Name">
...
<FooterTemplate>
<asp:TextBox ID="txtNameAdd" Runat="server" Width="100%"
Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>' />
</FooterTemplate>
</asp:TemplateColumn>
<asp:DataGrid>

I'm using the following C# code to try to cause this to be selected, but it
is not working.
private void dg1_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
Control txtNameAdd = e.Item.FindControl("txtNameAdd");
if(txtNameAdd == null) Debug.WriteLine("txtNameAdd is null");
else
{
string js = string.Format("<script
language=\"javascript\">document.getElementById('{ 0}').select();
document.getElementById('{0}').focus();</script>",txtNameAdd.UniqueID);
Debug.WriteLine(js);
this.RegisterStartupScript("FocusNameAdd", js);
}
}

Any ideas as to what I can do to get it working?

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ED M. | last post by:
Hello all...I'm new to the board. I have a problem that I hope someone here might be able to solve for me. I am doing some clientside validation using Javascript. The text I am testing is...
5
by: Bryan Masephol | last post by:
Hi All I got a datagrid and a ComboBox on a form. I populate the combobox with years for all the data avaiable. When the user chooses a year the datagrid is populated with the specific years...
0
by: Shravan | last post by:
Hi, I have a Windows Forms Custom DataGrid, which is put in a usercontrol, which on setting DataSource is setting focus to grid. The call stack for setting the focus is as follows. This is not...
0
by: Bonj | last post by:
Hi I've got an ASP.NET datagrid control, and in the footer, there is a series of controls for typing in new values to add an item. e.g. <asp:DataGrid runat="Server".... > <Columns> ......
2
by: jason | last post by:
Hello and Good Day. REALLY LOST. Running ASP.NET 1.1 Becuase I think I'm using my own controls smartnavigation does not appear to work for me. Stardard issue: I've got a datagrid thats...
2
by: AA | last post by:
Do anyone know how to refresh the datagrid without setting datasource to nothing and initialize the grid again? My case is that I have form consisting from two part. The upper part is a datagrid...
3
by: Darrell Wesley | last post by:
I have an application with 2 forms. Form1 is the main form and has 2 text boxes on it. Form2 is a datagrid showing a list of workorders that are to be manufactured. The user can use the mouse to...
21
by: Sharon | last post by:
I have added an auto scroll feature to my DataGrid control like this: private void DoAutoScroll() { DataView dv = m_DataGrid.DataSource as DataView; DataGridCell cell = m_DataGrid.CurrentCell;...
2
by: mfleet1973 | last post by:
Hello (again), Within my datagrid I add a control to the datagridtextboxcolumn when the underlying textbox receives focus as follows: Combobox1.Size = New...
0
by: toddw607 | last post by:
I have a datagrid in ASP.NET using VB.NET code which, when loaded it takes a parameter from the URL called DexNumb. When this parameter is brought it, it highlights the entire row Red and makes it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.