ObjectDataSource nulling GridView

T

tshad

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
 
T

tshad

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
 
T

tshad

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

Tom

tshad said:
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 said:
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
 
T

tshad

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 said:
As it turns out all the objects on my page are null???

Tom

tshad said:
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 said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top