Formatting DataBinder.Eval data

There is an optional overload for DataBinder.Eval to supply formatting: <%# DataBinder.Eval(Container.DataItem, “expression”[, “format”]) %> The format parameter is a String value, using the value placeholder replacement syntax (called composite formatting) like this: <asp:Label id=”lblNewsDate” runat=”server” Text=”<%# DataBinder.Eval(Container.DataItem, “publishedDate”, “{0:dddd d MMMM}”) %>”</label>

asp.net radio button grouping

I finally got around this by creating a plain radio button and setting the value using an server-side eval. <input type=”radio” name=”radCustomer” value=”<%#Eval(“CustomerNumber”) %>” /> Now when the application performs a postback, I check for the value of Request.Form[“radCustomer”]. This works flawlessly.

How can I loop through Items in the Item Template from an asp:Repeater?

It sounds to me like you want to use the ItemDataBound event. http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemdatabound.aspx You will want to check the ItemType of the RepeaterItem so that you don’t attempt to find the checkbox in Header/Footer/Seperator/Pager/Edit Your event would look something along the lines of: void rptItems_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType … Read more

Strange Error – CS0012: The type x is defined in an assembly that is not referenced

I’m Mike’s coworker, and we worked out a solution. The type X is defined in his assembly, that is only in the GAC. Even though his ASP.NET web appplication did have a reference, it was failing to load from the GAC only for this UserControl. The rest of the application worked as expected. We confirmed … Read more

Binding a generic list to a repeater – ASP.NET

It is surprisingly simple… Code behind: // Here’s your object that you’ll create a list of private class Products { public string ProductName { get; set; } public string ProductDescription { get; set; } public string ProductPrice { get; set; } } // Here you pass in the List of Products private void BindItemsInCart(List<Products> ListOfSelectedProducts) … Read more

Bind dictionary to repeater

An IDictionary<TKey,TValue> is also an ICollection<KeyValuePair<TKey, TValue>>. You need to bind to something like (untested): ((KeyValuePair<string,string>)Container.DataItem).Key ((KeyValuePair<string,string>)Container.DataItem).Value Note that the order in which the items are returned is undefined. They may well be returned in the insertion order for small dictionaries, but this is not guaranteed. If you need a guaranteed order, SortedDictionary<TKey, TValue> sorts … Read more

Repeater in Repeater

In the parent repeater, attach a method to the OnItemDataBound event and in the method, find the nested repeater and data bind it. Example (.aspx): <asp:Repeater ID=”ParentRepeater” runat=”server” OnItemDataBound=”ItemBound”> <ItemTemplate> <!– Repeated data –> <asp:Repeater ID=”ChildRepeater” runat=”server”> <ItemTemplate> <!– Nested repeated data –> </ItemTemplate> </asp:Repeater> </ItemTemplate> </asp:Repeater> Example (.cs): protected void Page_Load(object sender, EventArgs e) … Read more

Nested Repeaters in ASP.NET

I’ve found that the simplest way to do nested repeaters without worrying about databinding events is to just set the DataSource using <%# %> syntax. For example: <asp:Repeater runat=”server” id=”Departments”> <ItemTemplate> Name: <%# Eval(“DeptName”) %> Employees: <asp:Repeater runat=”server” DataSource=”<%# Eval(“Employees”) %>”> <ItemTemplate><%# Eval(“Name”) %></ItemTemplate> <SeparatorTemplate>,</SeparatorTemplate> </asp:Repeater> </ItemTemplate> </asp:Repeater> This is presuming that your Departments class … Read more

Default text for empty Repeater control

Joaos answer can even be simplified. In the footer, do not set the visible-property of your default item to false, but use the following expression: <FooterTemplate> <asp:Label ID=”defaultItem” runat=”server” Visible=”<%# YourRepeater.Items.Count == 0 %>” Text=”No items found” /> </FooterTemplate> This way, you can save the code behind.

tech