I am creating a social network website as facebook, but that website has an error with posing status , i used following code to post status.This code is on page load,
Label1.Text = Session["Email"].ToString();
if (!IsPostBack)
{
//load data
string db = "";
db = ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(db);
con.Open();
try
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT Name,Status FROM [PhotoStatusProfile] WHERE Email = #Email";
cmd.Parameters.AddWithValue("#Email", Session["Email"].ToString());
cmd.Connection = con;
SqlDataReader dr;
dr = cmd.ExecuteReader();
string status = "";
string name = "";
while (dr.Read())
{
System.Web.UI.HtmlControls.HtmlGenericControl div = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
Label nameLabel = new Label();
status += dr["Status"].ToString();
name += dr["name"].ToString();
nameLabel.Text = name;
Label statusLabel = new Label();
statusLabel.Text = status;
div.Controls.Add(nameLabel);
div.Controls.Add(statusLabel);
container.Controls.Add(div);
}
con.Close();
}
I am passing value to a div which name is container.
When i write a status saying hi,and click the post button but nothing happen, then i refresh the page, and it has posted like this
2nd time i do the same thing saying hello, this is the result of it.
This is container. it's a name of a div tag
<div id="container" runat="server"> </div>
This is post button event
string inserQuery = "insert into PhotoStatusProfile(Name,Status,Email) values (#Name,#Status,#e)";
SqlCommand commm = new SqlCommand(inserQuery, conn);
commm.Parameters.AddWithValue("#Name", ProfileName.Text);
commm.Parameters.AddWithValue("#Status",TextBox1.Text);
commm.Parameters.AddWithValue("#e", Label1.Text);
commm.ExecuteNonQuery();
I want to post the status for down to down,
Could anybody tell me , what should i do to prevent this errors. Thaks
I'd suggest you to do the following re-factoring to your code.
Extract the code between following if block in your Page_Load and create a method called LoadData().
if(!IsPostBack)
{
LoadData();
}
Then in your Post button's click event call this LoadData() method again just after saving your new post to the database.
Instead of Labels to display values use DIVs (I mean nameLabel and statusLabel)
Also add following style to these DIVs
style="float:left;"
This is how you'd add it in code behind
div.Style.Add("float", "left");
UPDATE 1
Here's how you'd add DIVs instead of Labels.
HtmlGenericControl divContainer = new HtmlGenericControl("div");
HtmlGenericControl nameDiv = new HtmlGenericControl("div");
// Not sure why you concatenate Name and Status here. I'll just use one value per each row
// status += dr["Status"].ToString();
// name += dr["name"].ToString();
nameDiv.InnerText = dr["name"].ToString();
nameDiv.Style.Add("float", "left");
divContainer.Controls.Add(nameDiv);
HtmlGenericControl statusDiv = new HtmlGenericControl("div");
statusDiv.InnerText = dr["Status"].ToString();
statusDiv.Style.Add("float", "left");
divContainer.Controls.Add(statusDiv);
container.Controls.Add(div);
UPDATE 2
Since you've adopted #mybirthname solution (using a Repeater) I'll just give you the design you want based on DIVs.
<asp:Repeater runat="server" ID="Repeater1">
<ItemTemplate>
<%--This is your template--%>
<div style="margin-top: 5px;">
<div style="padding: 2px; border: 1px solid black; background-color:Silver; display:table; width:600px;">
<div style="float:left;">
<div style="padding: 4px">
<asp:Image ID="Image1" runat="server" ImageUrl="~/Images/my-avatar.PNG" /> <%--Give the correct path to your image--%>
</div>
</div>
<div>
<div style="font-size: 16px; font-family: Arial, Helvetica, sans-serif; font-weight: bold; padding-top: 4px;">
<%#Eval("name") %>
<div style="float:right; font-size: 10px;">9:00 am</div> <%--If you need to have a time stamp for each entry make use of this div--%>
</div>
<div style="width:500px;"><%#Eval("Status") %></div>
</div>
</div>
</div>
<%--End template--%>
</ItemTemplate>
</asp:Repeater>
From what I see you are adding the div to container and nameLabel, StatusLabel to div on every iteration of the DataReader. Probably this is not your intention, You want to add them once, because you are storing in status all values of Status row.
while (dr.Read())
{
status += dr["Status"].ToString();
name += dr["name"].ToString();
}
System.Web.UI.HtmlControls.HtmlGenericControl div = new
System.Web.UI.HtmlControls.HtmlGenericControl("div");
container.Controls.Add(div);
Label nameLabel = new Label();
nameLabel.Text = name;
div.Controls.Add(nameLabel);
Label statusLabel = new Label();
statusLabel.Text = status;
div.Controls.Add(statusLabel);
Also it will be good idea to put some ID to the labels. I advice you to put labels and div always and just make them visible false if there are no values in them.
Also if you add dynamically controls do it always in CreateChildControls() method.
EDIT: For what you want(written in my comments) you need a repeater. Check this tutorial in MSDN
<div id="container">
<asp:Repeater runat="server" ID="Repeater1">
<ItemTemplate>
<div class="yourDivClass">
<asp:Label runat="server"> <%#Eval("Status") %> </asp:Label>
<asp:Label runat="server"> <%#Eval("name") %> </asp:Label>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
And in the code behind in Page_Load method:
if(!PostBack)
{
//in data set you will have dataTable with all rows and this rows should contain Name and Status columns
Repeater1.DataSource = dataSet;
Repeater1.DataBind();
}
Related
Here is my ASPX markup to display all the products available from the database, and allow the user to view details and add to cart:
<%# Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="home.aspx.cs" Inherits="WADAssignment.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<form runat="server" >
<section class="py-5">
<div class="container px-4 px-lg-5 mt-5">
<div class="row gx-4 gx-lg-5 row-cols-2 row-cols-md-3 row-cols-xl-4 justify-content-center">
<asp:Repeater ID="RepeaterHome" runat="server">
<ItemTemplate>
<div class="col mb-5">
<div class="card h-100">
<!-- Product image-->
<img class="card-img-top" width="205.99px" height="205.99px" src="data:image/jpg;base64,<%# #Convert.ToBase64String((byte[])(Eval("prod_photo"))) %>" alt="..." />
<!-- Product details-->
<div class="card-body p-4">
<div class="text-center">
<!-- Product name-->
<asp:HiddenField ID="prodId" Value='<%# Eval("prod_id") %>' runat="server" />
<h5 class="fw-bolder"><%# Eval("prod_name") %></h5>
<!-- Product price-->
RM <%# Eval("prod_price") %><br/>
<%# Eval("prod_desc") %>
</div>
</div>
<!-- Product actions-->
<div class="card-footer p-4 pt-0 border-top-0 bg-transparent">
<div class="text-center">
<asp:Button CssClass="btn btn-outline-dark mt-auto" ID="Button2" runat="server" Text="View Details" PostBackUrl='<%# "productDetails.aspx?id=" + Eval("prod_id") %>'/>
</div><br />
<div class="text-center">
<asp:Button CssClass="btn btn-outline-dark mt-auto" ID="Button1" runat="server" Text='<%# Convert.ToInt32(Eval("prod_quantity")) > 0 ? "Add to Cart" : "Sold out" %>' Enabled='<%# Convert.ToInt32(Eval("prod_quantity")) > 0 ? true : false %>' OnClick="Button1_Click" />
</div>
</div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
</div>
</section>
</form>
</asp:Content>
This is the onclick function for the add to cart button, however with my current implementation of going through the repeater item list, the biggest prodId will always be selected, instead of the respective one, and then causing a SQL error.
protected void Button1_Click(object sender, EventArgs e)
{
HiddenField hidden = null;
foreach (RepeaterItem item in RepeaterHome.Items)
{
hidden = (HiddenField)item.FindControl("prodId");
}
int prodId = Convert.ToInt32(hidden.Value);
String id = Session["id"].ToString();
string strCon = ConfigurationManager.ConnectionStrings["WebConfigConString"].ConnectionString;
using (SqlConnection con = new SqlConnection(strCon))
{
string strCart = "INSERT INTO CART_ITEM (id, prod_id, quantity) values (#id, #prod_id, #quantity)";
string strUpdateProd = "UPDATE PRODUCT SET PROD_QUANTITY = PROD_QUANTITY - 1 WHERE PROD_ID = #prod_id";
using (SqlCommand cmdCart = new SqlCommand(strCart, con))
{
try
{
con.Open();
cmdCart.Parameters.AddWithValue("#id", id);
cmdCart.Parameters.AddWithValue("#prod_id", prodId);
cmdCart.Parameters.AddWithValue("#quantity", 1);
SqlDataReader dtrCart = cmdCart.ExecuteReader();
dtrCart.Close();
con.Close();
using (SqlCommand cmdUpdateProd = new SqlCommand(strUpdateProd, con))
{
con.Open();
cmdUpdateProd.Parameters.AddWithValue("#prod_id", prodId);
SqlDataReader dtrUpdateProd = cmdUpdateProd.ExecuteReader();
dtrUpdateProd.Close();
con.Close();
}
} catch (SqlException)
{
Response.Write("<script>alert('Item already in cart!')</script>");
}
}
}
}
This screenshot is showing my web page:
My product page
Ok, you want the current item you click on. But you ahve a loop (for each) like this:
foreach (RepeaterItem item in RepeaterHome.Items)
{
hidden = (HiddenField)item.FindControl("prodId");
}
the above will loop for each item, and then when done it will ALWAYS be the last item.
You want to JUST get the current ONE item that you clicked on, not loop (for each) as you have above.
So, your code can be like this (example code).
protected void Button1_Click(object sender, EventArgs e)
{
HiddenField hidden = null;
// get row click information
Button MyBtn = (Button)sender;
RepeaterItem MyRepeaterItem = (RepeaterItem)MyBtn.NamingContainer;
hidden = (HiddenField)MyRepeaterItem.FindControl("prodId");
int prodId = Convert.ToInt32(hidden.Value);
String id = Session["id"].ToString();
string strCon = ConfigurationManager.ConnectionStrings["WebConfigConString"].ConnectionString;
using (SqlConnection con = new SqlConnection(strCon))
{
string strCart = #"INSERT INTO CART_ITEM (id, prod_id, quantity)
values (#id, #prod_id, #quantity)";
string strUpdateProd = #"UPDATE PRODUCT SET PROD_QUANTITY = PROD_QUANTITY - 1
WHERE PROD_ID = #prod_id";
using (SqlCommand cmdCart = new SqlCommand(strCart, con))
{
try
{
con.Open();
cmdCart.Parameters.Add("#id", SqlDbType.Int).Value = id;
cmdCart.Parameters.Add("#prod_id", SqlDbType.Int).Value = prodId;
cmdCart.Parameters.Add("#quantity", SqlDbType.Int).Value = 1;
cmdCart.ExecuteNonQuery();
cmdCart.Parameters.Clear();
cmdCart.CommandText = strUpdateProd;
cmdCart.Parameters.Add("#prod_id", SqlDbType.Int).Value = prodId;
cmdCart.ExecuteNonQuery();
}
catch (SqlException)
{
Response.Write("<script>alert('Item already in cart!')</script>");
}
}
}
}
Now, above will do the update and add to the cart. But, we have good chance that we want to check if the item is already in the cart, and not allow to add again. (or just increase the qty if they choose again - not sure which choice you want). So, the above will allow adding again and again. So, before we run the above? We should find out if the item already in the cart.
(that part is missing, and was not part of your question).
I am trying to fetch table category and based on that table category the multiple details of that category will have to automatically fetch under this following category but unfortunately multiple table is created under this single category.
First of all I have created tbl_category(ID{PK}, catName) table on DB. Then created tbl_categoryDetails(ID{PK}, catId{FK}, catDetails). So I have needed multiple categoryDetails fields under single category.
So then I have to fetch this catName with their details part by part. I have attached of the static table, I need this way table data will be fetched Static Table Image.
But Unfortunately I am getting data this way My Dynamic Table Image. The categoryName fetch multiple time but I want single time. I am using repeater control to fetch data from DB. please help me to solve this problem.
My Forms.aspx code is here:
<asp:Repeater ID="rptr_form" runat="server">
<ItemTemplate>
<section class="about">
<div class="container">
<div class="row no-gutters d-flex justify-content-center">
<div class="flex-column justify-content-center about-content minwidth">
<div class="section-title">
<div class="mycontent-center">
<h2 style="margin-bottom: -5px;" data-toggle="collapse" role="button" href="#collapseExample19" aria-expanded="false" aria-controls="collapseExample19"><%#Eval("form_categoryname") %>   <i class="fa fa-chevron-circle-down" aria-hidden="true"></i></h2>
<br />
<div class="content-style collapse tbl-scroll" id="collapseExample19">
<table class="table table-striped">
<thead>
<tr>
<th scope="col"></th>
<th scope="col">No</th>
<th scope="col">Bangla</th>
<th scope="col">English</th>
</tr>
</thead>
<tbody>
<tr class="table-info">
<td><%#Eval("form_details") %></td>
<td><%#Eval("form_no") %></td>
<td><a href="<%# "../" + Eval("form_bengali_path") %>" target="_blank">
<img src="assets/image/pdf.jpg" style="height: 30px; width: 48px;" /></a></td>
<td class="center"><a href="<%# "../" + Eval("form_english_path") %>" target="_blank">
<img src="assets/image/pdf.jpg" style="height: 30px; width: 48px;" /></a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</ItemTemplate>
</asp:Repeater>
My Forms.aspx.cs code is here:
protected void AllFormLoad()
{
try
{
using (SqlConnection con = new SqlConnection(strcon))
{
SqlCommand cmd = new SqlCommand("spFormDetailsFetch", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
rptr_form.DataSource = dt;
rptr_form.DataBind();
}
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message + "');</script>");
}
}
Sql Query
select D.ID, C.form_categoryname, D.form_details, D.form_no, D.form_bengali_path, D.form_english_path from tbl_form_details D inner join tbl_form_category C on D.form_categoryId = C.ID order by form_categoryname
Sounds like you really need two nested loops here, one for categories and one for each category's details. You should add the SQL statement that is pulling the data to your question so we can tell for sure, but I'm guessing the duplication is because of the join.
This isn't a wonderful solution, but what I've done before in this scenario is to use the ItemDataBound event in codebehind to show the header only for the first row of each category. So you keep track of the category id somewhere, maybe in a hidden field, and as itemdatabound loops through the records, when the category id changes, you show the header for that item record, and then update the category id. Then as long as the category id stays the same, you keep hiding the header. When it changes again, you know you've hit the records for the next category and it's time to show the header again.
Below is a simplified example, note that you need to wrap a placeholder around the header and foot sections so you can hide them as needed. In your case that would be everything above and below the tr.
Repeater code:
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
<ItemTemplate>
<asp:PlaceHolder ID="pnlHead" runat="server">
<section>
<h2><%#DataBinder.Eval(Container.DataItem, "form_categoryname").ToString()%></h2>
</asp:PlaceHolder>
<div>
<%#DataBinder.Eval(Container.DataItem, "form_details").ToString()%>
<asp:HiddenField ID="HiddenFieldID" runat="server" Value='<%# DataBinder.Eval(Container.DataItem,"form_categoryname") %>' />
</div>
<asp:PlaceHolder ID="pnlFoot" runat="server">
</section>
</asp:PlaceHolder>
</ItemTemplate>
</asp:Repeater>
Page Load:
public string CurrentCategory = "";
protected void Page_Load(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(DB.GetDBConn()))
{
con.Open();
using (IDataReader rs = DB.GetRS("select D.ID, C.form_categoryname, D.form_details, D.form_no, D.form_bengali_path, D.form_english_path from tbl_form_details D inner join tbl_form_category C on D.form_categoryId = C.ID order by form_categoryname", con))
{
Repeater1.DataSource = rs;
Repeater1.DataBind();
}
}
int idx = 0;
// where head is visible, show the foot for the previous row
foreach (RepeaterItem item in Repeater1.Items)
{
if (idx > 0)
{
bool headvisible = item.FindControl("pnlHead").Visible;
if (headvisible)
{
Repeater1.Items[idx - 1].FindControl("pnlFoot").Visible = true;
}
}
idx++;
}
}
OnItemDataBound:
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
HiddenField HiddenFieldID = e.Item.FindControl("HiddenFieldID") as HiddenField;
string itemCategory = HiddenFieldID.Value;
if (itemCategory == CurrentCategory)
{
PlaceHolder pnlHead = e.Item.FindControl("pnlHead") as PlaceHolder;
PlaceHolder pnlFoot = e.Item.FindControl("pnlFoot") as PlaceHolder;
pnlHead.Visible = false;
pnlFoot.Visible = false;
}
else
{
//Now we're in a new category, so show header
PlaceHolder pnlHead = e.Item.FindControl("pnlHead") as PlaceHolder;
PlaceHolder pnlFoot = e.Item.FindControl("pnlFoot") as PlaceHolder;
pnlHead.Visible = true;
pnlFoot.Visible = false;
CurrentCategory = itemCategory;
}
}
I have created Ajax autocomplete extender on my web page that retrieves the values from the database.
When I select one of the options from the autocomplete dropdown list I get the desired result.
The problem is:
When the user types entire word by himself (or if the word is pasted) and when he does not select one of the options from the dropdownlist and presses enter, result is blank.
How do I solve this problem?
My code for autocomplete extender is:
<asp:HiddenField ID="HiddenID" runat="server" />
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:TextBox ID="SearchRetailer" runat="server" Style="background-image: url(Search-icon.png ); border: 1px groove black; background-position: right; background-repeat: no-repeat; float: right; width: 20%;" />
<asp:AutoCompleteExtender
ID="AutoCompleteExtender1"
TargetControlID="tgt1"
runat="server" MinimumPrefixLength="2" ServiceMethod="GetCompletionList" UseContextKey="True" OnClientItemSelected="GetCode" EnableCaching="true" />
The javascript function is:
<script type="text/javascript" language="javascript">
function GetCode(source, eventArgs) {
var hfield = $get('<%=this.HiddenID.ClientID%>');
hfield.value = eventArgs.get_value();
window.open("newPage.aspx?Paramter1=" + hfield.value + "", "_self", false);
}
</script>
And my webservice code is:
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{
SqlConnection sqlconn = "my connection string"
string sql = "select abc from aaa where abc like '" + prefixText + "%'";
SqlDataAdapter cmd1 = new SqlDataAdapter(sql, sqlconn);
DataTable dt0r = new DataTable();
cmd1.Fill(dt0r);
int i = 0;
string[] rList = new string[dt0r.Rows.Count];
foreach (DataRow dr in dt0r.Rows)
{
rList.SetValue(dr["abc"].ToString(), i);
i++;
}
return rList;
}
I got it to work.
I added FirstRowSelected="true" in the properties of the autocomplete extender and the functionality is now working!!
Foreach loop in Aspx page how to add checkbox and label values from datatable . Recieve all ticked checkbox value.
I have written this code in aspx page not in aspx.cs .
<% foreach (Employee myEmp in _empList) {
empName = myEmp.ToString(); %>
<div class="abc">
<div class="pqr">
<asp:Label Text="<% empName %>" runat="server" ID="lblEmpName"></asp:Label></label>
</div>
<div class="xyz">
<asp:CheckBox ID="chkBox" Checked="false" runat="server" />
</div>
</div>
<% } %>
I think you're just missing the : or = for the label. <% should be <%:. Use : to encode any html and avoid js injection. More info on = vs :
<% foreach (Employee myEmp in _empList) {
empName = myEmp.ToString(); %>
<div class="abc">
<div class="pqr">
<asp:Label Text="<%: empName %>" runat="server" ID="lblEmpName"></asp:Label>
</div>
<div class="xyz">
<asp:CheckBox ID="chkBox" Checked="false" runat="server" />
</div>
</div>
<% } %>
You can do something like this:
List<user> userList = new List<user>();
foreach (user usr in userList)
{
PlaceHolder1.Controls.Add(new CheckBox()
{
ID = "cb_"+usr.UserId,
Text = usr.Name,
});
}
I think the best way to add controls dynamically to asp.net page is oninit page-event.
you should try something like this.
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
/*LinkButton lb = new LinkButton();
lb.ID = "lbAddFilter";
pnlFilter.Controls.Add(lb);
lb.Text = "Add Filter";
lb.Click += new EventHandler(lbAddFilter_Click);*/
// regenerate dynamically created controls
foreach ( var employee in employeeList)
{
Label myLabel = new Label();
// Set the label's Text and ID properties.
myLabel.Text = "Label" + employee.Name.ToString();
myLabel.ID = "Label" + employee.ID.ToString();
CheckBox chkbx = new CheckBox();
chkbx.ID = "CheckBox" + employee.ID.ToString();
chkbx.Text = "Label" + employee.Name.ToString();
MyPanel.Controls.Add(myLabel);
MyPanel.Controls.Add(chkbx);
}
}
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";
}
}
}
}
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.