在表html css asp net中突出显示用户

时间:2017-01-17 11:58:54

标签: c# html css asp.net

我将此表放在转发器中,列出数据库中的所有联系人,如果用户点击特定联系人,该联系人应以蓝色背景颜色突出显示。我试过这段代码,但它不起作用......!

ASPX

<asp:Repeater runat="server" OnItemCommand="rptList_OnItemCommand" ID="rptList">
<HeaderTemplate>
    <table id="tblListContact">
        <tr id="tblRowContact">
            <th>
                <asp:Label runat="server" Text="TRNSLTName" />
            </th>
        </tr>
</HeaderTemplate>
<ItemTemplate>
    <%# ContactId.HasValue && ContactId == Convert.ToInt32(Eval("ID"))? "<tr style='background-color: #67C6FA;'>" : "<tr>" %> // Shouldn't this code make it work?
    <td>
        <asp:LinkButton runat="server" CommandName="selectContact" CommandArgument='<%# Eval("ID") %>'><%# Eval("Name") %></asp:LinkButton>
    </td>
</ItemTemplate>
<FooterTemplate>
    </table>
</FooterTemplate>
</asp:Repeater>

C#

public long? ContactId
{
    get
    {
        if (ViewState["ContactId"] == null)
        {
            return null;
        }

        return Convert.ToInt64(ViewState["ContactId"]);
    }

    set
    {
        ViewState["ContactId"] = value;
    }
}

/// <summary>
/// Assigning commands to repeater.
/// </summary>
protected void rptList_OnItemCommand(object source, RepeaterCommandEventArgs e)
{
    var contactId = Convert.ToInt64(e.CommandArgument);

    switch (e.CommandName)
    {
        case "selectContact":
            divRead.Visible = true;
            ContactId = contactId;
            var getContact = _ecSystem.GetContact(contactId);

            if (getContact != null)
            {
                lblName.Text = getContact.Name;
                lblPhone.Text = getContact.PhoneNumber;
                lblMobile.Text = getContact.Cellphone;
                lblAdress.Text = getContact.Street;
                lblNotes.Text = getContact.Notes;
                lblPage.Text = getContact.Homepage;
                lblEmail.Text = getContact.Email;

                imgPhone.Visible = !string.IsNullOrEmpty(lblPhone.Text);
                imgMobile.Visible = !string.IsNullOrEmpty(lblMobile.Text);
                imgAddress.Visible = !string.IsNullOrEmpty(lblAdress.Text);
                imgNotes.Visible = !string.IsNullOrEmpty(lblNotes.Text);
                imgPage.Visible = !string.IsNullOrEmpty(lblPage.Text);
                imgEmail.Visible = !string.IsNullOrEmpty(lblEmail.Text);
            }
            break;

        case "deleteContact":
            ContactId = contactId;
            break;

        case "noBtn":
            divRead.Visible = true;
            break;

        case "yesBtn":
            if (ContactId != null)
            {
                _ecSystem.DeleteContact(ContactId.Value);
            }
            ContactId = null;
            Response.Redirect("Contact.aspx");
            break;

        case "editContact":
            _editMode = true;
            divAdd.Visible = true;
            var contacts = _ecSystem.GetContact(contactId);
            ViewState["ContactID"] = contactId;
            ViewState["Contacts"] = contacts;
            break;
    }
}

/// <summary>
/// Sets datasource and databind to aspx page.
/// </summary>
public void RptDataBind()
{
    var userId = UserID;

    _ecSystem = new ExternalCatalog();

    var contacts = _ecSystem.GetContacts(userId);

    if (contacts != null && contacts.Length > 0)
    {
        rptList.DataSource = contacts;
    }

    if (!Page.IsPostBack)
    {
        rptList.DataBind();
    }
}

0 个答案:

没有答案