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/