473,498 Members | 1,938 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 "editcommandcolumn" 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.Tables(0).Rows.Count-1
DataGrid1.EditItemIndex = index
myComponent.FillDataSet(DataSet11)
DataBind()
Dim focusBox As TextBox
focusBox = DataGrid1.Items(index).Cells(0).Controls(0) <-****
error here**** (TypeCast is invalid)

scriptJs = "<Script Language=JavaScript>" & vbCrLf
scriptJs &= "document.getElementById('" & focusBox.UniqueID &
"').focus();" & vbCrLf
scriptJs &= "document.getElementById('" & focusBox.UniqueID &
"').select();" & vbCrLf
scriptJs &= "<" & "/script>"
If (Not Me.IsStartupScriptRegistered("Startup")) Then
Me.RegisterStartupScript("Startup", 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:linkbutton id="LinkButton1" runat="server"
onclick="LinkButton1_Add">Create New Row</asp:linkbutton>
<br>
<asp:datagrid id="DBGrid1" runat="server" ondeletecommand="DBGrid1_Delete"
oneditcommand="DBGrid1_Edit"
oncancelcommand="DBGrid1_Cancel" onupdatecommand="DBGrid1_Update"
bordercolor="#DEDFDE" borderstyle="None"
borderwidth="1px" backcolor="White" cellpadding="4"
gridlines="Vertical" forecolor="Black"
datakeyfield="rowId">
<alternatingitemstyle backcolor="White"></alternatingitemstyle>
<itemstyle backcolor="#F7F7DE"></itemstyle>
<headerstyle font-bold="True" backcolor="#CCCC99"></headerstyle>
<columns>
<asp:editcommandcolumn buttontype="LinkButton"
updatetext="Update" canceltext="Cancel"
edittext="Edit"></asp:editcommandcolumn>
<asp:buttoncolumn text="Delete"
commandname="Delete"></asp:buttoncolumn>
</columns>
</asp:datagrid>

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

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...
3
4854
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...
3
4056
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...
0
1066
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...
8
7301
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...
15
3733
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....
1
1131
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...
9
6085
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...
3
1627
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...
0
7002
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...
0
7165
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
7203
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...
1
6885
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...
1
4908
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...
0
4588
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...
0
3093
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...
0
3081
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
290
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...

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.