Hi,
I am trying to use a REPEATER to display data. I have added a button to my item template. The data displays fine, and the buttons show as expected. The problem is events. I load and bind the repeater in the page_load function and so whenever I click a button the entire table goes away along with all its goodies. And if I set a breakpoint in the repeaters event handler it never seems to get called. I have read many posts but cant seem to find exactly what I need. From what I gather the repeater has a view stat that should persist if you create the repeater in the page_load function, and the event should fire if you are checking for postback in the page_load function before you databind on the repeater. Here is some code for insight.
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
SqlConnection conx = new SqlConnection(@"Initial Catalog=ATC_Prod;Data Source=localhost;User ID=matt;Password=snoochie;timeout=10");
conx.Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand();
SqlParameter param1 = new SqlParameter();
SqlParameter param2 = new SqlParameter();
param1.ParameterName = "@customer";
param2.ParameterName = "@po";
param1.Value = DropDownList1.SelectedValue;
param2.Value = DropDownList2.SelectedValue;
da.SelectCommand.Parameters.Add(param1);
da.SelectCommand.Parameters.Add(param2);
da.SelectCommand.Connection = conx;
da.SelectCommand.CommandText = "Select distinct(PartNumber), count(PartNumber) from dbo.vw_order_statusAll WHERE Customer = @customer AND PO = @po GROUP BY PartNumber ORDER BY 1 DESC;";
da.Fill(ds, "vw_order_statusAll");
Repeater1.DataSource = ds.Tables[0];
Repeater1.DataBind();
}
AND MY REPEATER CODE:
<asp:Repeater id="Repeater1" OnItemCommand="Button_ItemCommand" runat="server">
<HeaderTemplate>
<table border="1">
<tr style="background: beige">
<th>Part Number</th>
<th>WO Qty</th>
<th>Get #'s</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background: white">
<td><%# DataBinder.Eval(Container.DataItem, "PARTNUMBER")%></td>
<td><%# DataBinder.Eval(Container.DataItem, "Column1")%></td>
<td><asp:Button CommandName="ID" Text = "WO Nums" runat="server" /></td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr style="background: beige">
<td><%# DataBinder.Eval(Container.DataItem, "PARTNUMBER")%></td>
<td><%# DataBinder.Eval(Container.DataItem, "Column1")%></td>
<td><asp:Button CommandName="ID" Text = "WO Nums" runat="server" /></td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
I am trying to use a REPEATER to display data. I have added a button to my item template. The data displays fine, and the buttons show as expected. The problem is events. I load and bind the repeater in the page_load function and so whenever I click a button the entire table goes away along with all its goodies. And if I set a breakpoint in the repeaters event handler it never seems to get called. I have read many posts but cant seem to find exactly what I need. From what I gather the repeater has a view stat that should persist if you create the repeater in the page_load function, and the event should fire if you are checking for postback in the page_load function before you databind on the repeater. Here is some code for insight.
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
SqlConnection conx = new SqlConnection(@"Initial Catalog=ATC_Prod;Data Source=localhost;User ID=matt;Password=snoochie;timeout=10");
conx.Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand();
SqlParameter param1 = new SqlParameter();
SqlParameter param2 = new SqlParameter();
param1.ParameterName = "@customer";
param2.ParameterName = "@po";
param1.Value = DropDownList1.SelectedValue;
param2.Value = DropDownList2.SelectedValue;
da.SelectCommand.Parameters.Add(param1);
da.SelectCommand.Parameters.Add(param2);
da.SelectCommand.Connection = conx;
da.SelectCommand.CommandText = "Select distinct(PartNumber), count(PartNumber) from dbo.vw_order_statusAll WHERE Customer = @customer AND PO = @po GROUP BY PartNumber ORDER BY 1 DESC;";
da.Fill(ds, "vw_order_statusAll");
Repeater1.DataSource = ds.Tables[0];
Repeater1.DataBind();
}
AND MY REPEATER CODE:
<asp:Repeater id="Repeater1" OnItemCommand="Button_ItemCommand" runat="server">
<HeaderTemplate>
<table border="1">
<tr style="background: beige">
<th>Part Number</th>
<th>WO Qty</th>
<th>Get #'s</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background: white">
<td><%# DataBinder.Eval(Container.DataItem, "PARTNUMBER")%></td>
<td><%# DataBinder.Eval(Container.DataItem, "Column1")%></td>
<td><asp:Button CommandName="ID" Text = "WO Nums" runat="server" /></td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr style="background: beige">
<td><%# DataBinder.Eval(Container.DataItem, "PARTNUMBER")%></td>
<td><%# DataBinder.Eval(Container.DataItem, "Column1")%></td>
<td><asp:Button CommandName="ID" Text = "WO Nums" runat="server" /></td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>