Question using if() { } else {} in Repeater
-
I have a repeater control which displays project information. I would like to check the security to ensure that the given user has access to the project he is trying to view. SO i'm tying to do so like this...
<%# if(checkSubscribersRegions(Session["uid"].ToString(), DataBinder.Eval(Container.DataItem, "aut_projectID").ToString()) == "1") { %> display this stuff <% } else { %> display error <% } %>
Here is the error i receive:Compiler Error Message: CS1513: } expected
Can anyone help me out with this? Sincere Thanks, Brian
-
I have a repeater control which displays project information. I would like to check the security to ensure that the given user has access to the project he is trying to view. SO i'm tying to do so like this...
<%# if(checkSubscribersRegions(Session["uid"].ToString(), DataBinder.Eval(Container.DataItem, "aut_projectID").ToString()) == "1") { %> display this stuff <% } else { %> display error <% } %>
Here is the error i receive:Compiler Error Message: CS1513: } expected
Can anyone help me out with this? Sincere Thanks, Brian
This is a patently bad idea. You should handle this in your code behind, and have your repeater just call a function. Inline code is one of the things that ASP.NET allows us to do away with. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
This is a patently bad idea. You should handle this in your code behind, and have your repeater just call a function. Inline code is one of the things that ASP.NET allows us to do away with. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
Thanks for the advice... My repeater is dealing with alot of data. Can you give me an example of your idea? (how you mean to implement this). Brian
<%# getMyStuff(Container.DataItem) %> In code behind
public function getMyStuff( obj as object) as string { //get the data from the object, ie myString = obj.item("aut_projectID").ToString() if(checkSubscribersRegions(Session["uid"].ToString(), MyString) == "1") { return "display this stuff" } else { return "display error" } }
-
<%# getMyStuff(Container.DataItem) %> In code behind
public function getMyStuff( obj as object) as string { //get the data from the object, ie myString = obj.item("aut_projectID").ToString() if(checkSubscribersRegions(Session["uid"].ToString(), MyString) == "1") { return "display this stuff" } else { return "display error" } }
Marcus_2 wrote: myString = obj.item("aut_projectID").ToString() Does this work in VB ? In C#, I'd need to cast the object to something useful before I could do anything like this. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
Thanks for the advice... My repeater is dealing with alot of data. Can you give me an example of your idea? (how you mean to implement this). Brian
The aspx needs to be like the other guy said, but in C#, the code would look like this: System.Data.DataRowView oDataRowView = (System.Data.DataRowView) oDataGridItem; string item = oDataRowView.Row["ColumnName"].ToString(); etc. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
Marcus_2 wrote: myString = obj.item("aut_projectID").ToString() Does this work in VB ? In C#, I'd need to cast the object to something useful before I could do anything like this. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
No actually it doesn't. You have to declare MyString somewhere (ie "dim myString as string = obj.item("aut_projectID").ToString()") and the function I wrote is a mess with both C# and VB code. I'm currently working in VB.NET so my head was there right then, and when I try to write this small snippets it's not actual code that will work, but more the general idea that has to be shown. Therefore MyString wasn't decalread and MyString isn't a name for a variable that I would use.