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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting panel to visible

Status
Not open for further replies.

rac55

Programmer
Jul 1, 2003
62
AU
Hi

I am trying to refernce an invisble panel and a %# DataBinder.Eval(Container.DataItem, "Department") %> is equal to a specific department then display the panel.

the code is ;

<panel id="pnlName" visible="false" runat="server">
<td bgcolor="#B5C7DE">
<b>Ticket No:</b></td>
<td bgcolor="#E4E4E4" width="100">
<%# DataBinder.Eval(Container.DataItem, "TicketNo") %>
</td>
</panel>

The dataset is called rsAction

dim pnlName as Panel

If rsAction.items is "Maintenance" then
pnlName.Visible = true
end if

Any help with the if statement would really be appreciated

Thanks
 
I think you will have to drill down into your dataset a little.
rsAction.Tables("index or name").Rows(index).Item("index or name")
Marty
 
Where is the code called from?

Do you have a textbox or label that the "Maintenance" is supposed to be in or are your reading from a dataset? I don't think you are reading from the dataset properly with the rsAction.Items - this shouldn't come up with one records field value.

Hope everyone is having a great day!

Thanks - Jennifer
 
Thanks for your reply

Its actually in a panel within a datalist, so rsAction.Tables("index or name").Rows(index).Item("index or name").

I need to pull whatever department the datalist is displaying. If the department is equal to maintenance then set the panel to visible.

Any more ideas?

thanks
Rachel
 
So are you doing this on the databind method for the datalist?

Hope everyone is having a great day!

Thanks - Jennifer
 
I would try it in the databind method.

Code:
    Private Sub dg_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dg.ItemDataBound

        If e.Item.ItemType <> ListItemType.Header And e.Item.ItemType <> ListItemType.Footer Then
            Dim strDept As String = e.Item.Cells(5).Text
            If strDept = "Maintenance" Then
                e.Item.BackColor = Color.Red
                'Replace with the visible code
            Else
                e.Item.BackColor = Color.Gold
                'Replace with the not visible code
            End If
        End If
    End Sub

Hope this helps.

Hope everyone is having a great day!

Thanks - Jennifer
 
Hi

Thanks for your help but that code above is for a datagrid, and I have a datalist.

All I need to code is panel1.visible = true but its doesn't like it, it says its not declared and when I do declare it, another error occurs saying its not an instance of an object.

Does anyone have any ideas?

Thanks
Rachel
 
The DataList and DataGrid act very much the same. The only code that I have for the DataList is in C#.

Code:
public void dl_ItemDataBound(Object sender, System.Web.UI.WebControls.DataListItemEventArgs e) {
	if (e.Item.ItemType != ListItemType.Header & e.Item.ItemType != ListItemType.Footer) {
		DataGrid dg = (DataGrid)e.Item.Controls[3];

		string strItem = Convert.ToString(dl.DataKeys[e.Item.ItemIndex]);

		if (strItem == Convert.ToString(sb.getCurrent("Selected_IN",strUser))) {
			dg.Visible = true;
			try {				
			DataSet ds = new DataSet(); 
			ds = Getdg();
			if (ds.Tables[0].DefaultView.Count > 0){
			dg.DataSource = ds.Tables[0].DefaultView;
			dg.DataBind();				        }
			else {
			DoOption(Convert.ToInt32(strItem));
			}
		}
		catch (Exception ex) {
			string strErr;
			strErr = syslblError.Text + " A problem was found with the Item Data Bound Event. Please try again.";
			syslblError.Text = strErr.Trim();
			syslblErrorMessage.Text = ex.Message;
		}
	}
	else {
	dg.Visible = false;
	dg.DataSource = null;
	dg.DataBind();
	}
}
}

Hope this helps.

Hope everyone is having a great day!

Thanks - Jennifer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top