Board index » Web Programming » prevent DropDownList from displaying in GridView column if it's em

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

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


-
 

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

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

www.societopia.net">www.societopia.net

www.webswapp.com">www.webswapp.com





"Dabbler" wrote:



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

-

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



Wow Phillip, that was simple and worked on the first try! So many events, so

little time. Thanks much.



"Phillip Williams" wrote:



Quote
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

www.societopia.net">www.societopia.net

www.webswapp.com">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.

-