Disable the visibility of controls dependant on gridview

Last post 05-11-2008 7:30 AM by KelseyThornton. 8 replies.

Sort Posts:

  • Disable the visibility of controls dependant on gridview

    04-27-2008, 2:19 PM
    • Loading...
    • lokus
    • Joined on 09-02-2006, 12:31 PM
    • Marlton, NJ
    • Posts 126

    I have a dropdownlist that is acting like a filter against my gridview. When you select a value on the dropdownlist it takes that value, along with the id of the record and passes it to my BLL and DAL which results in a List of objects being passed back into a gridview. Now if you select a value form the dropdownlist that doesn't exist for the selected record, no objects will be passed back into the Gridview. My issue is that if the gridview isn't visible because there are zero objects, how do I set the labels and buttons I have on the form to not show? I tried setting the Visible property to false on the controls but it isn't working. I have been assuming that I need to do something like the code below in order to set the values which obviously isn't working. Any thoughts?

    if(gvwTable.Rows.Count < 0)

    {

        label1.Visible = false;

        button1.Visible = false; 

  • Re: Disable the visibility of controls dependant on gridview

    04-27-2008, 2:33 PM
    Answer
    • Loading...
    • janmaru
    • Joined on 10-23-2007, 1:28 PM
    • italia
    • Posts 430

    hi!

    maybe you should check the gvwTable.Rows.Count  in the right event, to make sure that the gridview databind has happened then put youR code in the 

    gvwTable_DataBound event

    ciao ;-)

    jan maru

    Click "Mark as Answer" on the post if my words were helpful.

  • Re: Disable the visibility of controls dependant on gridview

    04-27-2008, 2:46 PM
    • Loading...
    • KelseyThornton
    • Joined on 07-15-2007, 8:01 AM
    • Breda, The Netherlands
    • Posts 174

    you can set the cisible property of an entire column in the gridview.

    Kelsey Thornton
    (In the Netherlands)

    Don't forget - Mark the post which answered your question with "Answer", then that user will get some kudos, and your post will be marked as "Answered" for future readers!
  • Re: Disable the visibility of controls dependant on gridview

    04-27-2008, 3:26 PM
    • Loading...
    • mpt_fz
    • Joined on 07-27-2007, 2:51 PM
    • Posts 406

    Just programmatically add a row..

    Please "Mark as an Answer" if you think my post had helped you!

    Thanks.
  • Re: Disable the visibility of controls dependant on gridview

    04-27-2008, 7:03 PM
    • Loading...
    • lokus
    • Joined on 09-02-2006, 12:31 PM
    • Marlton, NJ
    • Posts 126

    janmaru:

    hi!

    maybe you should check the gvwTable.Rows.Count  in the right event, to make sure that the gridview databind has happened then put youR code in the 

    gvwTable_DataBound event

    ciao ;-)

    Could you provide a code snippet showing an example? Thanks! 

  • Re: Disable the visibility of controls dependant on gridview

    04-27-2008, 10:30 PM
    • Loading...
    • vinz
    • Joined on 10-05-2007, 11:47 AM
    • Cebu Philippines
    • Posts 4,433

    lokus :

    I have a dropdownlist that is acting like a filter against my gridview. When you select a value on the dropdownlist it takes that value, along with the id of the record and passes it to my BLL and DAL which results in a List of objects being passed back into a gridview. Now if you select a value form the dropdownlist that doesn't exist for the selected record, no objects will be passed back into the Gridview. My issue is that if the gridview isn't visible because there are zero objects, how do I set the labels and buttons I have on the form to not show? I tried setting the Visible property to false on the controls but it isn't working. I have been assuming that I need to do something like the code below in order to set the values which obviously isn't working. Any thoughts?

    Check the data from the DataSource instead of the GridView like

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {

        DataTable dt = //Set DataSource here that returna a DataTable

        if (dt.Rows.Count <= 0)

        {

           Label.Visible = false;

           Button1.Visible = false;
     

        }
     

    You can also try it on GridView_RowCreated or RowDataBound event to check if the Grid has a Data 

    Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post fixed your problem.


  • Re: Disable the visibility of controls dependant on gridview

    05-09-2008, 4:41 PM
    • Loading...
    • lokus
    • Joined on 09-02-2006, 12:31 PM
    • Marlton, NJ
    • Posts 126

    I am having an issue with a search page. By the gridview will only bind and be displayed if there are record matching a user's search term. When are no results or no gridview is displayed I would like to display a label say something like "No results found" but no matter where I put my if statement below the label does not show up. 

    For example, I'll use this in various gvwSearchResult events with no effect:

    if( gvwSearchResults.Rows.Count <= 0)

    {

    lblNoResults.Visible = true;

    }

     

    Here is some of my code behind:

    protected void Button1_Click(object sender, EventArgs e)

    {

    CISSoftwareList softwareList;

    int selection = Convert.ToInt32(ddlSelection.SelectedValue);

    string searchTerm = txtSearch.Text;

    softwareList = CISSoftwareDB.GetCISSoftwareListBySearch(searchTerm, selection);

    System.Threading.Thread.Sleep(700);

    gvwSearchResults.DataSource = softwareList;

    gvwSearchResults.DataBind();

    }

    protected void gvwSearchResults_RowDataBound(object sender, GridViewRowEventArgs e)

    {

    if (e.Row.RowType == DataControlRowType.DataRow)

    {

    e.Row.Attributes.Add(
    "onmouseover",

    "this.originalcolor=this.style.backgroundColor;" + " this.style.backgroundColor='#ecf6fb';");

    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.originalcolor;");

    }

    }

  • Re: Disable the visibility of controls dependant on gridview

    05-10-2008, 6:33 AM
    • Loading...
    • KelseyThornton
    • Joined on 07-15-2007, 8:01 AM
    • Breda, The Netherlands
    • Posts 174

    For this it's quite simple.

    Either use an EmptyDataTemplate (if you're using data templates), or set the EmptyDataText property of the gridview.

    Regarding disabling columns in your gridview, have a look at the following posts:
    http://forums.asp.net/t/1170046.aspx
    http://forums.asp.net/t/1158847.aspx
    http://forums.asp.net/t/1207321.aspx

    hope one of these helps!

    Kelsey Thornton
    (In the Netherlands)

    Don't forget - Mark the post which answered your question with "Answer", then that user will get some kudos, and your post will be marked as "Answered" for future readers!
  • Re: Disable the visibility of controls dependant on gridview

    05-11-2008, 7:30 AM
    • Loading...
    • KelseyThornton
    • Joined on 07-15-2007, 8:01 AM
    • Breda, The Netherlands
    • Posts 174

    If one or more of these replies has solved your question, please mark it as the answer - then others may benefit from the response...

    Kelsey Thornton
    (In the Netherlands)

    Don't forget - Mark the post which answered your question with "Answer", then that user will get some kudos, and your post will be marked as "Answered" for future readers!
Page 1 of 1 (9 items)