Top DevX Stories
Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Search the forums:

Go Back   DevX.com Forums > DevX Developer Forums > ASP.NET

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 10-26-2009, 06:53 AM
theit8514 theit8514 is offline
Registered User
 
Join Date: Oct 2009
Posts: 3
Question Migration from DataView to ListView

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 { }
        }
    }
Upon debugging, I can see chkBox.ID getting set to the new value "dg1_1","dg1_2", etc.
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)
...
cb.ID is always chkSelect, and not what I specified in the ItemDataBound.

Has anyone experienced this before? Am I completely insane doing it this way?
Reply With Quote
  #2  
Old 10-26-2009, 12:36 PM
theit8514 theit8514 is offline
Registered User
 
Join Date: Oct 2009
Posts: 3
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*
Reply With Quote
  #3  
Old 10-26-2009, 01:06 PM
theit8514 theit8514 is offline
Registered User
 
Join Date: Oct 2009
Posts: 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.
Reply With Quote
Reply

Bookmarks

Tags
checkbox, itemdatabound, listitem

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

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


All times are GMT -4. The time now is 10:33 PM.


Sponsored Links



Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.