472,969 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Reading columns in a datagrid that is nested in a repeater

Hi everyone,

I have a datagrid that I create inside a Repeater at runtime. I have
defined a checkbox beside each row so that users can select multiple rows.
<asp:datagrid id="dgProducts" HorizontalAlign="Center"
AutoGenerateColumns="false" CellPadding="2"
runat="server" >
......
<asp:TemplateColumn HeaderText="" HeaderStyle-Width="20">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:CheckBox ID="cbxProduct" Runat="server"
AutoPostBack="False"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>

Just below my datagrid I have a button (Add button). I want to read the
values of all the checkboxes in my dynamically created datagrid. But it
keeps complaining that

System.NullReferenceException: Object reference not set to an instance of an
object.
for that Line Response.Write...

This is the code
private void btnAddProducts_Click(object sender, System.EventArgs e)
{
DataGrid dgProducts = this.Page.FindControl("dgProducts") as DataGrid;
Response.Write("Rows: " + dgProducts.Items.Count);
}

Can someone please help me with this?

Thank you
Maz
Nov 19 '05 #1
3 1504
wrong name FindControl("dgProducts") : name (and ids) must be reasonably
unique and are thus :
- prefixed by the name of the parent container.
- suffixed by a number

you will have to iterate through the object hierarchy looking for objects
whose id includes "cbxProduct"

"Maziar Aflatoun" <ma***@rogers.com> a écrit dans le message de news:
08********************@rogers.com...
Hi everyone,

I have a datagrid that I create inside a Repeater at runtime. I have
defined a checkbox beside each row so that users can select multiple rows.
<asp:datagrid id="dgProducts" HorizontalAlign="Center"
AutoGenerateColumns="false" CellPadding="2"
runat="server" >
.....
<asp:TemplateColumn HeaderText="" HeaderStyle-Width="20">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:CheckBox ID="cbxProduct" Runat="server"
AutoPostBack="False"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>

Just below my datagrid I have a button (Add button). I want to read the
values of all the checkboxes in my dynamically created datagrid. But it
keeps complaining that

System.NullReferenceException: Object reference not set to an instance of
an object.
for that Line Response.Write...

This is the code
private void btnAddProducts_Click(object sender, System.EventArgs e)
{
DataGrid dgProducts = this.Page.FindControl("dgProducts") as DataGrid;
Response.Write("Rows: " + dgProducts.Items.Count);
}

Can someone please help me with this?

Thank you
Maz

Nov 19 '05 #2
Isn't dgProducts unique? Can you please show me an example? (Prefixed by the
name of the parent container and suffixed by a number)? Is there an easier
way to do this?

Thanks
Maz.

"Michel de Becdelièvre" <m_*****@msn.com> wrote in message
news:Oe**************@TK2MSFTNGP09.phx.gbl...
wrong name FindControl("dgProducts") : name (and ids) must be reasonably
unique and are thus :
- prefixed by the name of the parent container.
- suffixed by a number

you will have to iterate through the object hierarchy looking for objects
whose id includes "cbxProduct"

"Maziar Aflatoun" <ma***@rogers.com> a écrit dans le message de news:
08********************@rogers.com...
Hi everyone,

I have a datagrid that I create inside a Repeater at runtime. I have
defined a checkbox beside each row so that users can select multiple
rows.
<asp:datagrid id="dgProducts" HorizontalAlign="Center"
AutoGenerateColumns="false" CellPadding="2"
runat="server" >
.....
<asp:TemplateColumn HeaderText="" HeaderStyle-Width="20">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:CheckBox ID="cbxProduct" Runat="server"
AutoPostBack="False"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>

Just below my datagrid I have a button (Add button). I want to read the
values of all the checkboxes in my dynamically created datagrid. But it
keeps complaining that

System.NullReferenceException: Object reference not set to an instance of
an object.
for that Line Response.Write...

This is the code
private void btnAddProducts_Click(object sender, System.EventArgs e)
{
DataGrid dgProducts = this.Page.FindControl("dgProducts") as DataGrid;
Response.Write("Rows: " + dgProducts.Items.Count);
}

Can someone please help me with this?

Thank you
Maz


Nov 19 '05 #3
Hi Maz,

No, it’s in the Repeater, so it’s not unique.
You should use repeater.Items[index].FindControl("dgProducts").

HTH

Elton Wang
el********@hotmail.com
"Maziar Aflatoun" wrote:
Hi everyone,

I have a datagrid that I create inside a Repeater at runtime. I have
defined a checkbox beside each row so that users can select multiple rows.
<asp:datagrid id="dgProducts" HorizontalAlign="Center"
AutoGenerateColumns="false" CellPadding="2"
runat="server" >
......
<asp:TemplateColumn HeaderText="" HeaderStyle-Width="20">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:CheckBox ID="cbxProduct" Runat="server"
AutoPostBack="False"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>

Just below my datagrid I have a button (Add button). I want to read the
values of all the checkboxes in my dynamically created datagrid. But it
keeps complaining that

System.NullReferenceException: Object reference not set to an instance of an
object.
for that Line Response.Write...

This is the code
private void btnAddProducts_Click(object sender, System.EventArgs e)
{
DataGrid dgProducts = this.Page.FindControl("dgProducts") as DataGrid;
Response.Write("Rows: " + dgProducts.Items.Count);
}

Can someone please help me with this?

Thank you
Maz

Nov 19 '05 #4

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

Similar topics

1
by: Lalit Bhatia | last post by:
how can we fix first column in DataGrid? Regards, Lalit Bhatia
0
by: Lalit Bhatia | last post by:
thanks for the answer but I need it for windows forms. I have a desktop application where I need to implement this. -- Regards, Lalit Bhatia "Mona" <mona@discussions.microsoft.com> wrote in...
0
by: Maziar Aflatoun | last post by:
Hi everyone, I have a datagrid that I create inside a Repeater at runtime. I have defined a checkbox beside each row so that users can select multiple rows. <asp:datagrid id="dgProducts"...
3
by: Antonio Maciel | last post by:
Hi. I have a datatable created at runtime that I want to display using a repeater control. The problem is that the number of columns of the datatable can vary. Is there any way to configure the...
6
by: John Ruiz | last post by:
Greetings, I originally posted this to microsoft.public.dotnet.framework.aspnet.datagridcontrol two weeks ago, but no one was able to answer. I am unable to dynamically add columns to a...
2
by: Simon Harris | last post by:
Hi All, I have an app which requires a list of coutries to be displayed, so far I have a datagrid which contains displays the countries Ok, along with flag images, these are also links to my...
2
by: mark | last post by:
(not sure if this is the correct group) My problem is I need to have a "nested" repeater. I have an array which I load into a hashtable - that part works great. I can setup the second repeater...
2
by: mark4asp | last post by:
This page is currently using a Repeater control to create a table with 6 columns. The first column has 2 ImageButton controls and a common header. How can I do this with a DataGrid ? I need...
2
by: Ralf | last post by:
I have a custome request to print a gridview with lots of columns, 31 to be exact. I know how to print out a gridview, done it already for a GV with 6 columns. But, this GV is very wide and will...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.