User-1174608757 posted
Hi understandcsharp:
According to your description, I have made the sample here. HtmlTableCell thCustCol = ListView1.FindControl("customColumn") as HtmlTableCell will get the cell which contains the linkbutton you want to keep styling.The code thCustCol.InnerText = query.Select(x
=> x.Custom1).First().ToString() will change the contents of the cell to a text which means the linkbutton would be deleted.I guess what you want is to change the text of linkbotton,but the code you post would delete linkbutton and add a text.Here is my
code.I hope it will hep you.
LinkButton.aspx:
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListView ID="ListView1" runat="server">
<LayoutTemplate>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th runat="server" id="customColumn">
<asp:LinkButton id="LinkButton1" runat="server" CommandArgument="Custom1" CommandName="Sort">Group ID</asp:LinkButton>
</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</thead>
</table>
</div>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr runat="server">
<td>
<asp:Label ID="FirstNameLabel" runat="Server" Text='<%#Eval("id") %>' />
</td>
<td>
<asp:Label ID="LastNameLabel" runat="Server" Text='<%#Eval("username") %>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
</div>
</form>
</body>
LinkButton.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string sql = "select * from db";
this.ListView1.DataSource = SqlHelper.ExecuteDataTable(sql);
ListView1.DataBind();
HtmlTableCell thCustCol = ListView1.FindControl("customColumn") as HtmlTableCell;
LinkButton lk = thCustCol.FindControl("LinkButton1") as LinkButton;
lk.Text = "link text";
}
}

Best Regards
Wei Zhang