Write an Article Write a Tutorial Add a Fast Code* *Fast Code might be any helpful code with brief comment
Stem Cells Blood Banks Insurances .Net Hosting Credit Cards PC Rental Business
Tutorials: ASP .NET C# .NET VB .NET Articles: ASP .NET C# .NET VB .NET Fast Code: ASP .NET C# .NET VB .NET
Assigning Text to a Label Control embeded inside an ItemTemplate of a DataList
We will be able to access the Row item of a Datalist when the DataList is already bounded to the Database. so we will using ItemDataBound event of the DataList.
our DataList with its DataSource Control look like this:
DataSourceID="SqlDataSource1" OnItemDataBound="DataList1_ItemDataBound"> AlbumID: Caption: IsPublic: UserName: ConnectionString="<%$ ConnectionStrings:Personal %>" SelectCommand="SELECT * FROM [Albums]">
Now the Code behind for ItemDataBound event is the following:
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Label exam_weigh = (Label)e.Item.FindControl("Label1"); exam_weigh.Text = "Test String"; } }
You noticed that we are accessing two ListItemType (Item and AlternatingItem) types from the current row.
@@ Omer Kamal is a Software Developer at Elanize KG Germany. He MSc. Mathematics from Islamia University Bahawalpur, Pakistan and Certified Developer from National Institute of Electronics Islamabad, Pakistan. He is Founder of FriendsPoint.de and Dotnet-Friends.com. He is currently Involved with Microsoft Office SharePoint 2007, Microsoft Dynamics CRM, BI Portal Solutions (Microsoft Dynamics Customization) and Web Security Solutions. Check Omer Kamal Profile
29/07/2008 13:19:43 UTC
04/11/2008 05:10:10 UTC