简体   繁体   English

使用主/详细方法时隐藏详细信息视图

[英]hide detailsview when using master/detail method

I am using a GridView that populates DetailsViews (master/detail method). 我正在使用填充DetailsViews(主/详细方法)的GridView。 When I click on Select in the GridView and display a DetailsView, that view remains displayed after I Select another row from the GridView and it displays another DetailsView. 当我在GridView中单击“选择”并显示一个DetailsView时,该视图在我从GridView中选择另一行后仍然显示,并显示另一个DetailsView。 My question is: how can I display only one DetailsView at the sameone time??? 我的问题是:如何只能一次显示一个DetailsView?

So far I have: 到目前为止,我有:

protected void grdMonster_SelectedIndexChanged(object sender, EventArgs e)
{
    //grdMonster is GridView and "BookTitle" is datafield and pnlBooks is panel around BookTitle  
    //DetailsView
    if (grdMonster.SelectedValue.ToString() != "BookTitle")
        pnlBooks.Visible = false;
    else
        pnlBooks.Visible = true;
} 

It doesn't work! 它不起作用! The BookTitle DetailsView doesn't display! BookTitle DetailsView不显示! } }

Fixed it by accident. 意外修复。 "BookTitle" needed to be in the DataKeyNames along with the following code (I added this code for something else): “ BookTitle”需要与以下代码一起放在DataKeyNames中(我为其他代码添加了此代码):

protected void grdMonster_SelectedIndexChanged(object sender, EventArgs e) { string BookTitle = grdMonster.DataKeys[grdMonster.SelectedIndex]["BookTitle"].ToString(); 受保护的无效grdMonster_SelectedIndexChanged(对象发送者,EventArgs e){字符串BookTitle = grdMonster.DataKeys [grdMonster.SelectedIndex] [“ BookTitle”]。ToString(); sqlDV1.SelectParameters.Clear(); sqlDV1.SelectParameters.Clear(); sqlDV1.SelectParameters.Add("BookTitle", BookTitle); sqlDV1.SelectParameters.Add(“ BookTitle”,BookTitle); dtv1.DataBind(); dtv1.DataBind(); } }

Not quite sure how that works, but it does. 不太确定它是如何工作的,但是确实可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM