Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to display or not display a table row based on an ObjectDataSource

Status
Not open for further replies.

PushCode

Programmer
Dec 17, 2003
573
US
I'm using an ObjectDataSource to populate a DropDownList. What I want to do is only display the table row that contains this DropDownList if the ObjectDataSource returns results. If it doesn't return any records to populate the DropDownList, I don't want to display the table row.

So I have wrapped the table row in a div tag, then figured I could use the Visible property to toggle its display.

Here's what I have so far:
Code:
<asp:ObjectDataSource ID="SuppliersDS" runat="server" 
    SelectMethod="GetSuppliersByUserLogin" TypeName="DataAccess.APSupplierInvoiceSystem">
    <SelectParameters>
        <asp:SessionParameter Name="UserLogin" SessionField="USER_NAME" Type="String" />
    </SelectParameters>
</asp:ObjectDataSource>
<table cellpadding="5" border="0" width="100%">
    <div runat="server" id="supplierDD">
    <tr>
        <td width="15%">Supplier:</td>
        <td width="85%"><asp:DropDownList ID="ddlSupplier" runat="server" 
                    DataTextField="vendor_name" 
                    DataValueField="vendor_id" CausesValidation="true"
                    DataSourceID="SuppliersDS" >
                </asp:DropDownList></td>    
    </tr>
    </div>
...
Then in the codebehind I figure I need an if statement...
Code:
if ()
            {
                this.supplierDD.Visible = true;
            }
            else
            {
                this.supplierDD.Visible = false;
            }
I'm just not sure how to reference the ObjectDataSource, or if that's even what I need to reference to make this work.

Any help would be much appreciated. Thanks!
 
Okay, I have figured it out and thought I'd go ahead and post the solution. I added the following code to the Page_Load event. If anyone has a better solution, I'd love to see it.
Code:
string userLogin = Session["USER_NAME"].ToString();
DataSet suppLkpDS = APSupplierInvoiceSystem.GetSuppliersByUserLogin(userLogin);
if (suppLkpDS.Tables[0].Rows.Count > 0)
{
    this.supplierDD.Visible = true;
}
else
{
    this.supplierDD.Visible = false;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top