Datagrid with web user controls

S

slersami

Any help is appreciated!
My problem is following:

I have a datagrid consisting of only one column. Template contains
several standard web controls (image, label, etc.). Datagrid is
populated from database. This part works OK.

I also like to have checkboxes in the datagrid so that user can select
them; after pushing a button checkboxes IDs are collected and some
actions are performed based on checkboxes checked. I do not like to
raise an event when check box is checked or unchecked.

What I did - I created user control AlbumChkBox, added checkbox control
to it and added properties to the class:

public string CheckBxID
{
get {return ChkBxID;}
set {this.ChkBxID = value;}
}
public bool EmbChkBxStatus
{
get {return this.achkb.Checked;}
set {this.achkb.Checked=value;}
}

Added control to the web page, containing the datagrid. Populated
CheckBxID's with values from database.

Added code to find out first checked checkbox (for debugging purposes):

for (int i = 0; i < this.datagrid7.Items.Count; i++)
{
DataGridItem dgItem = datagrid7.Items;
AlbChBxOne = (AlbumChkBox)dgItem.FindControl("AlbChBx1");
if (AlbChBxOne.EmbChkBxStatus == true)
{
this.TextBox1.Text = AlbChBxOne.CheckBxID.ToString();
break;
}
}

Problem is that it is impossible to retrieve status/id of checkbox in
AlbumChkBox. No error is generated and no value is retrieved either. I
checked the source of the web page. AlbumChkBox-es control are listed
there, however in strange form - id="datagrid7__ctl24_AlbChBx1_achkb
instead of id="datagrid7__ctl24_AlbChBx1. I tried to modify the line

AlbChBxOne = (AlbumChkBox)dgItem.FindControl("AlbChBx1_achkb") but
result was the same.

Is it .NET bug or I am doing something wrong?
Please help!
 

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,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top