473,568 Members | 2,762 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Control Focus and DataList

Once the datalist is in edit mode and the text boxes and all happily appear,
how can I force the textbox to be the control with focus, so the user can
start editing without having to click the textbox first? Thanks.

Jerry
Nov 19 '05 #1
4 2778
In the past, I have put the following code in the ItemDataBound event of the
text box.

Where TextBoxToFocusI d in the text box id in the datagrid

private void DataGrid1_ItemD ataBound(object sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e)
{
if (e.Item.ItemTyp e == ListItemType.Ed itItem)
{
TextBox txt = e.Item.FindCont rol("TextBoxToF ocusId");
RegisterClientS criptBlock("Dat aGridFocus",
string.Format(" <script
language=\"java script\">docume nt.getElementBy Id('{0}').focus ();</script>",
txt.ClientID));
}
}

--
Jay Douglas
http://www.jaydouglas.com
"Jerry Camel" <rl*****@msn.co m> wrote in message
news:O6******** ******@TK2MSFTN GP14.phx.gbl...
Once the datalist is in edit mode and the text boxes and all happily
appear,
how can I force the textbox to be the control with focus, so the user can
start editing without having to click the textbox first? Thanks.

Jerry

Nov 19 '05 #2
Here's the problem... The Datalist control renders the code and assigns IDs
and names to all the controls. So you don't know the name of the control
that needs the focus until the html is rendered. And the name will be
different for every line in the datalist.

For instance, I named the textbox "txtName", but the ID when rendered is
something like "dlEntities__ct l4_txtName" and if I click a different record
to edit, the name would be different. How can you tell what control to set
the focus to?

Thanks.
"Jay Douglas" <ja************ ****@jaydouglas .com> wrote in message
news:u$******** ******@TK2MSFTN GP09.phx.gbl...
In the past, I have put the following code in the ItemDataBound event of the text box.

Where TextBoxToFocusI d in the text box id in the datagrid

private void DataGrid1_ItemD ataBound(object sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e)
{
if (e.Item.ItemTyp e == ListItemType.Ed itItem)
{
TextBox txt = e.Item.FindCont rol("TextBoxToF ocusId");
RegisterClientS criptBlock("Dat aGridFocus",
string.Format(" <script
language=\"java script\">docume nt.getElementBy Id('{0}').focus ();</script>",
txt.ClientID));
}
}

--
Jay Douglas
http://www.jaydouglas.com
"Jerry Camel" <rl*****@msn.co m> wrote in message
news:O6******** ******@TK2MSFTN GP14.phx.gbl...
Once the datalist is in edit mode and the text boxes and all happily
appear,
how can I force the textbox to be the control with focus, so the user can start editing without having to click the textbox first? Thanks.

Jerry


Nov 19 '05 #3
Per the example below, you on the ItemDataBound event, you can use:

TextBox txt = (TextBox) e.Item.FindCont rol("txtName");

then txt.ClientID will return the full control name, ie:
dlEntities__ctl 4_txtName

--
Jay Douglas
http://www.jaydouglas.com
"Jerry Camel" <rl*****@msn.co m> wrote in message
news:ek******** ******@TK2MSFTN GP09.phx.gbl...
Here's the problem... The Datalist control renders the code and assigns
IDs
and names to all the controls. So you don't know the name of the control
that needs the focus until the html is rendered. And the name will be
different for every line in the datalist.

For instance, I named the textbox "txtName", but the ID when rendered is
something like "dlEntities__ct l4_txtName" and if I click a different
record
to edit, the name would be different. How can you tell what control to
set
the focus to?

Thanks.
"Jay Douglas" <ja************ ****@jaydouglas .com> wrote in message
news:u$******** ******@TK2MSFTN GP09.phx.gbl...
In the past, I have put the following code in the ItemDataBound event of

the
text box.

Where TextBoxToFocusI d in the text box id in the datagrid

private void DataGrid1_ItemD ataBound(object sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e)
{
if (e.Item.ItemTyp e == ListItemType.Ed itItem)
{
TextBox txt = e.Item.FindCont rol("TextBoxToF ocusId");
RegisterClientS criptBlock("Dat aGridFocus",
string.Format(" <script
language=\"java script\">docume nt.getElementBy Id('{0}').focus ();</script>",
txt.ClientID));
}
}

--
Jay Douglas
http://www.jaydouglas.com
"Jerry Camel" <rl*****@msn.co m> wrote in message
news:O6******** ******@TK2MSFTN GP14.phx.gbl...
> Once the datalist is in edit mode and the text boxes and all happily
> appear,
> how can I force the textbox to be the control with focus, so the user can > start editing without having to click the textbox first? Thanks.
>
> Jerry
>
>



Nov 20 '05 #4
Figured it out right after I sent that note. Thanks for the info - much
appreciated.

"Jay Douglas" <ja************ ****@jaydouglas .com> wrote in message
news:eB******** ******@tk2msftn gp13.phx.gbl...
Per the example below, you on the ItemDataBound event, you can use:

TextBox txt = (TextBox) e.Item.FindCont rol("txtName");

then txt.ClientID will return the full control name, ie:
dlEntities__ctl 4_txtName

--
Jay Douglas
http://www.jaydouglas.com
"Jerry Camel" <rl*****@msn.co m> wrote in message
news:ek******** ******@TK2MSFTN GP09.phx.gbl...
Here's the problem... The Datalist control renders the code and assigns
IDs
and names to all the controls. So you don't know the name of the control that needs the focus until the html is rendered. And the name will be
different for every line in the datalist.

For instance, I named the textbox "txtName", but the ID when rendered is
something like "dlEntities__ct l4_txtName" and if I click a different
record
to edit, the name would be different. How can you tell what control to
set
the focus to?

Thanks.
"Jay Douglas" <ja************ ****@jaydouglas .com> wrote in message
news:u$******** ******@TK2MSFTN GP09.phx.gbl...
In the past, I have put the following code in the ItemDataBound event of
the
text box.

Where TextBoxToFocusI d in the text box id in the datagrid

private void DataGrid1_ItemD ataBound(object sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e)
{
if (e.Item.ItemTyp e == ListItemType.Ed itItem)
{
TextBox txt = e.Item.FindCont rol("TextBoxToF ocusId");
RegisterClientS criptBlock("Dat aGridFocus",
string.Format(" <script

language=\"java script\">docume nt.getElementBy Id('{0}').focus ();</script>", txt.ClientID));
}
}

--
Jay Douglas
http://www.jaydouglas.com
"Jerry Camel" <rl*****@msn.co m> wrote in message
news:O6******** ******@TK2MSFTN GP14.phx.gbl...
> Once the datalist is in edit mode and the text boxes and all happily
> appear,
> how can I force the textbox to be the control with focus, so the user

can
> start editing without having to click the textbox first? Thanks.
>
> Jerry
>
>



Nov 20 '05 #5

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

Similar topics

0
3092
by: Alex | last post by:
Interested in more .NET stuff visit www.dedicatedsolutions.co.uk The DataList is not as powerful as the DataGrid. It requires more work from you since it has no default data presentation format. However, the DataGrid begins to get very cumbersome as the number of columns of data you present increases. Anything more than half a dozen columns...
1
10920
by: bill yeager | last post by:
I have a datagrid control within a datalist control. When I try and do a "Find" on the control, the object comes back with nothing and then my pgm crashes. I am 100% sure that my datagird inside my datalist has an id of "Datagrid3". dgChild comes back with "Nothing" while debugging. Here is my code in the itemdatabound event for the...
6
8605
by: Davids | last post by:
having a 100% working aspx page I wanted to create a user control from a small DataList section (which has an ID="DataList1") of the page, so I created an ascx file with the DataList and Register the control as should be done. Now the DataList1 can't be found any more: The name 'DataList1' does not exist in the current context why's that??
2
2197
by: Olav Tollefsen | last post by:
I have a Web Form with a DataList. Inside the ItemTemplate, I have a DropDownList control. <asp:DataList ID="ProductDataList" Runat="server"> <ItemTemplate> <asp:DropDownList ID="DropDownList1" Runat="server" DataTextField="PropertyValue" DataValueField="PropertyValueId"> </asp:DropDownList> </ItemTemplate> </asp:DataList>
1
2164
by: yer darn tootin | last post by:
Ahoy, I have an aspx web page that loads an ascx control that's populated with various items ( in a datalist ). Select an item and the page reloads and the datalist now shows the details. >From here I want to put a print option in, a button that will either immediately print the contents of the datalist or maybe pop-up something with...
2
3427
by: Hans Merkl | last post by:
Hi, I am trying to use a user control as EditItemTemplate in a DataList. It loads fine but I can't figure out how to bind to the data of the DataList. Here is what I have got so far: //Page_load of my user control protected void Page_Load(object sender, EventArgs e) { IDataItemContainer DataContainer = this.Parent as
4
2143
by: Sam Martin | last post by:
Hi, I have got a User Control that contains for the sake of argument, a single DataList control. eg. <asp:DataList id="DataListMain" runat="server" RepeatDirection="Horizontal" RepeatColumns="4" Width="100%" GridLines="Vertical"> <ItemTemplate>
1
3953
by: shantanu_kush | last post by:
Hi there, I am using a DataList in a composite control. The DataList has an Custom ItemTemplate(ITemplate) which adds a Button to the DataList Item as shown in the code below : public class DatalistItemTemplate : ITemplate { public void InstantiateIn(Control container)
6
2210
by: Victor | last post by:
Hi. all I have a customize web control. I have three simple properties and customized render class. then I add this control into my datalist like <asp:DataList ID="datalist" runat="server" RepeatColumns="3"> <ItemTemplate> <uc:mycontrol id="test" runat="server" /> </ItemTemplate> </asp:DataList> In the code-behind I have something like...
0
7604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7916
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8117
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7660
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
932
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.