|
#1
|
|||
|
|||
|
I'm working on converting a DataView object to a ListView object. What I had previously was working but the source data became so long so I decided to move to ListView so I could do multiple columns.
I'm running into a few problems though. When I was working with DataView I was able to set each Item's checkbox by using OnItemDataBound. The same method for ListView is not working: Code:
protected void lv1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
try
{
CheckBox chkBox = (CheckBox)e.Item.FindControl("chkSelect");
using (ListViewDataItem lvdi = (ListViewDataItem)e.Item)
{
if (lvdi != null)
{
chkBox.ID = "dg1_" + DataBinder.Eval(lvdi.DataItem, "ServerID");
chkBox.Text = (string)DataBinder.Eval(lvdi.DataItem, "Server_Name");
chkBox.TabIndex = (short)(lvdi.DataItemIndex + 6);
}
}
}
catch { }
}
}
When I look in the source of the page, the first checkbox is name="lv1$ctrl0$ctl00$dg1_1" However, when I do a postback using a button onClick="doPostBack" Code:
protected void doPostBack(object sender, EventArgs e)
{
ListView tdg1 = (ListView)this.FindControl("inputform1").FindControl("lv1");
...
foreach (ListViewItem dgi in tdg1.Items)
{
counta += dgi.Controls.Count;
foreach (Control cc in dgi.Controls)
{
debug += cc.ID;
if (cc.GetType() == typeof(CheckBox))
{
CheckBox cb = (CheckBox)cc;
if (cb.Checked == true)
{
Regex r = new Regex("dg1_(?<id>[0-9]+)");
Match m = r.Match(cb.ID);
if (m.Success)
...
Has anyone experienced this before? Am I completely insane doing it this way? |
|
#2
|
|||
|
|||
|
An update to this, I have also tried the DataList control, but I can't seem to get anything to stick.
I set both ID and Attributes["sid"] in the ItemDataBound function, and when its posted back both are not keeping their values. Another note: If I remove the CheckBox's ID tag from the aspx file, in the postback it returns null, which I thought was impossible. *sigh* |
|
#3
|
|||
|
|||
|
Heh, Ooops. I took another look at the debugging for the assignment of chkBox.ID, it was failing due to a missing cast.
int d = (int)DataBinder.Eval(dli.DataItem, "ServerID"); c.ID = "dg1_" + d.ToString(); Unfortunately, that still didn't work as the ID still shows up as "chkBox" in the postback. However, now that it is getting to where it assigns the attribute, I can now pick up cb.Attributes["sid"] from the postback and all is well. |
![]() |
| Bookmarks |
| Tags |
| checkbox, itemdatabound, listitem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Please Help me with Drag-n-Drop of multiple items from one Listview to another. | vb_programmer | VB Classic | 1 | 09-16-2006 08:37 PM |
| ListView Control and Custom Sorting | Birhanu | VB Classic | 0 | 11-09-2001 04:26 PM |
| ListView Control and Custom Sorting | Birhanu | VB Classic | 0 | 11-09-2001 04:26 PM |
| Listview boxes | Kenneth | VB Classic | 0 | 04-24-2001 12:04 PM |
| Re: Listview Item structure HELP. | Diego | VB Classic | 1 | 08-28-2000 09:15 AM |