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 to tell the DetailsView which value to take from the GridView

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

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

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Anurag ThakurTechnical ManagerCommented:
this looks like a better approach to me

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.  
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
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

jjrr007Author Commented:
Thanks ragi0017, I will try this when I get in the office in the morning and let you know.
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 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
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
jjrr007Author Commented:
Thanks for your time and expertise!  It worked!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.