943,965 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 1665
  • ASP.NET RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Nov 11th, 2009
0
Re: problem with the gridview
ASP.NET Syntax (Toggle Plain Text)
  1. Dim datatable As New Data.DataTable
  2. datatable = DirectCast((SqlDataSource1.[Select](DataSourceSelectArguments.Empty)), DataView).Table
  3. Dim dataRow As Data.DataRow = datatable.NewRow()
  4. datatable.Rows.InsertAt(dataRow, 0)
  5. GridView1.DataSource = datatable
  6. 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
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
mshravs is offline Offline
75 posts
since May 2009
Nov 11th, 2009
0
Re: problem with the gridview
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
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
fawadkhalil is offline Offline
88 posts
since Dec 2008
Nov 12th, 2009
0
Re: problem with the gridview
it's not working and the code is posted in the above post
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
mshravs is offline Offline
75 posts
since May 2009
Nov 12th, 2009
0
Re: problem with the gridview
if u want to add rows to datatable at runtime try this
ASP.NET Syntax (Toggle Plain Text)
  1. Dim dataRow As Data.DataRow = datatable.NewRow()
  2. dataRow .Item("TableID") = 0
  3. datatable.Rows.Add(dataRow )
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
fawadkhalil is offline Offline
88 posts
since Dec 2008
Nov 12th, 2009
0
Re: problem with the gridview
is the above code which I posted is correct or not, plz help me. i got stuck here for past two days
Last edited by mshravs; Nov 12th, 2009 at 3:37 am.
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
mshravs is offline Offline
75 posts
since May 2009
Nov 13th, 2009
0
Re: problem with the gridview
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
Last edited by mshravs; Nov 13th, 2009 at 3:31 am.
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
mshravs is offline Offline
75 posts
since May 2009
Nov 13th, 2009
0
Re: problem with the gridview
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
Last edited by Ramesh S; Nov 13th, 2009 at 4:44 am.
Reputation Points: 165
Solved Threads: 113
Posting Pro
Ramesh S is offline Offline
580 posts
since Jun 2009
Nov 13th, 2009
0
Re: problem with the gridview
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
ASP.NET Syntax (Toggle Plain Text)
  1. GridView1.DataSourceID = SqlDataSource1.ID
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
mshravs is offline Offline
75 posts
since May 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: help regarding session
Next Thread in ASP.NET Forum Timeline: How to reduce image weight using asp.net





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC