Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET bind
Good day
 
I have created a website in ASP.net using Datalists. I am binding the data from a database using a datalist. I am trying to expand and collapse the items in the datalist. When I click on the first item in the datalist, it expands and when I click on the first item again, then it collapses. That is working 100%.
 
The problem that I have is, when I click on the first item in the datalist, and I click on the second item in the datalist, the first item in the datalist stays open..
 
When I want to collapse the first item in the datalist, after opening the second item in the datalist, by clicking again on the first item in the datalist, both items are closing.. What can I add or change in my coding, so that when I open another item in the datalist, the previous one that I opened, collapse automatically?
 
Here is my code
 
protected void Page_Load(object sender, EventArgs e)
    {
       
            if (!IsPostBack)
            {
                Session["SystemName"] = "";
                loadSystemnames();
            }
     }
//Loading the names in the datalist
    public void loadSystemnames()
    {
        clsTsogoSafe.Instance.Decrypt();
        clsDBCalls objDBcalls = new clsDBCalls();
       
        dtSystems = objDBcalls.dtSystems();
        dtlSystems.DataSource = dtSystems;
        dtlSystems.DataBind();
    }
 
//Clicking on an item in the datalist will expand or close an item in the datalist
    public void lnkSystemnames_Click(object sender, DataListCommandEventArgs e)
    {
 
        if (IsPostBack)
        {
            clsDBCalls objDBcalls = new clsDBCalls();
 
            DataTable dtfullDesc = new DataTable();
            int iDTListID = e.Item.ItemIndex;
     
            LinkButton strlblSystem = e.Item.FindControl("lnkSystem") as LinkButton;
            string strValue = strlblSystem.Text;
 
            if (Session["SystemName"].ToString() != strValue)
            {
 
                dtfullDesc = objDBcalls.dtSystemDescription(strValue);
                DataList dtSystemdescription = e.Item.FindControl("dtSystemDescription") as DataList;
 
                Session["SystemName"] = strValue;
                dtSystemdescription.DataSource = dtfullDesc;
                dtSystemdescription.DataBind();
            }
            else
            {
                Session["SystemName"] = "";
                loadSystemnames();
            }
        }
    } 
 
Thanks for the help
Posted 27-Aug-12 3:16am
JacoBosch1.4K
Edited 27-Aug-12 5:46am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

public void lnkSystemnames_Click(object sender, DataListCommandEventArgs e)
   {
 
       if (IsPostBack)
       {
//here use for loop on datalist row to collapse row if it is open it will collpase all
//row

//your code as it is so first you are collapse all row then your code to open only //clicked row
  Permalink  
Comments
JacoBosch at 27-Aug-12 8:48am
   
Hi pradiprenushe, thanks for the reply.. How can I check whether the row was opened, because at the momemnt I am only checking whether the item was clicked.
pradiprenushe at 27-Aug-12 8:51am
   
What are you using for collapsing?
If you are using ajax collapsible panel then refer this
http://chandradev819.wordpress.com/2010/11/03/how-to-make-collapable-panel-in-datalist-using-ajax/
http://www.vbforums.com/showthread.php?637327-RESOLVED-AJAX-Collapsible-Panel-inside-Repeater-strangeness
JacoBosch at 27-Aug-12 9:00am
   
When I am collapsing the item in the datalist, I used a session variable, and rebinded the data.. I am not using the ajax collapsible panel.
pradiprenushe at 27-Aug-12 9:03am
   
use some hidden field to store row info which is open. while in for loop check rowid with that hidden field
JacoBosch at 27-Aug-12 10:39am
   
Hi pradiprenushe, I have tried it, but it did not work.. Do you have any other idea how this problem can be solved?
pradiprenushe at 28-Aug-12 0:40am
   
if (IsPostBack)
{
loadSystemnames();// call this methis
//your code as it is

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 27 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100