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

G

Guest

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

Guest

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);
}
 
G

Guest

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top