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

LVL 1
jjrr007Asked:
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
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

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.  
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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

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
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.