Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Datagrid Setting Focus and "ontextchanged"

Reply
Thread Tools

Datagrid Setting Focus and "ontextchanged"

 
 
Derek Mendez
Guest
Posts: n/a
 
      04-14-2004

I am trying to add records to a dataset using the footer of datagrid.
That works fine.

Additional functionality I am having a hard time with is performing a
query based on the text entered in the first textbox of the footer. I
would like to use an “ontextchanged” to initiate the query. I can do
this on a textbox on the webform outside the datagrid but cannot seem to
associate the footer - textbox to perform the operation.

Also I want to reset the focus to the first textbox in the footer after
the “add” button action is performed. I have tried with JavaScript I
think my issue is with assigning the textbox id to associate the action
with.

Any help would be greatly appreciated. Thanks in advance

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      04-15-2004
Hi Derek,

Based on my understanding, you meet the problem of manipulating the child
control(TextBox) in DataGrid

To add the OnTextChanged server side event handler for your child TextBox
control in datagrid, you should hook into DataGrid.ItemCreated event, in
the event find your TextBox, do like this:

private void DataGrid1_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
DataGridItem dgi=e.Item;
if(dgi.ItemType==ListItemType.Footer)
{
Control c=dgi.FindControl("TextBox's ID");
TextBox tb=c as TextBox;
tb.TextChanged+=new EventHandler(tb_TextChanged);
}
}

If you did not specify the server side ID to the TextBox, you have to loop
through and find it, like this:

private void DataGrid1_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
DataGridItem dgi=e.Item;
if(dgi.ItemType==ListItemType.Footer)
{
foreach(Control c in dgi.Cells[0].Controls)
{
if(c is TextBox)
{
TextBox tb=c as TextBox;
tb.TextChanged+=new EventHandler(tb_TextChanged);
}
}
}
}

For your second request of set the textfocus, I think the key point is get
the correct client id of your TextBox. You should refer to the TextBox's
ClientID property, for example, in ItemCreated event, you may get it
through tb.ClientID.

==============================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
 
 
 
Derek Mendez
Guest
Posts: n/a
 
      04-15-2004
Thanks for the response.

This almost gets me there. I am having a couple of problems though…

I do not have textchanged available for an aspx(html view) page – I know
its available for a windows app I may not have clarified that in my
original post.

When setting the ontextchanged event for the textbox in html to call the
sub I am getting a “delegate” error. Do I have to use the ItemCreated
Sub or can I incorporate this code into another sub with a Javascript on
textchange??

Again, any help would be greatly appreciated



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Derek Mendez
Guest
Posts: n/a
 
      04-15-2004
This looks ugly I know everything works except the setting focus on the
textbox at the end of this sub. I added in your code and called the
javascript to set focus.

Also I was referring to correct clientID for the textbox but it was
never recognizing it. Maybe my javascript is incorrect.

Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
DataGrid1.ItemCommand

If e.CommandName = "Delete" Then

Dim intlid As Integer

intlid = DataGrid1.DataKeys(e.Item.ItemIndex)

SqlDeleteCommand1.Parameters("@lid").Value = intlid

SqlConnection1.Open()

SqlDeleteCommand1.ExecuteNonQuery()

SqlConnection1.Close()

DataGrid1.EditItemIndex = -1

BindcallNo()

End If

If e.CommandName = "Add" Then

Dim fyshort As String

Dim newid As String

Dim fyear As String

Dim fycn As String

Dim txtcn As TextBox

Dim strcn As String

txtcn = e.Item.FindControl("txt_add_cn")

strcn = txtcn.Text

Dim txtname As TextBox

Dim strname As String

Dim datcurrent As Date

Dim ydate As String

Dim nextyr As Date

datcurrent = Date.Now()

nextyr = DateAdd(DateInterval.Year, 1, datcurrent)

ydate = DatePart(DateInterval.Year, datcurrent)

If DatePart(DateInterval.Month, datcurrent) < 7 Then

fyear = Mid(ydate, 3, 2)

Else

fyear = Mid(nextyr, 3, 2)

End If

fyshort = lblFYtxt.Text

txtname = e.Item.FindControl("txt_add_cnname")

strname = txtname.Text

fycn = fyear + strcn


Label1.Visible = True

Label5.Visible = False

Label6.Visible = False

Label7.Visible = False

'Label9.Visible = True

lblduplicatename.Visible = False

lblduplicatecn.Visible = False

lblduplicatedate.Visible = False

lblduplicatehotel.Visible = False

lblduplicateinvoice.Visible = False

lblduplicatePOC.Visible = False

lblduplicatephone.Visible = False

Label12.Visible = False

Label13.Visible = False

lblduplicatename.Text = ""

lblduplicatecn.Text = ""

lblduplicatedate.Text = ""

lblduplicatehotel.Text = ""

lblduplicateinvoice.Text = ""

Label4.Visible = False

Label8.Visible = False


SqlSelectCommand6.Parameters("@cn").Value = strcn

SqlConnection1.Open()

Dim myReader As SqlDataReader =
SqlSelectCommand6.ExecuteReader()

If myReader.HasRows Then

Label1.Text = "The duplicate information is listed
below"



'lblduplicatehotel.Visible = True

'Do While myReader.Read()

'Console.WriteLine(myReader.GetString(0) & " " &
myReader.GetString(1) & " " & myReader.GetString(5))

myReader.Read()

If Not myReader.IsDBNull(0) Then

lblduplicatename.Text = myReader.GetValue(0)

Else

lblduplicatename.Text = "no data"

End If

If Not myReader.IsDBNull(1) Then

lblduplicatecn.Text = myReader.GetValue(1)

Else

lblduplicatecn.Text = "no data"

End If

If Not myReader.IsDBNull(2) Then

lblduplicatedate.Text = myReader.GetValue(2)

Else

lblduplicatedate.Text = "no data"

End If

If Not myReader.IsDBNull(4) Then

lblduplicatehotel.Text = myReader.GetValue(4)

Else

lblduplicatehotel.Text = "no data"

End If

If Not myReader.IsDBNull(5) Then

lblduplicateinvoice.Text = myReader.GetValue(5)

Else

lblduplicateinvoice.Text = "no data"

End If

If Not myReader.IsDBNull(6) Then

lblduplicatePOC.Text = myReader.GetValue(6)

Else

lblduplicatePOC.Text = "no data"

End If



If Not myReader.IsDBNull(7) Then

lblduplicatephone.Text = myReader.GetValue(7)

Else

lblduplicatephone.Text = "no data"

End If

'lblduplicatehotel.Text = myReader.GetString(5)

'Loop

Label5.Visible = True

Label6.Visible = True

Label7.Visible = True

'Label9.Visible = True



lblduplicatename.Visible = True

lblduplicatecn.Visible = True

lblduplicatedate.Visible = True

lblduplicatehotel.Visible = True

lblduplicateinvoice.Visible = True

lblduplicatePOC.Visible = True

lblduplicatephone.Visible = True

Label4.Visible = True

Label8.Visible = True

Label12.Visible = True

Label13.Visible = True

' txtCN.Text = ""

myReader.Close()

SqlConnection1.Close()

Else

myReader.Close()

SqlConnection1.Close()

Label1.Text = "there are no duplicates for this call
number"



End If

If Label1.Text = "there are no duplicates for this call
number" Then



SqlInsertCommand2.Parameters("@FY").Value = fyshort

SqlInsertCommand2.Parameters("@name").Value = strname

SqlInsertCommand2.Parameters("@cn").Value = strcn

SqlInsertCommand2.Parameters("@fycn").Value = fycn

SqlInsertCommand2.Parameters("@ltid").Value = 112
'CType(lbllastid.Text, Integer)

SqlConnection1.Open()

SqlInsertCommand2.ExecuteNonQuery()

SqlConnection1.Close()



BindcallNo()

e.Item.TabIndex = 1



End If

Dim dgi As DataGridItem

dgi = e.Item

If dgi.ItemType = ListItemType.Footer Then

Dim c As Control

c = dgi.FindControl("txt_add_cn")

Dim tb As TextBox

tb = c

lbl_clientid.Text = tb.ClientID()



txtname.Text = ""

txtcn.Text = ""

RegisterStartupScript("focus", "<script
language=""JavaScript"">" & vbCrLf & _

vbTab & "form1." & tb.ClientID & ".focus();" & _

vbCrLf & vbTab & "form1." & tb.ClientID & ".select();" & _

vbCrLf & "<" & "/script>")

End If

'Page.RegisterClientScriptBlock("focus", _

' "<script language=""JavaScript"">" & _

' "form1.<txt_add_cn>.focus();" & _

' "</script> ")



End If



End Sub




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      04-16-2004
Hi Derek,

I have found that this post has been posted in this group. I have added a
reply to you in that post, please follow up me there. I will help you.

Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
Derek Mendez
Guest
Posts: n/a
 
      04-16-2004

Hi Jeffrey

Thanks for the response. I never recieved the attachment you sent with
you earlier reply. Thanks in advance.

Derek


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      04-19-2004
Hi Derek,

Thanks for your feedback.

You should get and access my attachment through Outlook Express. You can
not see it through IE explorer.

I have tried to use OE to that reply, and I succeeded get the attachment. I
think you should refer to that reply through OE again.

If you still can not get it, please give me a valid e-mail address, I will
sent the project to you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      04-20-2004
Hi Derek,

Have you refered my attached project? Is your problem resolved?

Please feel free to post. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
Derek Mendez
Guest
Posts: n/a
 
      04-20-2004
I am still unable to recieve your attached file. If you can, please
send to http://www.velocityreviews.com/forums/(E-Mail Removed)

Thanks in advance..

Derek



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      04-21-2004
Hi Derek,

Oh, I think it is very strange, because I can successfully get the
attachment through OE.

Anyway, I have sent the entire project to you through the E-mail you
provided. Please refer to it.

Hope it helps.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
emulating window.focus in Body onload() event and setting focus to a control on same page Jason ASP .Net 4 05-07-2007 05:54 PM
this.window.focus() vs. window.focus() vs. this.focus() Roger Javascript 3 03-08-2007 08:53 PM
Setting Focus on Edit Row in Datagrid - how do I reference new clientid name??? jason@cyberpine.com ASP .Net 1 07-15-2005 08:16 PM
setting focus to a control within a datagrid Craig G ASP .Net 2 12-15-2004 06:12 PM
setting focus to datagrid subcontrol Bonj ASP .Net 1 11-13-2004 09:47 PM



Advertisments