ASP.NET Datagrid filling textboxes

Discussion in 'ASP .Net Datagrid Control' started by Aaron, Jul 19, 2004.

  1. Aaron

    Aaron Guest

    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
     
    Aaron, Jul 19, 2004
    #1
    1. Advertising

  2. Aaron

    Raterus Guest

    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

    "Aaron" <> wrote in message news:Xns952BA644F7E1aaronjonharveycom@207.46.248.16...
    > 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("&nbsp;") Then
    > txtFullname.Text = ""
    > Else
    > txtFullname.Text = Trim(Cell1)
    > End If
    >
    > If e.Item.Cells(2).Text.Equals("&nbsp;") Then
    > txtCompany.Text = ""
    >
    > Else
    > txtCompany.Text = Trim(e.Item.Cells(2).Text)
    >
    > End If
    >
    > If e.Item.Cells(3).Text.Equals("&nbsp;") Then
    > txtTitle.Text = ""
    >
    > Else
    > txtTitle.Text = Trim(e.Item.Cells(3).Text)
    >
    > End If
    > If Cell4.Equals("&nbsp;") Then
    > txtBPhone.Text = ""
    >
    > Else
    > txtBPhone.Text = Trim(Cell4)
    >
    > End If
    >
    > If e.Item.Cells(5).Text.Equals("&nbsp;") Then
    > txtWorkExt.Text = ""
    >
    > Else
    > txtWorkExt.Text = Trim(e.Item.Cells(5).Text)
    >
    > End If
    > If e.Item.Cells(6).Text.Equals("&nbsp;") Then
    > txtClientCell.Text = ""
    >
    > Else
    > txtClientCell.Text = Trim(e.Item.Cells(6).Text)
    >
    > End If
    >
    >
    > If e.Item.Cells(7).Text.Equals("&nbsp;") Then
    > txtNotes.Text = ""
    >
    > Else
    > txtNotes.Text = Trim(e.Item.Cells(7).Text)
    >
    > End If
    >
    > If e.Item.Cells(9).Text.Equals("&nbsp;") 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("&nbsp;") 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
     
    Raterus, Jul 19, 2004
    #2
    1. Advertising

  3. Aaron

    Aaron Guest

    > 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
     
    Aaron, Jul 19, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lloyd Sheen
    Replies:
    3
    Views:
    364
    Mythran
    Jun 29, 2004
  2. thegame
    Replies:
    1
    Views:
    947
    =?Utf-8?B?ZGlyazQx?=
    Feb 28, 2005
  3. Toni Pohl
    Replies:
    1
    Views:
    963
    Toni Pohl
    Aug 10, 2008
  4. Mohsen Pahlevanzadeh
    Replies:
    0
    Views:
    130
    Mohsen Pahlevanzadeh
    Sep 9, 2013
  5. MRAB
    Replies:
    0
    Views:
    124
Loading...

Share This Page