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

  • SEARCH
  • Home
  • 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 8817393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:50:12+00:00 2026-06-14T04:50:12+00:00

I have a ListView filled with data from a DataSet loaded out of a

  • 0

I have a ListView filled with data from a DataSet loaded out of a MySql database. The ListView shows a list of text modules to create a word- file later. Here is the ListView definition:

<asp:ListView ID="addTextModuleList" runat="server" OnItemCommand="addTextModuleList_OnItemCommand" DataKeyNames="ID" >           
    <ItemTemplate>
        <asp:LinkButton ID="addTextModuleButton" runat="server" CssClass="insertTextModuleButtonFade" CommandName="insertTextModule"></asp:LinkButton>
        <div id="listViewId" runat="server" style="float:left; width:24px; height:16px; margin:2px 15px 5px 0px; text-align:right;"><%# Eval("ID") %></div>
        <div style="float:left; width:200px; height:25px; margin:2px 10px 5px 0px; text-align:left; font-weight:bold;"><%# Eval("shortName") %>:</div>
        <div style="float:left; width:700px; margin:5px;"><%# Eval("fullName") %></div>
        <div class="clear"></div>
    </ItemTemplate>        
</asp:ListView>

I want to add textModules to the confirmation by clicking on an icon. And that’s my problem. The icon has to be shown in different colors, depending on if the text module is already added or not. The icon is loaded as an asp:Linkbutton and I have a CSS class for the icon shown in green and another CSS class for the same icon in faded grey.

I can change the CssClass of the icon by clicking it but I do not know how to change the CssClass of the icon while loading the Page or the ListView. Any ideas?

Here is my codebehind for the DataSet:

protected void executeTemplateSelection()
    {
        // connect to database
        MySqlConnection con = new MySqlConnection();
        con.ConnectionString = Helper.CONNECTION_STRING;
        MySqlCommand cmd = null;

        // load customer textModules
        con.Open();
        cmd = new MySqlCommand();
        cmd.Connection = con;
        cmd.CommandText = "SELECT * FROM textmodule WHERE ID IN " + Session["loadTextModuleTemplates"].ToString();
        MySqlDataAdapter sda = new MySqlDataAdapter(cmd);
        DataSet ds = new DataSet();        
        sda.Fill(ds);
        addTextModuleList.DataSource = ds;
        addTextModuleList.DataBind();
        con.Close();

        cmd = new MySqlCommand();
        con.Open();
        cmd.Connection = con;
        cmd.CommandText = "SELECT * FROM linktextmodule WHERE confirmationId = " + Session["currentConfirmationId"].ToString();
        MySqlDataReader mdr = cmd.ExecuteReader();
        ds.Tables[0].Columns.Add("alreadyAdded");

        while (mdr.Read())
        {            

            for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
            {
                if (mdr["textModule"].Equals(ds.Tables[0].Rows[i]["ID"]))
                {
                    ds.Tables[0].Rows[i]["alreadyAdded"] = "yes";                    
                }
            }

        }

    }
  • 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-14T04:50:13+00:00Added an answer on June 14, 2026 at 4:50 am

    You can implement the ListView.ItemDataBound event (see http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.itemdatabound%28v=vs.100%29.aspx), which would allow you to change properties on the controls for each item as it’s bound. I have used this approach before.

    You could also try using the data binding syntax ( <%# %> ) directly in the CssClass attribute, though I’m not certain if that works inside the CssClass attribute like it does inside some other attributes. You’re already doing that inside the div, but see for example http://support.microsoft.com/kb/307860 where they give an example inside an attribute.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hy!! I have a listview that should be filled with data from the database
I have a listview which is filled with data form sqlitedatabase. A list-view element
I have a list view filled with data. I set up a context menu
I have ListView which is saving all data to database. For adding i have
I have a ListView which I filled in from SQL Server view called view_ListaKlientow
I have a ListView filled with for loop. The data inside ListView is now
I have a sortable listview that gets filled with a live data as it
I have a ListView that is filled with a dynamic set of data each
I have a List and it is filled with strings like this: List<string> data
I have a ListView and a Arrayadapter filled with Strings. The data should be

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.