**the tables contains set of links that my website contains** ... i want to show some of these links while restrict access to other links dependng on the user role Id for this i use stored proc: GetAllowedLinksForUserRole which return only allowed links correctly ( as i saw it using BreakPoints) ... i m using same databound event for all repeaters
here is the item data bound event
protected void rpt_Config_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item)
{
HtmlAnchor li = (e.Item.FindControl("lnk")) as HtmlAnchor;
if (!CheckLink(int.Parse(DataBinder.Eval(e.Item.DataItem, "LnkId").ToString())))
{
li.HRef = "";
}
}
}
**but with the above code it is giving access to those links also which are not in list "AllowedLinks"** can some one please help me with this problem???
**Please note: all the stored procedures and other stuff is working correctly ... its just thecod with in ~~*"rpt_Config_ItemDataBound"*~~ thats causing problem*
it is being accessed because it is a class attribute ... and plus i have seen values using breakpoints .. the list AllowedLinks do contain what it should throughout. ..
Have you tried using the debugger and inspecting all variables to see what happens?
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
sana_sz91
Member
3 Points
22 Posts
Item Data Bound Event in repeaters ???
Aug 17, 2012 10:03 PM|LINK
i m binding 4 diff tables to 4 diff. repeaters in following manner:
protected void Page_Load(object sender, EventArgs e) { #region attributes DAL DataObj; DataSet ds; DataTable dt; List<int> AllowedLinks = new List<int>(); #endregion DataObj = new DAL(); dt = DataObj.GetDataTable("GetAllowedLinksForUserRole",2); foreach (DataRow myRow in dt.Rows) { AllowedLinks.Add(Convert.ToInt32(myRow["LnkId"])); } if (!IsPostBack) { DataObj = new DAL(); ds = DataObj.GetDataSet("GetLinksName"); rpt_Config.DataSource = ds.Tables[0]; rpt_Config.DataBind(); rpt_Employee.DataSource = ds.Tables[1]; rpt_Employee.DataBind(); rpt_Attendance.DataSource = ds.Tables[2]; rpt_Attendance.DataBind(); rpt_Report.DataSource = ds.Tables[3]; rpt_Report.DataBind(); } }**the tables contains set of links that my website contains** ... i want to show some of these links while restrict access to other links dependng on the user role Id for this i use stored proc: GetAllowedLinksForUserRole which return only allowed links correctly ( as i saw it using BreakPoints) ... i m using same databound event for all repeaters
here is the item data bound event
protected void rpt_Config_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item) { HtmlAnchor li = (e.Item.FindControl("lnk")) as HtmlAnchor; if (!CheckLink(int.Parse(DataBinder.Eval(e.Item.DataItem, "LnkId").ToString()))) { li.HRef = ""; } } }**the method "CHECKLINK" code":**
#region methods private bool CheckLink(int linkID) { return AllowedLinks.Contains(linkID); } #endregion**but with the above code it is giving access to those links also which are not in list "AllowedLinks"** can some one please help me with this problem???
**Please note: all the stored procedures and other stuff is working correctly ... its just thecod with in ~~*"rpt_Config_ItemDataBound"*~~ thats causing problem*
C-sharp eventargs asp itemdatabound Repeater
oned_gk
All-Star
31247 Points
6384 Posts
Re: Item Data Bound Event in repeaters ???
Aug 17, 2012 11:31 PM|LINK
Prashant Kum...
Star
12334 Points
1992 Posts
Re: Item Data Bound Event in repeaters ???
Aug 17, 2012 11:39 PM|LINK
How is AllowedLinks accessible in the method CheckLink since it is declared in Page_Load?
Is there another declaration/initialialization of AllowedLinks?
sana_sz91
Member
3 Points
22 Posts
Re: Item Data Bound Event in repeaters ???
Aug 18, 2012 01:38 AM|LINK
it is being accessed because it is a class attribute ... and plus i have seen values using breakpoints .. the list AllowedLinks do contain what it should throughout. ..
sowhat will u say now? :)
sana_sz91
Member
3 Points
22 Posts
Re: Item Data Bound Event in repeaters ???
Aug 18, 2012 01:46 AM|LINK
can u please tell how and where wil i use it??
superguppie
All-Star
48225 Points
8679 Posts
Re: Item Data Bound Event in repeaters ???
Aug 20, 2012 07:36 AM|LINK
Have you tried using the debugger and inspecting all variables to see what happens?
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
Qin Dian Tan...
All-Star
113532 Points
12480 Posts
Microsoft
Re: Item Data Bound Event in repeaters ???
Aug 20, 2012 07:47 AM|LINK
Hi,
1) Add this to item type checking:
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
2) Use HyperLink instead of anchor, then access it by HyperLink.
3) set the Enabled property of HyperLink to control clickable or not.
Thanks,
If you have any feedback about my replies, please contactmsdnmg@microsoft.com.
Microsoft One Code Framework
sana_sz91
Member
3 Points
22 Posts
Re: Item Data Bound Event in repeaters ???
Aug 20, 2012 10:34 AM|LINK
Yes i did .. all variables or objects , lists do contains what they should ...
sana_sz91
Member
3 Points
22 Posts
Re: Item Data Bound Event in repeaters ???
Aug 20, 2012 10:39 AM|LINK
@Qin Dian Tang:
Thanksss a million problem solved ... i m getting what i want ... :) ..