Conditionally displaying elements of a repeater control

  • Thread starter Thread starter Imran Aziz
  • Start date Start date
I

Imran Aziz

Hello all,

I am populating the contents of a repeater control using a database query.
In the repeater control I have a link , which I want to display or not based
on the current logged in user. I have a asp:panel surrounding this link and
evaluate its value using the code below.

<asp:panel ID="Panel5" runat=server Visible='<%#
((DataBinder.Eval(Container.DataItem, "nUserID")).ToString() !=
ViewState["intLoginUserID"].ToString() ) %>' Wrap="false" >



I have the user id of the logged in user in session and compare it with the
userid from the database, if both are same I need to show the delete link
otherwise not. Now the issue is that I cannot seem to reference with Session
variables or ViewSate variables in the front end aspx page. So how can I can
do the comparison then ?

Thanks a lot for your help.

Imran.
 
Try use the OnItemDataBound event in the repeater.

That way you can check the session

private void Repeater1_ItemDataBound(object sender,
System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
if(e.Item.ItemType != ListItemType.Header && e.Item.ItemType !=
ListItemType.Footer) //check its not the header or footer
{
string WotEver = (string)Session["MySession"];
}
}

HTH
 
Hi,

Try to comparasion on repeaters ItemDataBound Event instead of aspx page
becoz when you bind the repeater with datasource its ItemDataBound Event get
fired and and you will get the control of both session and your database
value as well.

Regards,
Sachin Saki
..NET Developer - Capgemini, INDIA

"Imran Aziz" ने लिखा:
 
Imran,

Try

<asp:panel ID="Panel5" runat=server Visible='<%# IsLogged
(DataBinder.Eval(Container.DataItem, "nUserID")) %>' Wrap="false" >

and in the code

protected bool IsLogged (string id)
{ return id == ViewState["intLoginUserID"].ToString();}

Eliyahu
 
Ok understood, thanks a lot for the tip :)
Imran.

Eliyahu Goldin said:
Imran,

Try

<asp:panel ID="Panel5" runat=server Visible='<%# IsLogged
(DataBinder.Eval(Container.DataItem, "nUserID")) %>' Wrap="false" >

and in the code

protected bool IsLogged (string id)
{ return id == ViewState["intLoginUserID"].ToString();}

Eliyahu

Imran Aziz said:
Hello all,

I am populating the contents of a repeater control using a database
query.
In the repeater control I have a link , which I want to display or not based
on the current logged in user. I have a asp:panel surrounding this link and
evaluate its value using the code below.

<asp:panel ID="Panel5" runat=server Visible='<%#
((DataBinder.Eval(Container.DataItem, "nUserID")).ToString() !=
ViewState["intLoginUserID"].ToString() ) %>' Wrap="false" >



I have the user id of the logged in user in session and compare it with the
userid from the database, if both are same I need to show the delete link
otherwise not. Now the issue is that I cannot seem to reference with Session
variables or ViewSate variables in the front end aspx page. So how can I can
do the comparison then ?

Thanks a lot for your help.

Imran.
 
Ah yes its best to check it in the event for the Repeater, thanks a lot for
pointing that out.
Imran.

Grant Merwitz said:
Try use the OnItemDataBound event in the repeater.

That way you can check the session

private void Repeater1_ItemDataBound(object sender,
System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
if(e.Item.ItemType != ListItemType.Header && e.Item.ItemType !=
ListItemType.Footer) //check its not the header or footer
{
string WotEver = (string)Session["MySession"];
}
}

HTH

Imran Aziz said:
Hello all,

I am populating the contents of a repeater control using a database
query. In the repeater control I have a link , which I want to display or
not based on the current logged in user. I have a asp:panel surrounding
this link and evaluate its value using the code below.

<asp:panel ID="Panel5" runat=server Visible='<%#
((DataBinder.Eval(Container.DataItem, "nUserID")).ToString() !=
ViewState["intLoginUserID"].ToString() ) %>' Wrap="false" >



I have the user id of the logged in user in session and compare it with
the userid from the database, if both are same I need to show the delete
link otherwise not. Now the issue is that I cannot seem to reference with
Session variables or ViewSate variables in the front end aspx page. So
how can I can do the comparison then ?

Thanks a lot for your help.

Imran.
 

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

Back
Top