i am working on the gridview, the problem, it that when i am executing the form containing the gridview, the problem is that it is not showing the gridview in the webpage.
even though i have set the visible property true in the properties, it is not working.plz help me
thanks a lot

Check whether the data source (such as DataTable, DataSet) bound to the GridView has records by putting a break point.

If DataTable has no records, then the GridView does not render anything.

it doesn't have any records but the values should be entered through the gridview, then what should i do that too in the web page

A simple way is to add empty rows to the DataTable before binding to the GridView.

Use footer row to add a new record

i'm using sqldatasource and it is not possible to add empty tables because of the primary keys, so is there any other way to make the gridview visible in the web page while executing

First check if you have marked auto generated columns true or not then see whether u have written
Gridview.Databind() or not

one of these may solve your problem dude
:-)

i am working on the gridview, the problem, it that when i am executing the form containing the gridview, the problem is that it is not showing the gridview in the webpage.
even though i have set the visible property true in the properties, it is not working.plz help me
thanks a lot

i tried both of them but its not working

If you need to add empty rows to a GridView which is bound to SqlDataSource, you can do it via the stored procedure.

Assign a stored procedure to the SelectCommand property of the SqlDataSource.

In the stored procedure, check whether record exists in the relevant database table.

If not exists return some dummy values otherwise return the records from that table.

See this sample code.

IF NOT EXISTS(SELECT 1 FROM Employee)
 BEGIN
	SELECT -1 EMPNO, ' ' Ename, 0 AS SAL 
  END
ELSE
  BEGIN
    SELECT EMPNO, Ename, SAL FROM Employee
  END
Dim datatable As New Data.DataTable
        datatable = DirectCast((SqlDataSource1.[Select](DataSourceSelectArguments.Empty)), DataView).Table
        Dim dataRow As Data.DataRow = datatable.NewRow()
        datatable.Rows.InsertAt(dataRow, 0)
        GridView1.DataSource = datatable
        GridView1.DataBind()

but its giving any error saying
Data properties on data control 'GridView1' such as DataSource, DataSourceID, and DataMember cannot be changed during the databinding phase of the control.
what's actually wrong in this

Enter "No records found" in datagridviews property EmptyDataText if storeprocedure didnt return anything and gridview is binding properly.
otherwise post your code to help you more

it's not working and the code is posted in the above post

if u want to add rows to datatable at runtime try this

Dim dataRow As Data.DataRow = datatable.NewRow()
                dataRow .Item("TableID") = 0
                datatable.Rows.Add(dataRow )

is the above code which I posted is correct or not, plz help me. i got stuck here for past two days

why is this exception System.NullReferenceException: Object reference not set to an instance of an object. when i'm using this code...........what's wrong with this code

Protected Sub gridview1_databound(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.DataBound
        Dim datatable As New Data.DataTable
        datatable = CType(GridView1.DataSource, Data.DataTable)
        Dim dataRow As Data.DataRow
        dataRow = CType(GridView1.DataSource, Data.DataRow)
        'dataRow.Item("serial no") = 0
        'dataRow.Item("description") = 0
        'dataRow.Item("making") = 0
        'dataRow.Item("equipment no") = 0
        'dataRow.Item("quantity") = 0
        'dataRow.Item("total packets") = 0
        datatable.Rows.Add(dataRow) 
       GridView1.DataSourceID = SqlDataSource1.ID
        GridView1.DataBind()
    End Sub

You need to use DataTable.NewRow to create new DataRow object with the same schema as the DataTable.

Try this.

Protected Sub gridview1_databound(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.DataBound
        Dim datatable As New Data.DataTable
        datatable = CType(GridView1.DataSource, Data.DataTable)
        If Not datatable Is Nothing Then
            Dim dataRow As Data.DataRow
            'dataRow = CType(GridView1.DataSource, Data.DataRow)
            dataRow  = datatable.NewRow()
            'dataRow.Item("serial no") = 0
            'dataRow.Item("description") = 0
            'dataRow.Item("making") = 0
            'dataRow.Item("equipment no") = 0
            'dataRow.Item("quantity") = 0
            'dataRow.Item("total packets") = 0
             datatable.Rows.Add(dataRow) 
         End If
         GridView1.DataSourceID = SqlDataSource1.ID
        GridView1.DataBind()
    End Sub

then what this error System.Web.HttpException: Data properties on data control 'GridView1' such as DataSource, DataSourceID, and DataMember cannot be changed during the databinding phase of the control.
says
and the code pointing to

GridView1.DataSourceID = SqlDataSource1.ID
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.