Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8707679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:55:47+00:00 2026-06-13T03:55:47+00:00

I have a listview control and in layout template, i have linkbuttons. Now what

  • 0

I have a listview control and in layout template, i have linkbuttons. Now what i want to do. i have a span with each linkbutton. i want to give css class while we click on linkbutton. my html code is as follow:

<asp:ListView ID="lst_CallType" runat="server" ItemPlaceholderID="tr" OnItemDataBound="lst_CallType_ItemDataBound">
                            <LayoutTemplate>
                                <table cellspacing="0">
                                    <tr class="hdrRowColor1">
                                        <td align="left" width="500px">
                                            <asp:LinkButton ID="lnk_Name" runat="server" ValidationGroup="vgSearch" OnClientClick="changeSortState();"
                                                CommandArgument="tblCallTypenew.CallType" OnClick="lnk_Sort">Name</asp:LinkButton>
                                            <span id="imgSortPosition" class="sortNotSelected"></span>
                                        </td>
                                        <td align="left" width="80px">
                                            <asp:LinkButton ID="lnk_Status" runat="server" CommandArgument="tblCallTypenew.isactive"
                                                ValidationGroup="vgSearch" OnClick="lnk_Sort">Status</asp:LinkButton>
                                                <span id="Span1" class="sortNotSelected"></span>
                                        </td>
                                        <td align="left" width="200px">
                                            <asp:LinkButton ID="lnk_CreatedOn" runat="server" CommandArgument="tblCallTypenew.CreatedDate"
                                                ValidationGroup="vgSearch" OnClick="lnk_Sort">Created On</asp:LinkButton>
                                                <span id="Span2" class="sortNotSelected"></span>
                                        </td>
                                        <td align="left" width="200px">
                                            <asp:LinkButton ID="lnk_LastModfiedOn" runat="server" CommandArgument="tblCallTypenew.ModifiedDate"
                                                ValidationGroup="vgSearch" OnClick="lnk_Sort">Last Modified On</asp:LinkButton>
                                                <span id="Span3" class="sortNotSelected"></span>
                                        </td>
                                        <td align="left" width="200px">
                                            <asp:LinkButton ID="lnk_CreatedBy" runat="server" CommandArgument="tblUserNew.FirstName"
                                                ValidationGroup="vgSearch" OnClick="lnk_Sort">Created By</asp:LinkButton>
                                                <span id="Span4" class="sortNotSelected"></span>
                                        </td>
                                        <td align="left" width="200px">
                                            <%--<asp:LinkButton ID="lnkCreatedDate" runat="server" CommandArgument="tblUserActivities.CreatedDate"
                                        OnClick="lnk_Sort">Created Date</asp:LinkButton>--%>
                                            <asp:LinkButton ID="lnk_LastModfiedBy" runat="server" CommandArgument="v.FirstName"
                                                ValidationGroup="vgSearch" OnClick="lnk_Sort">Modified By</asp:LinkButton>
                                                <span id="Span5" class="sortNotSelected"></span>
                                        </td>
                                        <td align="left" style="border-right: 1px solid #6398cc">
                                            Activity
                                            <div style="width: 50px; float: right;">
                                            </div>
                                        </td>
                                    </tr>
                                    <tr id="tr" runat="server">
                                    </tr>
                                </table>
                            </LayoutTemplate>
                            <ItemTemplate>
                                <tr class='<%# Convert.ToBoolean(Container.DataItemIndex % 2) ? "EvenRowColor" : "OddRowColor" %>'>
                                    <td align="left">
                                        <asp:Label ID="lblDeptId" runat="server" Text='<%# Eval("ID")%>' Visible="false"></asp:Label>
                                        <%# Eval("Calltype")%>
                                    </td>
                                    <td align="left">
                                        <asp:Label ID="lbl_Status" runat="server" Style="display: none;" Text='<%# Eval("IsActive")%>'></asp:Label>
                                        <asp:ImageButton ID="imgbtnStatus" runat="server" CommandArgument='<%# Eval("id") %>'
                                            OnClick="imgbtnStatus_Onclick" />
                                    </td>
                                    <td align="left">
                                        <%# Eval("CreatedDate")%>
                                    </td>
                                    <td align="left">
                                        <%# Eval("ModifiedDate") %>
                                    </td>
                                    <td align="left">
                                        <%# Eval("CreatedBy")%>
                                    </td>
                                    <td align="left">
                                        <%# Eval("ModifiedBy")%>
                                    </td>
                                    <td>
                                        <asp:Label ID="lblCallType" runat="server" Style="display: none;" Text='<%# Eval("Calltype")%>'></asp:Label>
                                        <asp:ImageButton ID="imgbtnEdit" runat="server" ImageUrl="~/App_Themes/ThemeNew/Images/edit.png"
                                            ToolTip="Edit Details" CommandArgument='<%# Eval("ID") %>' OnClick="imgbtnEdit_OnClick" />
                                        <asp:ImageButton ID="imgbtnDelete" runat="server" ImageUrl="~/App_Themes/ThemeNew/Images/delete.png"
                                            ToolTip="Delete" Style="display: none;" CommandArgument='<%# Eval("id") %>' OnClientClick="return confirm('Are you sure you want to delete the Call type?');"
                                            OnClick="imgbtnDelete_OnClick" />
                                    </td>
                                </tr>
                            </ItemTemplate>
                        </asp:ListView>

Actually i want to show sort images while user click on linkbuttons.And i want to do it by code behind.
My .cs code is as follow:

 protected void lnk_Sort(object sender, EventArgs e)
{
    LinkButton lnk = (LinkButton)sender;
    string arg = lnk.CommandArgument.ToString();
    ViewState["sortCol"] = arg;
    GetSortDirection();
    BindData(ViewState["sortCol"].ToString(), ViewState["sortDir"].ToString(), Convert.ToInt32(ViewState["nmbr"]), Pager.PageSize);
}


private void GetSortDirection()
{
    if (Convert.ToString(ViewState["sortDir"]) == "Desc")
    {
        ViewState["sortDir"] = "asc";

    }
    else
    {
        ViewState["sortDir"] = "Desc";
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:55:48+00:00Added an answer on June 13, 2026 at 3:55 am

    i have done it with a silly trick

    my html code is:

    <asp:ListView ID="lst_CallType" runat="server" ItemPlaceholderID="tr" OnItemDataBound="lst_CallType_ItemDataBound">
                                <LayoutTemplate>
                                    <table cellspacing="0">
                                        <tr class="hdrRowColor1">
                                            <td width="35px" align="left">
                                                &nbsp;S.No
                                            </td>
                                            <td align="left" width="300px">
                                                <asp:LinkButton ID="lnk_Name" runat="server" ValidationGroup="vgSearch" CommandArgument="tblCallTypenew.CallType"
                                                    OnClick="lnk_Sort">Name</asp:LinkButton>
                                                <asp:Image ID="img_lnk_Name" Visible="false" runat="server" />
                                            </td>
                                            <td align="left" width="150px">
                                                <asp:LinkButton ID="lnk_CreatedBy" runat="server" CommandArgument="tblUserNew.FirstName"
                                                    ValidationGroup="vgSearch" OnClick="lnk_Sort">Created By</asp:LinkButton>
                                                <asp:Image ID="img_lnk_CreatedBy" Visible="false" runat="server" />
                                            </td>
                                            <td align="left" width="120px">
                                                <asp:LinkButton ID="lnk_CreatedOn" runat="server" CommandArgument="tblCallTypenew.CreatedDate"
                                                    ValidationGroup="vgSearch" OnClick="lnk_Sort">Created On</asp:LinkButton>
                                                <asp:Image ID="img_lnk_CreatedOn" Visible="false" runat="server" />
                                            </td>
                                            <td align="left" width="150px">
                                                <%--<asp:LinkButton ID="lnkCreatedDate" runat="server" CommandArgument="tblUserActivities.CreatedDate"
                                            OnClick="lnk_Sort">Created Date</asp:LinkButton>--%>
                                                <asp:LinkButton ID="lnk_LastModfiedBy" runat="server" CommandArgument="v.FirstName"
                                                    ValidationGroup="vgSearch" OnClick="lnk_Sort">Last Modified By</asp:LinkButton>
                                                <asp:Image ID="img_lnk_LastModfiedBy" Visible="false" runat="server" />
                                            </td>
                                            <td align="left" width="120px">
                                                <asp:LinkButton ID="lnk_LastModfiedOn" runat="server" CommandArgument="tblCallTypenew.ModifiedDate"
                                                    ValidationGroup="vgSearch" OnClick="lnk_Sort">Last Modified On</asp:LinkButton>
                                                <asp:Image ID="img_lnk_LastModfiedOn" Visible="false" runat="server" />
                                            </td>
                                            <td align="center" width="55px">
                                                <asp:LinkButton ID="lnk_Status" runat="server" CommandArgument="tblCallTypenew.isactive"
                                                    ValidationGroup="vgSearch" OnClick="lnk_Sort">Status</asp:LinkButton>
                                                <asp:Image ID="img_lnk_Status" Visible="false" runat="server" />
                                            </td>
                                            <td align="center" width="50px" style="border-right: 1px solid #6398cc">
                                                Activity
                                                <%-- <div style="width: 50px; float: right;">
                                                </div>--%>
                                            </td>
                                        </tr>
                                        <tr id="tr" runat="server">
                                        </tr>
                                    </table>
                                </LayoutTemplate>
                                <ItemTemplate>
                                    <tr class='<%# Convert.ToBoolean(Container.DataItemIndex % 2) ? "EvenRowColor" : "OddRowColor" %>'>
                                        <td align="left" valign="middle">
                                            &nbsp;<%# Container.DataItemIndex+1 %>.
                                        </td>
                                        <td align="left">
                                            <asp:Label ID="lblDeptId" runat="server" Text='<%# Eval("ID")%>' Visible="false"></asp:Label>
                                            <%# Eval("Calltype")%>
                                        </td>
                                        <td align="left">
                                            <%# Eval("CreatedBy")%>
                                        </td>
                                        <td align="left">
                                            <%# Convert.ToDateTime(Eval("CreatedDate")).ToString("MMM dd, yyyy")%>
                                        </td>
                                        <td align="left">
                                            <%# Eval("ModifiedBy")%>
                                        </td>
                                        <td align="left">
                                            <%# Convert.ToDateTime(Eval("ModifiedDate")).ToString("MMM dd, yyyy")%>
                                        </td>
                                        <td align="center">
                                            <asp:Label ID="lbl_Status" runat="server" Style="display: none;" Text='<%# Eval("IsActive")%>'></asp:Label>
                                            <asp:ImageButton ID="imgbtnStatus" runat="server" CommandArgument='<%# Eval("id") %>'
                                                OnClick="imgbtnStatus_Onclick" />
                                        </td>
                                        <td class="last" align="center">
                                            <asp:Label ID="lblCallType" runat="server" Style="display: none;" Text='<%# Eval("Calltype")%>'></asp:Label>
                                            <asp:ImageButton ID="imgbtnEdit" runat="server" ImageUrl="~/App_Themes/ThemeNew/Images/edit.png"
                                                ToolTip="Edit Details" CommandArgument='<%# Eval("ID") %>' OnClick="imgbtnEdit_OnClick" />
                                            <asp:ImageButton ID="imgbtnDelete" runat="server" ImageUrl="~/App_Themes/ThemeNew/Images/delete.png"
                                                ToolTip="Delete" Style="display: none;" CommandArgument='<%# Eval("id") %>' OnClientClick="return confirm('Are you sure you want to delete the Call type?');"
                                                OnClick="imgbtnDelete_OnClick" />
                                        </td>
                                    </tr>
                                </ItemTemplate>
                            </asp:ListView>
    

    My code behind code is:

     protected void lnk_Sort(object sender, EventArgs e)
    {
        LinkButton lnk = (LinkButton)sender;
        string arg = lnk.CommandArgument.ToString();
        ViewState["sortCol"] = arg;
        GetSortDirection();
        BindData(ViewState["sortCol"].ToString(), ViewState["sortDir"].ToString(), Convert.ToInt32(ViewState["nmbr"]), Pager.PageSize);
        string name = lnk.ID;
        Image img = (Image)(lst_CallType.FindControl("img_" + name));
        if (img != null)
        {
            SetSortOrderImage(img, ViewState["sortDir"].ToString());
        }
    }
    
    private void SetSortOrderImage(Image image, String sortorder)
    {
        if (sortorder == "asc")
        {
            image.Visible = true;
            image.ImageUrl = "../App_Themes/ThemeNew2/images/up.png";
        }
        else if (sortorder == "Desc")
        {
            image.Visible = true;
            image.ImageUrl = "../App_Themes/ThemeNew2/images/down.png";
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQLDataSource that is bound to a ListView control but I want
I have a ListView that has a FileUpload control and a button in each
I have a ListView control and in the LayoutTemplate I have a LinkButton. I
I have listview control.There is an option to remove selected items.After the user removes
I have a ListView control set up in details mode with 5 columns. It
I have a ListView control on my form set up like this in details
I'm coding in VS2008 using C#. On my form, I have a ListView control.
I have an asp:ListView control on an ASP.NET page. It is bound to an
OK, so, I have a ListView-derived control that changes Grouping and ItemsSource on the
I have an ASP.NET 2.0 ListView control (aka:parent) and configured inside this ListView I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.