Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TemplateField helper function passes variable name not value

Status
Not open for further replies.

dzr

Programmer
Nov 20, 2001
109
0
0
US
I have the field user_is_active in a table - 1 = active, 0 = inactive.

I have a GridView set up and I want it to display text "active/inactive" instead of 1/0. Easy right?

It seems to be passing the variable name "user_is_active" instead of the value 1 or 0 so all records are showing "inactive" in the status column.
------------------------------------
my Template field:

<asp:Label ID="lbl_getstatus" runat="server" Text='<%# GetStatus("user_is_active")%>'></asp:Label>

---
my C# Codebehind
protected string GetStatus(string program_status)
{
if (program_status == "1")
{
return "active";
}
else
{
return "inactive";
}
}
------------------------------------

I know it's passing the variable name since I put:
return program_status + "inactive";
for the if/else and got "user_is_activeinactive" in the status column.
I tried variations of "Container.DataItem" which I saw in so many examples but got errors.

Can anyone see what I'm doing wrong here??
 
dzr: Just a shot in the dark. Using a helper function in one of my pages; which is VB so may not be related, or even helpful here) I have the following:

Text='<%# GetStatus("user_is_active")%>'

..which shows up in the Helper function as:

Function GetStatus (user_is_active As Object)

..just a thought dzr; I don't write in C# so might not have any application here - but did think it might be worth mentioning.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top