简体   繁体   中英

How to keep styling on ListView Tableheader Link (after programmatically setting value)

I would like to change the text on a particular table header in a Layout Template in a ListView programmatically (depending on the value in the database). It works but the styling is no longer using the LinkButton styling(green and clickable). Instead it's black and bold (not clickable)

I used the following ( Access "th" in Listview ):

My c#:

HtmlTableCell thCustCol = lstAuthorizations.FindControl("customColumn") as HtmlTableCell;
thCustCol.InnerText = query.Select(x => x.Custom1).First().ToString();

I also tried applying FindControl to "LinkButton10" instead, but then it had an (null reference)exception.

My aspx:

<LayoutTemplate>
    <div class="table-responsive">
        <table class="table">
            <thead>
                <tr>
                      <th runat="server" id="customColumn"><asp:LinkButton id="LinkButton10" runat="server" CommandArgument="Custom1" CommandName="Sort">Group ID</asp:LinkButton></th>

It looks like this:

表头

The "1000" is a tableheader, but should be a green LinkButton like "Member Name"

What am I missing?

Instead of setting the value to the ID of the LinkButton, I needed to associate the LinkButton to the th in the c# code and then set the value:

LinkButton lk = thCustCol.FindControl("LinkButton1") as LinkButton;
lk.Text = "link text";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM