Here is the html code for the page :
<ul class="list quicker">
<li><asp:LinkButton runat="server" ID="education_news" OnClick="education_news_Click" >Education</asp:LinkButton></li>
<li><asp:LinkButton runat="server" ID="immigration_news" OnClick="immigration_news_Click">Immigration</asp:LinkButton></li>
<li><asp:LinkButton runat="server" ID="visa_news" OnClick="visa_news_Click" >Visa</asp:LinkButton></li>
</ul>
Here is the code behind the page i've used:
protected void education_news_Click(object sender, EventArgs e)
{
string edu = education_news.Text;
using (SqlConnection _con = new SqlConnection(_Data.CS))
{
SqlCommand _Cmd = new SqlCommand("select * from tbl_brochures where type=@type", _con);
_Cmd.Parameters.AddWithValue("@type", edu);
_con.Open();
dl_brochures.DataSource = _Cmd.ExecuteReader();
dl_brochures.DataBind();
}
}
I have to do when i click on any link button the parent li of that link button should change or add the class to li(this). I have also query but got no solution.
答案 0 :(得分:2)
您需要在aspx中添加runat="server"
li
:
<ul class="list quicker">
<li runat="server"><asp:LinkButton runat="server" ID="education_news" OnClick="education_news_Click" >Education</asp:LinkButton></li>
<li runat="server"><asp:LinkButton runat="server" ID="immigration_news" OnClick="immigration_news_Click">Immigration</asp:LinkButton></li>
<li runat="server"><asp:LinkButton runat="server" ID="visa_news" OnClick="visa_news_Click" >Visa</asp:LinkButton></li>
</ul>
并在代码隐藏中添加这样的类:
protected void education_news_Click(object sender, EventArgs e)
{
((HtmlGenericControl) education_news.Parent).Attributes["class"] = "some-class";
}