GridView1_RowCreated1

Last post 05-16-2008 11:08 AM by lberan. 12 replies.

Sort Posts:

  • GridView1_RowCreated1

    05-15-2008, 11:29 AM
    • Contributor
      3,406 point Contributor
    • lberan
    • Member since 02-12-2008, 7:23 PM
    • Pittsburgh, PA
    • Posts 810

    I use GridView1_RowCreated1 to change font and backcolor for some fields upon certain conditions for the gridView.  It works fine when the gridView is loaded first time.  I rebind the gridview every time when the page is loaded.

    I also have a table above the gridView with a submit button and serveral input fields which are passed to the gridView as its sqldatasource parameters served as filters for the list of gridView data.  When the page is loaded first time, the gridview is not loaded.  When the submit button is clicked, the gridView is loaded.  This works fine too.

    However, after the griveView is loaded, I can neither sort the gridview nor submit again with same or different input values as filters.  The sorting and filters worked fine before I added the gridView1_RowCreated1 sub.

    The error message I got is:

    Object reference not set to an instance of an object.

    Object reference not set to an instance of an object.

    DataBinder.Eval(e.Row.DataItem, "myDataBindField")  'the line is within the GridView1_RowCreated1 sub and causes the error.

    I think the problem is after the first time the gridView is loaded, the rows have been created.  So when the page is postback again, the rows are not created again, which causes this error message. 

    How to fix?

    Lynn

    Please mark replies that have helped you as answers.
  • Re: GridView1_RowCreated1

    05-15-2008, 11:41 AM
    • Contributor
      2,031 point Contributor
    • ArminStockner
    • Member since 09-19-2006, 6:18 AM
    • Germany, Bavaria
    • Posts 375

    Could you post your code shortly. Maybe the problem comes with the line page.ispostback which is very often the problem.

    Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
  • Re: GridView1_RowCreated1

    05-15-2008, 11:47 AM
    • Contributor
      3,406 point Contributor
    • lberan
    • Member since 02-12-2008, 7:23 PM
    • Pittsburgh, PA
    • Posts 810

    although i don't think Page.IsPostBack has anything to do with the error, i am copying and pasting part of my page_load sub here: 

    Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Not Page.IsPostBack Then

    GridView1.DataSourceID = ""

    Else

    GridView1.DataSourceID = "myDataSource"

    End If

    GridView1.DataBind()

    LabelRecordCount.Text = GridView1.Rows.Count.ToString

    End Sub

    Lynn

    Please mark replies that have helped you as answers.
  • Re: GridView1_RowCreated1

    05-15-2008, 11:54 AM
    • Contributor
      2,031 point Contributor
    • ArminStockner
    • Member since 09-19-2006, 6:18 AM
    • Germany, Bavaria
    • Posts 375

    Maybe your problem comes with the page lifecycle because page.load is called in front of the rowcreated method. So maybe you lose your datas because of you page.load method and the new connection with the dataset

    Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
  • Re: GridView1_RowCreated1

    05-15-2008, 11:59 AM
    • Contributor
      3,406 point Contributor
    • lberan
    • Member since 02-12-2008, 7:23 PM
    • Pittsburgh, PA
    • Posts 810

    ArminStockner,

    i hope you read my question carefully.  i said what the problem is.  i need the solution to fix it.  sorry your posts are not helping.

    Lynn

    Please mark replies that have helped you as answers.
  • Re: GridView1_RowCreated1

    05-15-2008, 12:23 PM
    • Contributor
      3,406 point Contributor
    • lberan
    • Member since 02-12-2008, 7:23 PM
    • Pittsburgh, PA
    • Posts 810

    can anybody please help?

    Lynn

    Please mark replies that have helped you as answers.
  • Re: GridView1_RowCreated1

    05-15-2008, 1:01 PM
    • Contributor
      3,406 point Contributor
    • lberan
    • Member since 02-12-2008, 7:23 PM
    • Pittsburgh, PA
    • Posts 810

    I saw hundreds of people viewed the post.  Can anybody help? Or recommend a link?

    Lynn

    Please mark replies that have helped you as answers.
  • Re: GridView1_RowCreated1

    05-15-2008, 1:15 PM
    • Contributor
      2,117 point Contributor
    • dharnendra
    • Member since 12-26-2007, 5:04 AM
    • Posts 395

    Hi,

    Why you are put gridview binding source in page load event.

    Just make a function where gridview is assing to data source and bind and call it from submit button.

     

    Shah Dharnendra G
    Sr.Analyst Programmer,
    GTL-Ahmedabad
  • Re: GridView1_RowCreated1

    05-15-2008, 2:30 PM
    • Contributor
      3,406 point Contributor
    • lberan
    • Member since 02-12-2008, 7:23 PM
    • Pittsburgh, PA
    • Posts 810

    without gridview.bind() in page_load, i cannot get returned records number, which is assigned to a label on the page.

    even if i call bind() from submit button and suppose it may fix the current problem for re-submit, how are you going to address the issue from sorting the gridview?

    thanks for your input.

    Lynn

    Please mark replies that have helped you as answers.
  • Re: GridView1_RowCreated1

    05-15-2008, 3:25 PM
    • Contributor
      3,406 point Contributor
    • lberan
    • Member since 02-12-2008, 7:23 PM
    • Pittsburgh, PA
    • Posts 810

    i tried on_click for the submit button and it didn't work.  still every thing works fine when the gridview is first time loaded and it causes the same error message when i resubmit or sort the gridview.

    Lynn

    Please mark replies that have helped you as answers.
  • Re: GridView1_RowCreated1

    05-15-2008, 4:25 PM
    • Contributor
      3,406 point Contributor
    • lberan
    • Member since 02-12-2008, 7:23 PM
    • Pittsburgh, PA
    • Posts 810

    guess this is really tough question so that nobody knows how to fix.  i'm determined to find the solution.  i'll let you know how it goes.

    Lynn

    Please mark replies that have helped you as answers.
  • Re: GridView1_RowCreated1

    05-16-2008, 2:07 AM
    • Contributor
      2,117 point Contributor
    • dharnendra
    • Member since 12-26-2007, 5:04 AM
    • Posts 395

     Can you post the code?

    So that i can try over here and get some idea about solution. 

    Shah Dharnendra G
    Sr.Analyst Programmer,
    GTL-Ahmedabad
  • Re: GridView1_RowCreated1

    05-16-2008, 11:08 AM
    Answer
    • Contributor
      3,406 point Contributor
    • lberan
    • Member since 02-12-2008, 7:23 PM
    • Pittsburgh, PA
    • Posts 810

    problem solved by changing the line:

    If e.Row.RowType = DataControlRowType.DataRow Then

    to

    If e.Row.RowType = DataControlRowType.DataRow And Not IsNothing(e.Row.DataItem) Then

    Lynn

    Please mark replies that have helped you as answers.
Page 1 of 1 (13 items)
Microsoft Communities