问题描述
美好的一天
我已经使用数据列表在ASP.net中创建了一个网站.我正在使用数据列表绑定数据库中的数据.我正在尝试展开和折叠数据列表中的项目.当我单击数据列表中的第一个项目时,它会展开,而当我再次单击第一个项目时,它会折叠.可以100%工作.
我遇到的问题是,当我单击数据列表中的第一项,然后单击数据列表中的第二项时,数据列表中的第一项保持打开状态..
当我想折叠数据列表中的第一项时,在打开数据列表中的第二项后,再次单击数据列表中的第一项,这两项都将关闭.我可以在编码中添加或更改什么,以便当我打开数据列表中的另一个项目时,我打开的上一个项目会自动折叠吗?
这是我的代码
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
推荐答案
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
这篇关于收集和扩展数据列表中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!