Click here to Skip to main content
16,005,236 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
im making a website that has a community section in this section i want to make a dstalist and each dataitem of this datalist has (view more , comment , update) any article here to show that
Posted
Comments
[no name] 21-May-15 15:12pm    
Did you go look for one?
May Bash 23-May-15 5:38am    
not yet , i need a help

1 solution

]]>
]]>

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<script runat="server">

ICollection CreateDataSource()
{

// Create sample data for the DataList control.
DataTable dt = new DataTable();
DataRow dr;

// Define the columns of the table.
dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
dt.Columns.Add(new DataColumn("StringValue", typeof(String)));
dt.Columns.Add(new DataColumn("CurrencyValue", typeof(double)));

// Populate the table with sample values.
for (int i = 0; i < 9; i++)
{
dr = dt.NewRow();

dr[0] = i;
dr[1] = "Description for item " + i.ToString();
dr[2] = 1.23 * (i + 1);

dt.Rows.Add(dr);
}

DataView dv = new DataView(dt);
return dv;

}


void Page_Load(Object sender, EventArgs e)
{

// Load sample data only once, when the page is first loaded.
if (!IsPostBack)
{
ItemsList.DataSource = CreateDataSource();
ItemsList.DataBind();
}

}

void Item_Bound(Object sender, DataListItemEventArgs e)
{

if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{

// Retrieve the Label control in the current DataListItem.
Label PriceLabel = (Label)e.Item.FindControl("PriceLabel");

// Retrieve the text of the CurrencyColumn from the DataListItem
// and convert the value to a Double.
Double Price = Convert.ToDouble(
((DataRowView)e.Item.DataItem).Row.ItemArray[2].ToString());

// Format the value as currency and redisplay it in the DataList.
PriceLabel.Text = Price.ToString("c");

}

}

</script>

<head runat="server">
<title>DataList ItemDataBound Example</title>
</head>
<body>

<form id="form1" runat="server">

DataList ItemDataBound Example



<asp:datalist id="ItemsList" xmlns:asp="#unknown">
BorderColor="black"
CellPadding="5"
CellSpacing="5"
RepeatDirection="Vertical"
RepeatLayout="Table"
RepeatColumns="3"
OnItemDataBound="Item_Bound"
runat="server">

<HeaderStyle BackColor="#aaaadd">
</HeaderStyle>

<alternatingitemstyle backcolor="Gainsboro">


<HeaderTemplate>

List of items

</HeaderTemplate>

<itemtemplate>

Description:

<%# DataBinder.Eval(Container.DataItem, "StringValue") %>




Price:
<asp:label id="PriceLabel">
runat="server"/>





</form>

</body>
</html
 
Share this answer
 
Comments
May Bash 23-May-15 5:38am    
i cant find the comment , see more , or update sections !

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900