prevent DropDownList from displaying in GridView column if it's em

Discussion in 'ASP .Net' started by =?Utf-8?B?RGFiYmxlcg==?=, Apr 4, 2006.

  1. I have a number of rows in a GridView Column which don't have values for the
    DropDownList, is there a way to hide the control if it has no data?

    Here's my code:
    <ItemTemplate>
    <asp:DropDownList ID="RideDatesDropDownList" runat="server"
    DataSourceId="RideDatesSqlDataSource" DataTextField="RideDate"
    DataValueField="RideDate"
    DataTextFormatString="{0:MMM yyyy}" CssClass="waDropDownList">
    </asp:DropDownList>

    Thanks for any clues on this.
     
    =?Utf-8?B?RGFiYmxlcg==?=, Apr 4, 2006
    #1
    1. Advertising

  2. Consume the DataBound event of the dropdownlist, e.g.
    OnDataBound="ShowHideDDL"

    Then write a protected method in the codebehind like this:
    protected void ShowHideDDL(object sender, EventArgs e)
    {
    DropDownList ddl= (DropDownList) sender;
    ddl.Visible= (ddl.Items.Count>0);
    }
    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "Dabbler" wrote:

    > I have a number of rows in a GridView Column which don't have values for the
    > DropDownList, is there a way to hide the control if it has no data?
    >
    > Here's my code:
    > <ItemTemplate>
    > <asp:DropDownList ID="RideDatesDropDownList" runat="server"
    > DataSourceId="RideDatesSqlDataSource" DataTextField="RideDate"
    > DataValueField="RideDate"
    > DataTextFormatString="{0:MMM yyyy}" CssClass="waDropDownList">
    > </asp:DropDownList>
    >
    > Thanks for any clues on this.
     
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=, Apr 4, 2006
    #2
    1. Advertising

  3. RE: prevent DropDownList from displaying in GridView column if it'

    Wow Phillip, that was simple and worked on the first try! So many events, so
    little time. Thanks much.

    "Phillip Williams" wrote:

    > Consume the DataBound event of the dropdownlist, e.g.
    > OnDataBound="ShowHideDDL"
    >
    > Then write a protected method in the codebehind like this:
    > protected void ShowHideDDL(object sender, EventArgs e)
    > {
    > DropDownList ddl= (DropDownList) sender;
    > ddl.Visible= (ddl.Items.Count>0);
    > }
    > --
    > HTH,
    > Phillip Williams
    > http://www.societopia.net
    > http://www.webswapp.com
    >
    >
    > "Dabbler" wrote:
    >
    > > I have a number of rows in a GridView Column which don't have values for the
    > > DropDownList, is there a way to hide the control if it has no data?
    > >
    > > Here's my code:
    > > <ItemTemplate>
    > > <asp:DropDownList ID="RideDatesDropDownList" runat="server"
    > > DataSourceId="RideDatesSqlDataSource" DataTextField="RideDate"
    > > DataValueField="RideDate"
    > > DataTextFormatString="{0:MMM yyyy}" CssClass="waDropDownList">
    > > </asp:DropDownList>
    > >
    > > Thanks for any clues on this.
     
    =?Utf-8?B?RGFiYmxlcg==?=, Apr 4, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SnVhbmpv?=

    GridView: Filtr DropDownList from another DropDownList

    =?Utf-8?B?SnVhbmpv?=, Dec 23, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    1,885
    =?Utf-8?B?SnVhbmpv?=
    Dec 23, 2005
  2. Keith G Hicks
    Replies:
    3
    Views:
    779
    Keith G Hicks
    Feb 18, 2008
  3. BillGatesFan
    Replies:
    0
    Views:
    349
    BillGatesFan
    Jul 23, 2008
  4. mr.smiley
    Replies:
    0
    Views:
    1,588
    mr.smiley
    Apr 21, 2011
  5. Teej
    Replies:
    2
    Views:
    323
Loading...

Share This Page