473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Question about programmatic access to Button in Repeater control

Hi,

I have a Repeater control which is bound to a dataset. In the footer of the
repeater control, I have a Button whose visibility I want to vary according
to the sum of a column being > 0.

I have tried to set the button's visibility in Page_Load (after data
binding), but I get a NullReferenceException stating that "Object reference
not set to an instance of an object".

I'm sure this has to do with when my repeater control and it's contained
controls are being rendered, I've tried putting the logic in several places
but I can't figure it out. Below is the code; thank you for any help.

-Keith

==========================================
WebForm.aspx
==========================================
<asp:Repeater id="Repeater1" runat="server">
<HeaderTemplate>
<table>
<tr>
<td>Name</td>
<td>Num Users</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem,"GroupName") %></td>
<td><%# DataBinder.Eval(Container.DataItem,"NumUsers") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td>
<asp:Button id="buttonNext" runat="server" Text="Next"
OnClick="buttonNext_Click" Visible="True"></asp:Button>
</td>
</tr>
</table>
</FooterTemplate>

==========================================
WebForm.aspx.cs
==========================================
....
protected System.Web.UI.WebControls.Repeater Repeater1;
protected System.Web.UI.WebControls.Button buttonNext;
....
private void Page_Load(object sender, System.EventArgs e)
{
this.Repeater1.DataSource=dsDataSet;
this.Repeater1.DataBind();

object
sum=dsDataSet.Tables[0].Compute("SUM(NumUsers)","NumUsers=NumUsers");

buttonNext.Visible=( (int)sum > 0 );
}
Nov 16 '05 #1
1 1723
There are events for this sort of thing, like ItemCreated... Where you can
access your e.Item and then go look for controls on it.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Keith Harris" <Ke*********@discussions.microsoft.com> wrote in message
news:EE**********************************@microsof t.com...
Hi,

I have a Repeater control which is bound to a dataset. In the footer of the
repeater control, I have a Button whose visibility I want to vary according
to the sum of a column being > 0.

I have tried to set the button's visibility in Page_Load (after data
binding), but I get a NullReferenceException stating that "Object reference
not set to an instance of an object".

I'm sure this has to do with when my repeater control and it's contained
controls are being rendered, I've tried putting the logic in several places
but I can't figure it out. Below is the code; thank you for any help.

-Keith

==========================================
WebForm.aspx
==========================================
<asp:Repeater id="Repeater1" runat="server">
<HeaderTemplate>
<table>
<tr>
<td>Name</td>
<td>Num Users</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem,"GroupName") %></td>
<td><%# DataBinder.Eval(Container.DataItem,"NumUsers") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td>
<asp:Button id="buttonNext" runat="server" Text="Next"
OnClick="buttonNext_Click" Visible="True"></asp:Button>
</td>
</tr>
</table>
</FooterTemplate>

==========================================
WebForm.aspx.cs
==========================================
...
protected System.Web.UI.WebControls.Repeater Repeater1;
protected System.Web.UI.WebControls.Button buttonNext;
...
private void Page_Load(object sender, System.EventArgs e)
{
this.Repeater1.DataSource=dsDataSet;
this.Repeater1.DataBind();

object
sum=dsDataSet.Tables[0].Compute("SUM(NumUsers)","NumUsers=NumUsers");

buttonNext.Visible=( (int)sum > 0 );
}

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Stephen | last post by:
Hi, I have a quick question. I am displaying all the orders that are active. I am making use of a datarepeater with checkboxes to display data and a submit button to insert into the database. ...
1
by: Fraggle | last post by:
I have a repeater with controls added at run time. the <template> also contains a <asp:textbox that is made visible on some repeater elements. when I come to read the text info out it has...
5
by: Darren Smith | last post by:
Hi There, I have a shopping cart app that displays products along with a textbox (to enter quantity) and an image button to add the item to the shopping cart. Please explain why my below...
1
by: Z D | last post by:
Hello, I have a checkbox control as one of the items within my repeater control. I've set the AutoPostBack=True on the checkbox. How do I access the event (so that I can run some code)...
1
by: Keith Harris | last post by:
Hi, I have a Repeater control which is bound to a dataset. In the footer of the repeater control, I have a Button whose visibility I want to vary according to the sum of a column being > 0. ...
6
by: Joe | last post by:
Hi, I have a MS Access DB in which a record has just too many fields to be able to allow users to do inline editing in a datagrid. So I want to display as First Name: Text box where first...
3
by: Shimon Sim | last post by:
I put linkbutton in a repeater header. I attached event handler in makeup as onclick="btnSort_Click". Made btnSort_Click method public. It doesn't fire if I click on it. I tried to attach it in...
6
by: Blaine Manyluk | last post by:
I have a very unusual request. I need to be able to generate reports and save them as TIF files, with full programmatic control. The application will provide the filenames. Each page of the...
11
by: J055 | last post by:
Hi I have a dropdown control which is constructed in another dropdown control SelectedIndexChanged event protected void ddlParamType_SelectedIndexChanged(object sender, EventArgs e) { //...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.