Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

Details View Visible When

I am having trouble with some code.  When a row is selected in a GridView, the DetailView should be visibile.    I am doing this by using the code in the snippet, but for some reason I can't see the DetailView when a row is selected in the GridView.

BTW, I am using the code below in ASP.net to tell the DetailsView which value to take from the GridView

        <SelectParameters>
            <asp:ControlParameter ControlID="GridView1" DefaultValue="0" Name="ThreadPostID"
                PropertyName="SelectedValue" Type="Int32" />
        </SelectParameters>

What do you suggest that I change?  Thanks!

 

public partial class _Default : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.DetailsView1.Visible = false;
        }
 
        protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {
 
            this.DetailsView1.PageIndex = e.NewSelectedIndex;
            this.DetailsView1.Visible = true;
        }
 
    }

Open in new window

0
jjrr007
Asked:
jjrr007
  • 4
  • 3
1 Solution
 
Anurag ThakurTechnical ManagerCommented:
this looks like a better approach to me
http://www.aspdotnetcodes.com/Parent_Child_GridView_DetailsView.aspx

i am saying so as i am seeing that you are just setting the page index of the details view so you might be loading all the data on the page load so means that your entire data is present from the start
but in the above sample the data is brought everytime the index is changed in gridview
0
 
jjrr007Author Commented:
Is there a simpler way to do this?  I am hoping to just change the code I have provided.  

The Details View is returning all of the values as a default. However, it should only be visible when a value is selected in the GridView.  Thanks.  
0
 
Anurag ThakurTechnical ManagerCommented:
first you have just provided a fragment of code from your page and the second reason i will prefer to do the way my sample is done becasue its more efficient as the details view will be loaded with the data only when something is changed in the gridveiw and not at page load itself
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
jjrr007Author Commented:
Thanks ragi0017, I will try this when I get in the office in the morning and let you know.
0
 
jjrr007Author Commented:
Thanks for your time.  That worked but an issue came up.  Earlier, I had a message appear if the GridView didn't return any data.  Using this approach, I can't get the message to work since the settings were  in asp.net instead of in the code.  

Using this approach, do you know how I can have a message appear saying "there's no data" if the GridView doesn't return any data?

Thanks again
0
 
Anurag ThakurTechnical ManagerCommented:
if you bind the gridview with a datasource and the datasource does not contain any data then to indicate that set the emptydatatemplate
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.emptydatatemplate(VS.80).aspx
0
 
jjrr007Author Commented:
Thanks for your time and expertise!  It worked!!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now