ASP.NET在Datagrid行中显示/隐藏节

时间:2010-04-09 14:54:35

标签: asp.net asp.net-ajax datagridview collapsiblepanelextender

我有一个数据网格,其中每一行都有关于公司员工的信息。 我想允许每一行显示/隐藏额外信息。我的第一个想法是使用AJAX工具包中的CollapsiblePanelExtender并让每一行都像这样:

<ajaxtoolkit:collapsiblepanelextender
     TargetControlID="panel2">
     ExpandControlID="LinkButton1"
     CollapseControlID="LinkButton1">
</ajaxtoolkit:collapsiblepanelextender>

<asp:panel>
    FirstName | LastName | Phone | Email
    <LinkButton1>  <- this hides/show extra info in panel2
</asp:panel>

<asp:panel2>
     <textbox ="FirstName">
     <textbox ="LastName">
     <textbox ="EmailName">
     ...
     ...lots of textboxes where information is assigned from the database.
</asp:panel2>

这非常有效,但它的计算成本可能很高。额外的信息面板有很多文本框/标签,所有文本框/标签都从数据库中获取其值。 每次页面加载时,所有数据都是从数据库开始获取的,其中一些数据是隐藏的。

有没有更好的方法来实现我的目标?或者,有没有办法在单击“显示/隐藏”按钮时仅为员工加载额外的详细信息?

提前致谢!

1 个答案:

答案 0 :(得分:1)

我使用ModalPopupExtender完成了类似的操作。 我有一个带有文本框和标签的面板,只有当用户按下图像按钮时才能检索信息。 在此示例中,图像按钮位于GridViewRow中,用于检索数据的键位于Row的DataKeys属性中。

GridViewRow row = ((GridViewRow)((ImageButton)sender).NamingContainer);
//NamingContainer return the container that the control sits in
DataKey key = ((GridView)row.NamingContainer).DataKeys[row.RowIndex];

//Retrieve data with a server method. It can be with wathever you want, I use an ArrayList
ArrayList AL=Domain.GetCustomerData(key[0].ToString());

//Fill controls with data, 
LblDate.Text = AL[0].ToString();
dLectHidro.Value = AL[1].ToString();
idLectHL.Value = AL[2].ToString();
LblEstacion.Text = HttpUtility.HtmlDecode(AL[3].ToString());
TxtLluvia.Text = HttpUtility.HtmlDecode(AL[4].ToString());
TxtLluvia1.Text = HttpUtility.HtmlDecode(AL[5].ToString());

//Show the popup
this.ModalPopupModif.Show();

希望这会有所帮助。 克劳迪亚

相关问题