Howdy,
I didn't quite get what you wanted to do with hyperlink and description, but
please find the resolution below (it's just a guess, if you could be more
specific please). Your compiler error is caused by the SetStatus function, as
it does not always return a value, i.e.
string GetStatusImage(string status)
{
if (status == "0")
return "~/img/Pending.gif"
else if (status == "1")
return "~/img/Processing.gif";
else if (status == "2")
return "~/img/Complete.gif";
}
as you can see, function takes care of just two values "0" and "1", and if
you passed any other string (i.e. "2" or even "longtext") the result would be
unknown, which is not acceptable. Therefore in order to take care of all
other statuses, it needs to be changed to:
string GetStatusImage(string status)
{
if (result == "0")
return "~/img/pending.gif"
else if (result == "1")
return "~/img/processing.gif";
else
return "~/img/complete.gif";
}
In this particular case you have only three possible integere values, so it
would be better to define enumeration:
public enum TaskStatus
{
Pending = 0,
Processing = 1,
Complete = 2
}
<asp

ataList runat="server" ID="list" RepeatLayout="Table"
RepeatDirection="Vertical">
<ItemTemplate>
<asp:HyperLink runat="server" ID="link" BorderWidth="0"
ToolTip='<%# Eval("Description") %>'
NavigateUrl="#" ImageUrl='<%#
GetStatusImage((TaskStatus)Eval("Status")) %>' />
</ItemTemplate>
</asp

ataList>
protected string GetStatusImage(TaskStatus status)
{
switch (status)
{
case TaskStatus.Pending: return "~/img/pending.gif";
case TaskStatus.Processing: return "~/img/processing.gif";
default: return "~/img/complete.gif"; // covers all other
enumeration values
}
}
Hope this helps.
--
Milosz
"gh" wrote:
> I am using VS 2008. There datalist hase a filed, STATUS, that is 0, 1,
> or 2. Depending on the value I want to set the Image source. I also
> have a field with a description that I would like to concantenate to the
> image, as the hyperlink or use a hyperlink filed for everything Below
> is what I have for a function in the code behind:
>
> protected string SetStatus(string aStatus)
> {
> if (aStatus == "0")
> {
> return "<img src = \"../images/image1.gif\" />";
> }
> else
> if (aStatus == "0")
> {
> return "<img src = \"../images/image2.gif\" />";
> }
>
> }
>
> In the aspx file below is the template markup.
>
> <asp
ataList ID="DataList1" runat="server" RepeatColumns="3"
> RepeatDirection="Horizontal" DataSourceID="SqlDataSource1"
> onitemdatabound="DataList1_ItemDataBound">
> <ItemTemplate>
> <br />
> STATUS:
> <asp:Label ID="STATUSLabel" runat="server" Text='
> <%# SetStstus(Convert.ToString(DataBinder.Eval(Contain er.DataItem,
> "STATUS")))%>' />
> <br />
> <br />
> </ItemTemplate>
> </asp
ataList>
>
>
> 1. Can I add the markup to use an image and hyperlink for the cell?
> 2. When I try to view the page now I get the following error:
>
> Compiler Error Message: CS0161: '_Default.SetStatus(string)': not
> all code paths return a value
>
>
> Line 98: }
> Line 99:
> Line 100: protected string SetStatus(string aStatus)
> Line 101: {
> Line 102: /* if (aStatus == "0")
>
> The Status is stored as and integer but I am using a Convert.ToString in
> the SetStatus call.
>
> Waht would be the cause of the error?
>
> TIA
>