problem with the gridview

Reply

Join Date: May 2009
Posts: 60
Reputation: mshravs is an unknown quantity at this point 
Solved Threads: 1
mshravs mshravs is offline Offline
Junior Poster in Training
 
0
  #11
Nov 11th, 2009
  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
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 43
Reputation: fawadkhalil is an unknown quantity at this point 
Solved Threads: 1
fawadkhalil fawadkhalil is offline Offline
Light Poster
 
0
  #12
Nov 11th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 60
Reputation: mshravs is an unknown quantity at this point 
Solved Threads: 1
mshravs mshravs is offline Offline
Junior Poster in Training
 
0
  #13
Nov 12th, 2009
it's not working and the code is posted in the above post
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 43
Reputation: fawadkhalil is an unknown quantity at this point 
Solved Threads: 1
fawadkhalil fawadkhalil is offline Offline
Light Poster
 
0
  #14
Nov 12th, 2009
if u want to add rows to datatable at runtime try this
  1. Dim dataRow As Data.DataRow = datatable.NewRow()
  2. dataRow .Item("TableID") = 0
  3. datatable.Rows.Add(dataRow )
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 60
Reputation: mshravs is an unknown quantity at this point 
Solved Threads: 1
mshravs mshravs is offline Offline
Junior Poster in Training
 
0
  #15
Nov 12th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 60
Reputation: mshravs is an unknown quantity at this point 
Solved Threads: 1
mshravs mshravs is offline Offline
Junior Poster in Training
 
0
  #16
Nov 13th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 452
Reputation: Ramesh S will become famous soon enough Ramesh S will become famous soon enough 
Solved Threads: 82
Ramesh S Ramesh S is offline Offline
Posting Pro in Training
 
0
  #17
Nov 13th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 60
Reputation: mshravs is an unknown quantity at this point 
Solved Threads: 1
mshravs mshravs is offline Offline
Junior Poster in Training
 
0
  #18
Nov 13th, 2009
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
  1. GridView1.DataSourceID = SqlDataSource1.ID
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 753 | Replies: 17
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC