Results 1 to 7 of 7

Thread: [RESOLVED] Gridview headache: Get column names when autogeneratecolumns=true?

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    205

    Resolved [RESOLVED] Gridview headache: Get column names when autogeneratecolumns=true?

    I'm getting frustrated with the Gridview control. I'm populating the Gridview like this...

    VB Code:
    1. dt = obj.getDataTable("SELECT * FROM tblsamplestrings")
    2. gvTranslations.DataSource = dt
    3. gvTranslations.DataBind()

    I'm using "SELECT *" because tblsamplestrings will be variable and each table has different fields. So everything renders as expected. Now when the user clicks "Update" I need to know the column names so that I can construct an UPDATE statement. But I can't figure out how to get the column names and the column count property is ZERO (I'm guessing because the columns were autogenerated). So this is where I am stuck...

    VB Code:
    1. Protected Sub gvTranslations_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs) Handles gvTranslations.RowUpdating
    2.         Dim row As GridViewRow = gvTranslations.Rows(e.RowIndex)
    3.         Dim columnCount As Integer = gvTranslations.Columns.Count
    4.     End Sub

    Any help would be much appreciated.

    UDPATE: I managed to get the column names using a workaround. So now I'm stuck on the UPDATE statement.

    I have this code...

    VB Code:
    1. Protected Sub gvTranslations_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs) Handles gvTranslations.RowUpdating
    2.         Dim y As Integer = 0
    3.         Dim row As GridViewRow = gvTranslations.Rows(e.RowIndex)
    4.         Dim obj As New ERSLib.Data.PublicFunc
    5.         Dim sb As New StringBuilder
    6.        
    7.         sb.Append("UPDATE tblSampleStrings SET TYPE_ = '" & needNewValueHere & "'")
    8.  
    9.         obj.runSql(sb.ToString)
    10.  
    11.         obj.close()
    12.         obj = Nothing
    13.  
    14.     End Sub

    How do I fill the needNewValueHere variable with the appropriate value? I've tried everything I can think of. e.newvalues is empty. row.cells(e.rowindex) is empty. This is so frustrating
    Last edited by ferrethouse; Oct 31st, 2006 at 07:47 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width