473,796 Members | 2,560 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding Focus to new row to a DataGrid using Autogenerated Columns

Once a user clicks "add new row", a new row is created in my Datagrid. The
datasource is huge so they have to scroll to the bottom of the page to edit
the data in the new row. I have come across two EE solutions which use
javascript to focus on the textbox in the "editcommandcol umn" mode.
However, these solutions were made for non-autogenerated columns. I NEED
autogenerated columns for my project.

Is it possible to give focus to a textbox created from an autogenerated
column? If not i'll just live with it :)

Code I used in my "add row" click event:
Dim scriptJs As String
Dim index as Integer = DataSet11.Table s(0).Rows.Count-1
DataGrid1.EditI temIndex = index
myComponent.Fil lDataSet(DataSe t11)
DataBind()
Dim focusBox As TextBox
focusBox = DataGrid1.Items (index).Cells(0 ).Controls(0) <-****
error here**** (TypeCast is invalid)

scriptJs = "<Script Language=JavaSc ript>" & vbCrLf
scriptJs &= "document.getEl ementById('" & focusBox.Unique ID &
"').focus() ;" & vbCrLf
scriptJs &= "document.getEl ementById('" & focusBox.Unique ID &
"').select( );" & vbCrLf
scriptJs &= "<" & "/script>"
If (Not Me.IsStartupScr iptRegistered(" Startup")) Then
Me.RegisterStar tupScript("Star tup", scriptJs)
End If

Controls(0) is a LinkButton (for edit command column)
Controls(1) is a LinkButton (for deleting a column)
Controls(2) does not exist, etc

Here is my frontend asp.net code:

<asp:linkbutt on id="LinkButton1 " runat="server"
onclick="LinkBu tton1_Add">Crea te New Row</asp:linkbutton>
<br>
<asp:datagrid id="DBGrid1" runat="server" ondeletecommand ="DBGrid1_Delet e"
oneditcommand=" DBGrid1_Edit"
oncancelcommand ="DBGrid1_Cance l" onupdatecommand ="DBGrid1_Updat e"
bordercolor="#D EDFDE" borderstyle="No ne"
borderwidth="1p x" backcolor="Whit e" cellpadding="4"
gridlines="Vert ical" forecolor="Blac k"
datakeyfield="r owId">
<alternatingite mstyle backcolor="Whit e"></alternatingitem style>
<itemstyle backcolor="#F7F 7DE"></itemstyle>
<headerstyle font-bold="True" backcolor="#CCC C99"></headerstyle>
<columns>
<asp:editcomman dcolumn buttontype="Lin kButton"
updatetext="Upd ate" canceltext="Can cel"
edittext="Edit" ></asp:editcommand column>
<asp:buttoncolu mn text="Delete"
commandname="De lete"></asp:buttoncolum n>
</columns>
</asp:datagrid>

--
LUIS ESTEBAN VALENCIA
MICROSOFT DCE 3.
MIEMBRO ACTIVO DE ALIANZADEV
http://spaces.msn.com/members/extremed/
Nov 19 '05 #1
0 1747

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

Similar topics

1
840
by: Amber | last post by:
The DataGrid allows you to make columns visible or invisible on demand - even edit and other special columns. This article will show you how it is done. Some developers have reported problems controlling the visibility of columns in the DataGrid control. The problem usually comes down to one fact. The DataGrid has a property called AutoGenerateColumns. The default value is "True". This means that when AutoGenerateColumns is set to True,...
3
4886
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that the best method? Do you have a sample of how to do this?
3
4077
by: McNutt Consulting | last post by:
I'm trying to implement a datagrid with dynamically created columns. The data is coming out of a very simple XML file, and it's bound through a dataview. The datagrid is just a shell definition with no column definitions in the ..aspx file. The grid is binding fine with all the data being displayed, but my numeric columns aren't being formatted. I'm using the "dataformattextstring", but it doesn't seem to be working. Is there...
0
1082
by: Alvin Bruney [MVP] | last post by:
Anybody know of a link or resource to adding a control to an autogenerated datagrid when the edit button is clicked? I'm particularly not interested in adding template columns or setting autogenerated to false. So for example, i'd like to be able to add a dropdown instead of the regular text box to any dynamic column in the grid when it is in edit mode. -- Regards,
8
7321
by: Hanson | last post by:
I have a datagrid control in an aspx page. The datagrid columns will be dynamically generated according to the pre-page's search condition, I want to hide some columns in the datagrid. is that anyway to do that?
15
3767
by: John Blair | last post by:
Hi, Code attached but the line that gives me an error is MyDataGrid.Columns(2).Visible = False It actually gives me an error for any value instead of 2 even when 9 bound columns of data exist. How do i hide a column? Thanks. MyConnection = New SqlConnection("server=(local);database=pubs;Trusted_Connection=yes") MyCommand = New SqlDataAdapter("select * from Authors",
1
1147
by: MattC | last post by:
Hi, I am trying to export the contents of a DataGrid to Excel. I have already found the following articles: http://support.microsoft.com/default.aspx?scid=kb;en-us;317719 http://www.c-sharpcorner.com/Code/2003/Sept/ExportASPNetDataGridToExcel.asp These methods _only_ work if the following is true:
9
6108
by: Steve | last post by:
How I can remove an AutoGenerated column? I wnat to inlcude the primary key in the resultset for creating some custom LinkButtons, but I don't want it (the PK) displayed in the DataGrid. I tried searching the columnheader text, but found that AutoGenerated columns are members of the Columns collection. From the msdn documentation: Note: When the AutoGenerateColumns property is set to true, the columns created by the DataGrid control are...
3
1643
by: CharlesA | last post by:
Hi folks, I really need help with the following scenario, I'm going to describe as well as a I can what the setup is and what I can't understand I'm using the framework 1.1 using ASP.net with C# I have a datagrid that is bound to a datasource (through ADO.net) and all that works
0
9684
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10459
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10236
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10182
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9055
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7552
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5445
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2928
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.