B
Brad Baker
I'm going a little crazy
I'm trying to bind a repeater control to a
dataset on page load using the following code:
if (Request.QueryString["customerid"] != null)
{
string customerid = Request.QueryString["customerid"];
//open connection
SqlConnection m_conn = new SqlConnection("Server=server;
Database=database; UId=username; Pwd=password");
m_conn.Open();
// Create a SQL query
SqlDataAdapter tabs_query = new SqlDataAdapter("select site_id
from table where customer_id=@customerid", m_conn);
tabs_query.SelectCommand.Parameters.Add(new
SqlParameter("@customerid", customerid));
// Create and fill a DataSet
DataSet tabs_ds = new DataSet();
tabs_query.Fill(tabs_ds);
// Temp code to see if the datasource is being populated
if (tabs_ds != null) {
Response.Write("Results table is not null");
} else {
// write some kind of error message
Response.Write("Results table is null");
}
// (The code above produces not null)
// Bind tabs_repeater to the DataSet.
((Repeater)this.FormView1.Row.FindControl("tabs_repeater")).DataSource
= tabs_ds;
((Repeater)this.FormView1.Row.FindControl("tabs_repeater")).DataBind();
m_conn.Close();
}
.... later in the page .....
<ASP:Repeater id="tabs_repeater" runat="server">
<HeaderTemplate>
<table><tr>
</HeaderTemplate>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "site_id") %>
</ItemTemplate>
<FooterTemplate>
<td><h2>Information</h2></td></tr></table>
</FooterTemplate>
</ASP:Repeater>
I'm getting an error indicating: Object reference not set to an instance of
an object. The error references this line:
((Repeater)this.FormView1.Row.FindControl("tabs_repeater")).DataSource =
tabs_ds;
I'm probably doing something stupid but I just can't seem to figure out what
it is. Can anyone help?
Thank You!
Brad
dataset on page load using the following code:
if (Request.QueryString["customerid"] != null)
{
string customerid = Request.QueryString["customerid"];
//open connection
SqlConnection m_conn = new SqlConnection("Server=server;
Database=database; UId=username; Pwd=password");
m_conn.Open();
// Create a SQL query
SqlDataAdapter tabs_query = new SqlDataAdapter("select site_id
from table where customer_id=@customerid", m_conn);
tabs_query.SelectCommand.Parameters.Add(new
SqlParameter("@customerid", customerid));
// Create and fill a DataSet
DataSet tabs_ds = new DataSet();
tabs_query.Fill(tabs_ds);
// Temp code to see if the datasource is being populated
if (tabs_ds != null) {
Response.Write("Results table is not null");
} else {
// write some kind of error message
Response.Write("Results table is null");
}
// (The code above produces not null)
// Bind tabs_repeater to the DataSet.
((Repeater)this.FormView1.Row.FindControl("tabs_repeater")).DataSource
= tabs_ds;
((Repeater)this.FormView1.Row.FindControl("tabs_repeater")).DataBind();
m_conn.Close();
}
.... later in the page .....
<ASP:Repeater id="tabs_repeater" runat="server">
<HeaderTemplate>
<table><tr>
</HeaderTemplate>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "site_id") %>
</ItemTemplate>
<FooterTemplate>
<td><h2>Information</h2></td></tr></table>
</FooterTemplate>
</ASP:Repeater>
I'm getting an error indicating: Object reference not set to an instance of
an object. The error references this line:
((Repeater)this.FormView1.Row.FindControl("tabs_repeater")).DataSource =
tabs_ds;
I'm probably doing something stupid but I just can't seem to figure out what
it is. Can anyone help?
Thank You!
Brad