richardsimnett
asked on
how to use iff with a DataBinder.Eval
hi experts,
hope you're all having as much fun as I am coding today :D
(man do i hate web coding)
anyway, i am trying to force a checkbox to be checked or not inside a Repeater control with the following statement:
<%# iif(DataBinder.Eval(Contai ner.DataIt em,"pickTe amID")=Dat aBinder.Ev al(Contain er.DataIte m,"teamID1 "),"checke d","") %>
this statemtent is sitting inside of an <input ...> tag and i am seeing an error that says:
Compiler Error Message: CS0131: The left-hand side of an assignment must be a variable, property or indexer
does it mean i need an == instead of =
or does it mean that its not possible to have it check against another column in the dataSet and that I should instead have the sproc return a computed value like 1 or 0 that i can check against like this:
<%# iif(DataBinder.Eval(Contai ner.DataIt em,"pickTe amID")=1," checked"," ") %>
and if I am not even close feel free to point out I am an idiot and show me the way.
thanks.
hope you're all having as much fun as I am coding today :D
(man do i hate web coding)
anyway, i am trying to force a checkbox to be checked or not inside a Repeater control with the following statement:
<%# iif(DataBinder.Eval(Contai
this statemtent is sitting inside of an <input ...> tag and i am seeing an error that says:
Compiler Error Message: CS0131: The left-hand side of an assignment must be a variable, property or indexer
does it mean i need an == instead of =
or does it mean that its not possible to have it check against another column in the dataSet and that I should instead have the sproc return a computed value like 1 or 0 that i can check against like this:
<%# iif(DataBinder.Eval(Contai
and if I am not even close feel free to point out I am an idiot and show me the way.
thanks.
richardsimnett,
Are you coding in C#?
-- Jason
Are you coding in C#?
-- Jason
richardsimnett,
IIf is a VB function, C# would be (I think this should work fine):
(DataBinder.Eval(Container .DataItem, "pickTeamID") == DataBinder.Eval(Container. DataItem, "teamID1")) ? "checked" : "";
-- Jason
IIf is a VB function, C# would be (I think this should work fine):
(DataBinder.Eval(Container
-- Jason
ASKER
yes i am using C#. let me try what you suggested
richardsimnett,
Of course, while I'm at it, I'd recommend a <asp:CheckBox> control instead of <input>. Maybe something like:
<asp:CheckBox runat="server" id="cbTeam" Checked='<%# (DataRowView)Container.Dat aItem["pic kTeamID"] == (DataRowView)Container.Dat aItem["tea mID1"] %>' />
I'm primarly a VB.NET programmer, so I'm kind of taking stabs at the C# syntax -- I believe it's mighty close, but might need some tweaking.
-- Jason
Of course, while I'm at it, I'd recommend a <asp:CheckBox> control instead of <input>. Maybe something like:
<asp:CheckBox runat="server" id="cbTeam" Checked='<%# (DataRowView)Container.Dat
I'm primarly a VB.NET programmer, so I'm kind of taking stabs at the C# syntax -- I believe it's mighty close, but might need some tweaking.
-- Jason
ASKER
still getting an error about missing a )
here's the whole line of my code. just in case i am missing something else
<td><input type=checkbox name=team_<%# DataBinder.Eval(Container. DataItem, "teamID1") %> id=team_<%# DataBinder.Eval(Container. DataItem, "teamID1") %> <%# (DataBinder.Eval(Container .DataItem, "pickTeamID") == DataBinder.Eval(Container. DataItem, "teamID1")) ? "checked" : ""; %>>
here's the whole line of my code. just in case i am missing something else
<td><input type=checkbox name=team_<%# DataBinder.Eval(Container.
richardsimnett,
Whew, a syntax test, great! I'll play, here's my try at it:
<input type='checkbox' name='<%# "team_" + DataBinder.Eval(Container. DataItem, "teamID1") %>' id='<%# "team_" + DataBinder.Eval(Container. DataItem, "teamID1") %>' <%# ((DataBinder.Eval(Containe r.DataItem , "pickTeamID") == DataBinder.Eval(Container. DataItem, "teamID1")) ? "checked" : "") %> />
-- Jason
Whew, a syntax test, great! I'll play, here's my try at it:
<input type='checkbox' name='<%# "team_" + DataBinder.Eval(Container.
-- Jason
ASKER
thanks for being such a good sport. and you are about 99% of the way there.
only one problem remains for me. the == is returning false even when both sides of it have the same value. is there a way to type cast it so it works?
for instance, can i use a Convert.ToInt32() wrapped around those DataBinder.Eval statements?
actually i just tried that and it gave me more compilation errors.
maybe a straight cast:
<%# ((int)(DataBinder.Eval(Con tainer.Dat aItem, "pickTeamID") == (int)DataBinder.Eval(Conta iner.DataI tem, "teamID1")) ? "checked" : "") %>
nope. adding the (int) doesnt work either.
any more ideas?
only one problem remains for me. the == is returning false even when both sides of it have the same value. is there a way to type cast it so it works?
for instance, can i use a Convert.ToInt32() wrapped around those DataBinder.Eval statements?
actually i just tried that and it gave me more compilation errors.
maybe a straight cast:
<%# ((int)(DataBinder.Eval(Con
nope. adding the (int) doesnt work either.
any more ideas?
ASKER
actually i had the (int) in the wrong place there, but it still didnt work when i fixed it to this:
<%# (((int)(DataBinder.Eval(Co ntainer.Da taItem, "pickTeamID")) == (int)(DataBinder.Eval(Cont ainer.Data Item, "teamID2"))) ? "checked" : "") %> />
<%# (((int)(DataBinder.Eval(Co
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i added another databinder.eval to print the values out and they are indeed equal.
i tried it like this and the C# compiler didnt like it (i assume had i done int's it would have also crapped its pants)
public string CheckTeams(string pickTeam, string teamID)
so i changed it to objects and added the Convert and it ran perfectly. i didnt even know you could call functions like that in your code behind class.
you helped me big time today, jason. i wish i could give you more than 500 points. you earned it.
thanks.
public string CheckTeams(object pickTeam, object teamID)
{
if (Convert.ToInt32(pickTeam) == Convert.ToInt32(teamID))
{
return "checked";
}
else
{
return "";
}
}
i tried it like this and the C# compiler didnt like it (i assume had i done int's it would have also crapped its pants)
public string CheckTeams(string pickTeam, string teamID)
so i changed it to objects and added the Convert and it ran perfectly. i didnt even know you could call functions like that in your code behind class.
you helped me big time today, jason. i wish i could give you more than 500 points. you earned it.
thanks.
public string CheckTeams(object pickTeam, object teamID)
{
if (Convert.ToInt32(pickTeam)
{
return "checked";
}
else
{
return "";
}
}
Nice work, glad you got it going! See you around.
-- Jason
-- Jason
ASKER
both pickTeamID and teamID1 are tinyint's in the db. i dont know if that matters or what