I am using a GridView that populates DetailsViews (master/detail method). 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. My question is: how can I display only one DetailsView at the sameone time???
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! }
Fixed it by accident. "BookTitle" needed to be in the DataKeyNames along with the following code (I added this code for something else):
protected void grdMonster_SelectedIndexChanged(object sender, EventArgs e) { string BookTitle = grdMonster.DataKeys[grdMonster.SelectedIndex]["BookTitle"].ToString(); sqlDV1.SelectParameters.Clear(); sqlDV1.SelectParameters.Add("BookTitle", BookTitle); dtv1.DataBind(); }
Not quite sure how that works, but it does.