Link to home
Start Free TrialLog in
Avatar of Daves166
Daves166Flag for United States of America

asked on

databinder.eval question

I need to evaluate a field then send that data to a function to evaluate once more so I can display a name.  Here is what happens, I run a databinder.eval(Container.Dataitem, "BrnId") to get the branch ( it should yield 001, 002 005, etc).  Then I want to call my function GetBranch which uses a switch statement to give me the branch name.  However, I don't know how to position my inline ASP.Net tags so that it evaluates first, then calls my function second.  attached is my code.
<Script Runat="Server" type="text/C#">
	public string GetBranch(string BranchId)
	{
		string Branch = "";
		switch(BranchId)
		{
			case "001":
				Branch = "Columbus";
			break;
			case "002":
				Branch = "Youngstown";
			break;
			case "005":
				Branch = "Pittsburgh";
			break;
			case "006":
				Branch = "Barkeyville";
			break;
			case "007":
				Branch = "Cincinnati";
			break;
			Default:	
				Branch = "Columbus";
			break;
		}
		return Branch;
	}
</Script>
  				
...........

		<ItemTemplate>
		        <table width="946" border="0" cellspacing="0" cellpadding="0" bgcolor="FFFFFF"> 
		        <tr> 
			        <td width="160" height="40" align="left" valign="top" class="resultsbold">Unit: <%# DataBinder.Eval(Container.DataItem, "UntId") %></td> 
				<td width="786" height="40" align="left" valign="top" class="resultsbold">Location:  <%# DataBinder.Eval(Container.DataItem, "BrnId") %> </td>
		        </tr> 

Open in new window

Avatar of cslimrun
cslimrun

try this:
<td width="786" height="40" align="left" valign="top" class="resultsbold">Location:  <%# GetBranch(DataBinder.Eval(Container.DataItem, "BrnId")) %> </td>

Open in new window

Avatar of Daves166

ASKER

When I do that I get the following error message:
CS1502: The best overloaded method match for 'ASP:Search_New_Trucks_aspx.GetBranch(String)' has some invalid arguments.
I tried the following also:
<% string myBranch; myBranch=databinder.eval(Container.dataitem, "BrnId"); GetBranch(myBranch) %>

Still got an error.
<td width="786" height="40" align="left" valign="top" class="resultsbold">Location:  <%# GetBranch(DataBinder.Eval(Container.DataItem, "BrnId").ToString()) %> </td>
Same Error as above.  It doesn't seem like it's excuting "databinder.eval" first then calling my function.  I need it to evaluate the (DataBinder.Eval(Container.DataItem, "BrnId") first then let me call my function.
ASKER CERTIFIED SOLUTION
Avatar of gopaltayde
gopaltayde
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial