Conditional Values in DataList

Discussion in 'ASP General' started by Wayne Wengert, Apr 7, 2004.

  1. I am trying to build a project in VSNET 2003 using a sql datareader and
    a datalist. I want to have one column display either a hyperlink or a
    simple test string based on the values in one of the data fields. I have
    tried many combinations of code but cannot get it to work. My current
    code is listed below. From searching google I believe thast the
    DataRowView type works only with a datagrid. Any suggestions are
    appreciated

    ============= code snippets ============
    Public Function SetValue(ByVal data As DataRowView) As String
    Dim strResult As String
    If data("ProposedStatus") Is DBNull.Value Then
    strResult = String.Format( _

    "http://wengert.org/evaljudge.asp?name={0}&caption={1}&evalid={2}", _
    data("JudgeName"), data("Caption"), data("EvalID"))
    Else
    strResult = ""
    End If
    Return strResult
    End Function

    .......

    <asp:DataList id="judgelist" runat="server">
    <HeaderTemplate>
    <table width="90%">
    <tr bgcolor="#b0c4de">
    <th>
    Action</th>
    <th>
    Judge</th>
    <th>
    Caption</th>
    <th align="center">
    Current<br />
    Status</th>
    <th align="center">
    Proposed<br />
    Status</th>
    <tr>
    </HeaderTemplate>
    <ItemTemplate>
    <tr bgcolor="lightcyan">
    <td id="myLink" runat="server">
    SetValue()
    </td>


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Wayne Wengert, Apr 7, 2004
    #1
    1. Advertising

  2. Wayne Wengert wrote:
    > I am trying to build a project in VSNET 2003 using a sql datareader
    > and a datalist. I want to have one column display either a hyperlink
    > or a simple test string based on the values in one of the data
    > fields. I have tried many combinations of code but cannot get it to
    > work. My current code is listed below. From searching google I
    > believe thast the DataRowView type works only with a datagrid. Any
    > suggestions are appreciated


    This is a classic asp newsgroup. While you may be lucky enough to find a
    dotnet-savvy person here who can answer your question, you can eliminate the
    luck factor by posting your question to an appropriate group. I suggest
    microsoft.public.dotnet.framework.aspnet. or
    microsoft.public.dotnet.framework.adonet.

    Bob Barrows

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
    Bob Barrows [MVP], Apr 7, 2004
    #2
    1. Advertising

  3. Wayne Wengert

    [MSFT] Guest

    Hi Wayne,

    For such a ASP.NET question, you had better send to

    microsoft.public.dotnet.framework.aspnet

    A short answer to the question isyou should use
    DataBinder.Eval(Container.DataItem, "FieldName") in the HTML code, for
    example:

    <ItemTemplate>
    <li>
    <asp:Label ID="lblSiteName" runat=server ForeColor=Blue
    text='<%# "http://"+ DataBinder.Eval(Container.DataItem, "Name")%>'>
    </asp:Label>
    </li>
    </ItemTemplate>

    If you need more detail information on this, I suggest you may send this
    question to

    microsoft.public.dotnet.framework.aspnet

    I can guarantee you will get answer there.

    Luke
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    [MSFT], Apr 8, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe

    conditional items in a datalist

    Joe, Dec 9, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    446
  2. Jerry Camel

    Conditional Colors in a DataList Control

    Jerry Camel, Feb 12, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    303
    =?Utf-8?B?U3VyZXNo?=
    Feb 12, 2004
  3. Nevyn Twyll
    Replies:
    8
    Views:
    1,833
  4. =?Utf-8?B?RWQgQ2hpdQ==?=

    Conditional item template for a datalist

    =?Utf-8?B?RWQgQ2hpdQ==?=, Jul 27, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    3,996
    Craig Deelsnyder
    Jul 27, 2005
  5. Alec S.
    Replies:
    10
    Views:
    10,061
    Alec S.
    Apr 16, 2005
Loading...

Share This Page