ObjectDataSource nulling GridView

Discussion in 'ASP .Net' started by tshad, Feb 4, 2010.

  1. tshad

    tshad Guest

    I have a GridView object that is using an ObjectDataSource, but when I get I
    do a GridView1.DataBind(), the following method gets called:

    <asp:ObjectDataSource ID="ObjectDataSource1" EnablePaging="true"
    runat="server" SelectCountMethod="GetRowCount"
    SelectMethod="BindControl" TypeName="AutoUPS.AutoUPS"
    StartRowIndexParameterName="startRowIndex"
    MaximumRowsParameterName="maximumRows">
    </asp:ObjectDataSource>


    public DataTable BindControl(int startRowIndex, int maximumRows)
    {
    SqlConnection con = new
    SqlConnection(ConfigurationManager.ConnectionStrings["ConnectString"].ConnectionString);
    SqlCommand com = new SqlCommand("GetValidFileDetails2", con);
    com.CommandType = CommandType.StoredProcedure;
    com.Parameters.Add("@RowIndex", SqlDbType.Int, 4).Value =
    startRowIndex;
    com.Parameters.Add("@MaxRows", SqlDbType.Int, 4).Value =
    maximumRows;
    SetData(ObjectDataSource1);

    SqlDataAdapter ada = new SqlDataAdapter(com);

    DataTable dt = new DataTable();
    ada.Fill(dt);
    return dt;
    }

    At this point both GridView1 and ObjectDataSource1 are null????

    They weren't before when I did my GridView1.DataBind() and they weren't when
    I went into my PageLoad.

    So because of that I can't pass ObjectDataSource1 to my SetData program from
    this method.

    Why is that?

    Thanks,

    Tom
     
    tshad, Feb 4, 2010
    #1
    1. Advertising

  2. tshad

    tshad Guest

    It is almost as if I have left the object.

    But the BindControl method is in the page and if I put a break in the
    method, it sees the GridView1 it just happens to be null.

    Tom
    "tshad" <> wrote in message
    news:...
    >I have a GridView object that is using an ObjectDataSource, but when I get
    >I do a GridView1.DataBind(), the following method gets called:
    >
    > <asp:ObjectDataSource ID="ObjectDataSource1" EnablePaging="true"
    > runat="server" SelectCountMethod="GetRowCount"
    > SelectMethod="BindControl" TypeName="AutoUPS.AutoUPS"
    > StartRowIndexParameterName="startRowIndex"
    > MaximumRowsParameterName="maximumRows">
    > </asp:ObjectDataSource>
    >
    >
    > public DataTable BindControl(int startRowIndex, int maximumRows)
    > {
    > SqlConnection con = new
    > SqlConnection(ConfigurationManager.ConnectionStrings["ConnectString"].ConnectionString);
    > SqlCommand com = new SqlCommand("GetValidFileDetails2", con);
    > com.CommandType = CommandType.StoredProcedure;
    > com.Parameters.Add("@RowIndex", SqlDbType.Int, 4).Value =
    > startRowIndex;
    > com.Parameters.Add("@MaxRows", SqlDbType.Int, 4).Value =
    > maximumRows;
    > SetData(ObjectDataSource1);
    >
    > SqlDataAdapter ada = new SqlDataAdapter(com);
    >
    > DataTable dt = new DataTable();
    > ada.Fill(dt);
    > return dt;
    > }
    >
    > At this point both GridView1 and ObjectDataSource1 are null????
    >
    > They weren't before when I did my GridView1.DataBind() and they weren't
    > when I went into my PageLoad.
    >
    > So because of that I can't pass ObjectDataSource1 to my SetData program
    > from this method.
    >
    > Why is that?
    >
    > Thanks,
    >
    > Tom
    >
    >
    >
     
    tshad, Feb 5, 2010
    #2
    1. Advertising

  3. tshad

    tshad Guest

    As it turns out all the objects on my page are null???

    Tom

    "tshad" <> wrote in message
    news:%...
    > It is almost as if I have left the object.
    >
    > But the BindControl method is in the page and if I put a break in the
    > method, it sees the GridView1 it just happens to be null.
    >
    > Tom
    > "tshad" <> wrote in message
    > news:...
    >>I have a GridView object that is using an ObjectDataSource, but when I get
    >>I do a GridView1.DataBind(), the following method gets called:
    >>
    >> <asp:ObjectDataSource ID="ObjectDataSource1" EnablePaging="true"
    >> runat="server" SelectCountMethod="GetRowCount"
    >> SelectMethod="BindControl" TypeName="AutoUPS.AutoUPS"
    >> StartRowIndexParameterName="startRowIndex"
    >> MaximumRowsParameterName="maximumRows">
    >> </asp:ObjectDataSource>
    >>
    >>
    >> public DataTable BindControl(int startRowIndex, int maximumRows)
    >> {
    >> SqlConnection con = new
    >> SqlConnection(ConfigurationManager.ConnectionStrings["ConnectString"].ConnectionString);
    >> SqlCommand com = new SqlCommand("GetValidFileDetails2", con);
    >> com.CommandType = CommandType.StoredProcedure;
    >> com.Parameters.Add("@RowIndex", SqlDbType.Int, 4).Value =
    >> startRowIndex;
    >> com.Parameters.Add("@MaxRows", SqlDbType.Int, 4).Value =
    >> maximumRows;
    >> SetData(ObjectDataSource1);
    >>
    >> SqlDataAdapter ada = new SqlDataAdapter(com);
    >>
    >> DataTable dt = new DataTable();
    >> ada.Fill(dt);
    >> return dt;
    >> }
    >>
    >> At this point both GridView1 and ObjectDataSource1 are null????
    >>
    >> They weren't before when I did my GridView1.DataBind() and they weren't
    >> when I went into my PageLoad.
    >>
    >> So because of that I can't pass ObjectDataSource1 to my SetData program
    >> from this method.
    >>
    >> Why is that?
    >>
    >> Thanks,
    >>
    >> Tom
    >>
    >>
    >>

    >
    >
     
    tshad, Feb 5, 2010
    #3
  4. tshad

    tshad Guest

    It seems these methods have no access to the objects on the page, for some
    reason. You have to set up Select parameters to access basic data in the
    method (int,string).

    <SelectParameters>
    <asp:ControlParameter ControlID="ddlProcessJobsClient" Name="clientID"
    PropertyName="SelectedValue" Type="String" DefaultValue="1" />
    </SelectParameters>

    The problem is that I need to get access to a small Grid that has some
    dropdowns in them. I go through the dropdowns to get data I append to a
    string and send as a parameter to my stored procedure. But I can't get
    access to my Grid. I have a method on my page that will get the data for
    me, but I can't get to that either. And there is no way (that I can see) to
    use the SelectParameters to pass the Grid as it isn't a simple type.

    Tom

    "tshad" <> wrote in message
    news:...
    > As it turns out all the objects on my page are null???
    >
    > Tom
    >
    > "tshad" <> wrote in message
    > news:%...
    >> It is almost as if I have left the object.
    >>
    >> But the BindControl method is in the page and if I put a break in the
    >> method, it sees the GridView1 it just happens to be null.
    >>
    >> Tom
    >> "tshad" <> wrote in message
    >> news:...
    >>>I have a GridView object that is using an ObjectDataSource, but when I
    >>>get I do a GridView1.DataBind(), the following method gets called:
    >>>
    >>> <asp:ObjectDataSource ID="ObjectDataSource1" EnablePaging="true"
    >>> runat="server" SelectCountMethod="GetRowCount"
    >>> SelectMethod="BindControl" TypeName="AutoUPS.AutoUPS"
    >>> StartRowIndexParameterName="startRowIndex"
    >>> MaximumRowsParameterName="maximumRows">
    >>> </asp:ObjectDataSource>
    >>>
    >>>
    >>> public DataTable BindControl(int startRowIndex, int maximumRows)
    >>> {
    >>> SqlConnection con = new
    >>> SqlConnection(ConfigurationManager.ConnectionStrings["ConnectString"].ConnectionString);
    >>> SqlCommand com = new SqlCommand("GetValidFileDetails2", con);
    >>> com.CommandType = CommandType.StoredProcedure;
    >>> com.Parameters.Add("@RowIndex", SqlDbType.Int, 4).Value =
    >>> startRowIndex;
    >>> com.Parameters.Add("@MaxRows", SqlDbType.Int, 4).Value =
    >>> maximumRows;
    >>> SetData(ObjectDataSource1);
    >>>
    >>> SqlDataAdapter ada = new SqlDataAdapter(com);
    >>>
    >>> DataTable dt = new DataTable();
    >>> ada.Fill(dt);
    >>> return dt;
    >>> }
    >>>
    >>> At this point both GridView1 and ObjectDataSource1 are null????
    >>>
    >>> They weren't before when I did my GridView1.DataBind() and they weren't
    >>> when I went into my PageLoad.
    >>>
    >>> So because of that I can't pass ObjectDataSource1 to my SetData program
    >>> from this method.
    >>>
    >>> Why is that?
    >>>
    >>> Thanks,
    >>>
    >>> Tom
    >>>
    >>>
    >>>

    >>
    >>

    >
    >
     
    tshad, Feb 5, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kha Tran
    Replies:
    0
    Views:
    572
    Kha Tran
    Jun 3, 2005
  2. Danny W

    GridView update with ObjectDataSource

    Danny W, Sep 8, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    3,085
    Danny W
    Sep 8, 2005
  3. family

    gridview, objectdatasource

    family, Dec 22, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    544
    family
    Dec 22, 2005
  4. Frank Cisco

    Nulling an object

    Frank Cisco, May 17, 2009, in forum: Java
    Replies:
    35
    Views:
    1,107
    Seamus MacRae
    May 20, 2009
  5. David Thielen

    ObjectDataSource method as another ObjectDataSource

    David Thielen, Mar 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    267
    Steven Cheng[MSFT]
    Mar 23, 2006
Loading...

Share This Page