0

hello friends
I am trying to convert a vb.net datagridview code into asp.net. I want to display last three rows of table column from database table in gridview column1.

         Dim dt As New DataTable

        ' Create columns
        dt.Columns.Add("column1", Type.GetType("System.String"))
        dt.Columns.Add("column2", Type.GetType("System.String"))
        dt.Columns.Add("column3", Type.GetType("System.String"))
        dt.Columns("column3").Expression = "[column1]+[column2]"
        dt.Rows.Add("", "")
        dt.Rows.Add("", "")
        dt.Rows.Add("", "")
        dt.Rows.Add("", "")

        Me.GridView1.DataSource = dt

        GridView1.DataBind()




    I know how to display table data in gridview using the code below



   Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\dtb.accdb")
        Dim Query2 As String = "select * from table1"
        Dim Da As OleDbDataAdapter, Ds As New DataSet, Dtb As New System.Data.DataTable
        con.Open()
        Da = New OleDbDataAdapter(Query2, con)
        Da.Fill(Ds)
        con.Close()
        Dtb = Ds.Tables(0)
        GridView1.DataSource = Dtb
        GridView1.DataBind()

the gridview shows in web form but I cannot make any input in gridview cell,also how to bind last three rows in column1. can someone please help me with this
thanks

2
Contributors
1
Reply
8
Views
2 Years
Discussion Span
Last Post by confidence123
0

Hi,

depending on how youb process the rows. Assuming you loop them all through
when update button is clicked. You could just iterate

For Each row As GridViewRow in GridView1.Rows

Dim cbDelete As CheckBox = DirectCast(row.FindControl("CheckBox1"),
CheckBox)

' Accessing text in first Cell
Dim strText As String = row.Cells(0).Text
'...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.