MySql データベースからロードされたデータがListView
いっぱいです。は、後で単語ファイルを作成するためのテキスト モジュールのリストを示していますDataSet
。定義ListView
は次のとおりです。ListView
<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>
アイコンをクリックして確認に textModules を追加したい。それが私の問題です。テキストモジュールが既に追加されているかどうかに応じて、アイコンを異なる色で表示する必要があります。アイコンはとしてロードされasp:Linkbutton
、緑色で表示されるアイコンの CSS クラスと、色あせた灰色の同じアイコンの別の CSS クラスがあります。
アイコンをクリックして変更できますが、ロード中にアイコンのCssClass
変更方法がわかりません。何か案は?CssClass
Page
ListView
のコードビハインドは次のとおりです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";
}
}
}
}