ASP.NET Datagrid filling textboxes

A

Aaron

I am currently filling textboxes with the data from a datagrid with the
following code:
Sub Fillnextrecord(ByVal e As DataGridCommandEventArgs)

Dim Cell1 As String = e.Item.Cells(1).Text.ToString
Dim Cell2 As String = e.Item.Cells(2).Text.ToString
Dim Cell3 As String = e.Item.Cells(3).Text.ToString
Dim Cell4 As String = e.Item.Cells(4).Text.ToString
Dim Cell5 As String = e.Item.Cells(5).Text.ToString
Dim Cell6 As String = e.Item.Cells(6).Text.ToString
Dim Cell7 As String = e.Item.Cells(7).Text.ToString
Dim Cell8 As String = e.Item.Cells(8).Text.ToString
Dim Cell9 As String = e.Item.Cells(9).Text.ToString
Dim Cell10 As String = e.Item.Cells(10).Text.ToString
Dim Cell11 As String = e.Item.Cells(11).Text.ToString
Dim Cell12 As String = e.Item.Cells(12).Text.ToString
Dim Cell13 As String = e.Item.Cells(13).Text.ToString
Dim Cell14 As String = e.Item.Cells(14).Text.ToString
Dim Cell15 As String = e.Item.Cells(15).Text.ToString
Dim Cell16 As String = e.Item.Cells(16).Text.ToString
Dim Cell17 As String = e.Item.Cells(17).Text.ToString



If Cell1.Equals(" ") Then
txtFullname.Text = ""
Else
txtFullname.Text = Trim(Cell1)
End If

If e.Item.Cells(2).Text.Equals(" ") Then
txtCompany.Text = ""

Else
txtCompany.Text = Trim(e.Item.Cells(2).Text)

End If

If e.Item.Cells(3).Text.Equals(" ") Then
txtTitle.Text = ""

Else
txtTitle.Text = Trim(e.Item.Cells(3).Text)

End If
If Cell4.Equals(" ") Then
txtBPhone.Text = ""

Else
txtBPhone.Text = Trim(Cell4)

End If

If e.Item.Cells(5).Text.Equals(" ") Then
txtWorkExt.Text = ""

Else
txtWorkExt.Text = Trim(e.Item.Cells(5).Text)

End If
If e.Item.Cells(6).Text.Equals(" ") Then
txtClientCell.Text = ""

Else
txtClientCell.Text = Trim(e.Item.Cells(6).Text)

End If


If e.Item.Cells(7).Text.Equals(" ") Then
txtNotes.Text = ""

Else
txtNotes.Text = Trim(e.Item.Cells(7).Text)

End If

If e.Item.Cells(9).Text.Equals(" ") Then
txtConfNotes.Text = ""

Else
txtConfNotes.Text = Trim(e.Item.Cells(9).Text)

End If

If e.Item.Cells(10).Text.Equals("&nbsp") Then
txtActDate.Text = ""

Else
txtActDate.Text = Trim(e.Item.Cells(10).Text)

End If

If e.Item.Cells(11).Text.Equals(" ") Then 'If the FU date in
the grid is blank, then run function to count three businessdays
txtFollowUpDate.ForeColor = System.Drawing.Color.Black()
txtFollowUpDate.Text = FormatDateTime
(WebBizDev.Utilities.BusinessDateAdd(FormatDateTime(Now,
DateFormat.ShortDate), 3), DateFormat.ShortDate)
Else
Dim FUDate As Date = e.Item.Cells(11).Text
If FUDate < FormatDateTime(Now, DateFormat.ShortDate) Then
'ASPNET_MsgBox("The Follow Up Date has expired.")
txtFollowUpDate.ForeColor = System.Drawing.Color.Red()
txtFollowUpDate.Text = Trim(FUDate)
Else
txtFollowUpDate.ForeColor = System.Drawing.Color.Black()
txtFollowUpDate.Text = Trim(e.Item.Cells(11).Text)
End If
End If
If e.Item.Cells(14).Text.Equals("&nbsp;") Then
Label18.Text = ""

Else

Label18.Text = Trim(e.Item.Cells(14).Text)

End If
If e.Item.Cells(15).Text.Equals("&nbsp;") Then
Label19.Text = ""

Else
Label19.Text = Trim(e.Item.Cells(15).Text)

End If
If e.Item.Cells(17).Text.Equals("&nbsp;") Then
txtEmail.Text = ""

Else
txtEmail.Text = Trim(e.Item.Cells(17).Text)

End If
If e.Item.Cells(18).Text.Equals("&nbsp;") Then
txtBMail.Text = ""

Else
txtBMail.Text = Trim(e.Item.Cells(18).Text)

End If
If e.Item.Cells(19).Text.Equals("&nbsp;") Then
txtHomePhone.Text = ""

Else
txtHomePhone.Text = Trim(e.Item.Cells(19).Text)

End If




This is used to fill textboxes for editing the data. Once the data has
been modified, the user hits the "Update Record" button and the changes
are commited to the database.

I need to be able to move to the next record, or row in the datagrid. I
know the e is the datagrideventarg, and that is about it. I have tried e
+1 but that doesn't work.

Could anyone show me how to move to the next record? I am sure this is
not the best way to fill those textboxes, but it is the only way I found
to do it. Perhaps if there is a better approach, you could show me that
and how I would be able to move to the next row or record.

Thanks,
Aaron
 
R

Raterus

First off, yeah I think there are much better ways to do what you are doing, but I don't know what you are doing that you need to go to the next record..?

Second, there is no "next record", at least available from the EventArgs (e). If you need to get to other values that were stored in the datagrid, you'll have to access them via

myDataGrid.Items(rowNumber).cells(0..1..2..3..)

Hope this helps,
--Michael
 
A

Aaron

First off, yeah I think there are much better ways to do what you are
doing, but I don't know what you are doing that you need to go to the
next record..?

Basically, the user updates a record and then needs to move to the next
record for editing. They would like to do this with one click of the
"Update Button". (Update the current row, then move to the next one, and
populate the text boxes for editing)

Second, there is no "next record", at least available from the
EventArgs (e). If you need to get to other values that were stored in
the datagrid, you'll have to access them via

myDataGrid.Items(rowNumber).cells(0..1..2..3..)

Hope this helps,
Yes, this does help a lot. Thanks.

Aaron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top