0

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

5
Contributors
17
Replies
18
Views
8 Years
Discussion Span
Last Post by mshravs
0

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.

0

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

Edited by mshravs: n/a

0

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

0

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

0

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
0
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

0

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

0

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

0

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 )
0

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

Edited by mshravs: n/a

0

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

Edited by mshravs: n/a

0

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

Edited by Ramesh S: n/a

0

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
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.