I am making a pagination feature, because the default one in webforms uses postbacks, which is pathetic really.
Just wondering if there is a better way to output this List of links.
paginator = new Paginator(10,35);
// List<HyperLink>
rptPagination.DataSource = paginator.getPageLinks();
<asp:Repeater ID="rptPagination" runat="server">
<ItemTemplate>
<%# Eval("Text") %>
</ItemTemplate>
</asp:Repeater>
Obviously if I try to change other properties of the HyperLinks, like target, visible etc this will not be rendered into the page.
You can keep using that syntax and continue with pure HTML:
<ItemTemplate>
<%# Eval("Text") %>
</ItemTemplate>
Or, a server side version:
<ItemTemplate>
<asp:HyperLink runat="server"
NavigateUrl='<%# Eval("NavigateUrl") %>'
Text='<%# Eval("Text") %>' />
</ItemTemplate>
Related
Currently I am using asp:Repeater like this:
<asp:Repeater ID="itemsRepeater" runat="server">
<ItemTemplate>
<my:Button runat="server" Title='<%# DataBinder.Eval(Container.DataItem, "Title") %>' />
</ItemTemplate>
</asp:Repeater>
But now, I would like to send whole model to my:Button control like:
<asp:Repeater ID="itemsRepeater" runat="server">
<ItemTemplate>
<my:TabListButton runat="server" Model='<%# this %>' />
</ItemTemplate>
</asp:Repeater>
Could you tell me how to handle that?
I have solved this problem... somehow.
Maybe it's the only way to handle that. I know it's not beautiful, but it works:
public ModelType Model
{
get
{
return this;
}
}
and then:
<asp:Repeater ID="itemsRepeater" runat="server">
<ItemTemplate>
<my:Item runat="server" Model='<%# DataBinder.Eval(Container.DataItem, "Model") %>' />
</ItemTemplate>
</asp:Repeater>
This is dataGrid . How to add text(string) after <%# Bind("Value") %>
for example 123.432 and i want after any record to have "$" dolar sign
<asp:TemplateField HeaderText="Стойност">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Value") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="LabelValue" runat="server" Text='<%# Bind("Value") %>'>
</asp:Label>
</ItemTemplate>
<ControlStyle Width="100px" />
</asp:TemplateField>
<% String.Format("{0}$",Eval("Value")); %>
You can take benefit of Standard Numeric Format String
<asp:Label ID="LabelValue" runat="server"
text='<%# Bind("Value").ToString("C", CultureInfo.CurrentCulture) %>'/>
which is a standard format available with C#.
But you want to show it in the last then you can simply add it in the last.
<ItemTemplate>
<asp:Label ID="LabelValue" runat="server" Text='<%# Bind("Value") %>'>
</asp:Label>
$
</ItemTemplate>
I suggest you to use MaskedEdit extender in ajax toolkit if you already using ajax toolkit in your project. MaskedEdit extender can be use in edit template and it will handle the mask on client side you don't want to worry about value and $ sign when you read the value back.
without using ajax toolkit you can use one label for $ sign and textbox for value field on edit template. In normal template also use two labels for both value and $ sign. then it will be easy to read the values.
I have a hyperlink inside a repeater control for the list of pdf. I want to set a download counter on each click on each hyperlink. The FileName must be a parameter. My code is basically like below. There is also code that calls stored procedure and bind it to the repeater on page_load.
<asp:Repeater ID="rptPDF" runat="server">
<ItemTemplate>
<div class="repeaterResources">
<b><%# Eval("Name") %></b><br />
<b>Description</b> <%# Eval("Description") %><br />
<asp:HyperLink ID="HyperLink2" runat="server" class="downloadLink" NavigateUrl='<%# "~/PDF/" & Eval("Filename") %>' Target="_blank">Download</asp:HyperLink><br /><br />
</div>
</ItemTemplate>
</asp:Repeater>
The mystery bit is how to get a button click event from here. Thanks.
You can use the OnCommand event and set the CommandArgument attribute with a value using
<%# Eval('myvalue') %>.
MSDN has an example minus the repeater: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.oncommand.aspx
Sample:
<asp:Repeater ID="repeater" runat="server">
<ItemTemplate>
<asp:LinkButton runat="server" ID="button1" OnCommand="button1_command" CommandArgument='<%# Eval("myvalue") %>' />
</ItemTemplate>
</asp:Repeater>
I have a repeater control on my .aspx page. There are times where a product is unique, so you can't change it's quantity, but in other cases when there are lots of items of this product, you should be able to edit it's quantity using a textbox and a linkbutton. Both OnlyOne and Quantity are present in the binded collection classes. I need to check the OnlyOne condition, something like that:
<% if (OnlyOne) { %>
<%# Eval("Quantity") %>
<%} else { %>
<asp:TextBox ID="TextBox1" runat="server" />
<asp:LinkButton ID="LinkButton1" runat="server">OK</asp:LinkButton>
<% }%>
The problem is that ASP.NET doesn't find the OnlyOne field. I've tried also (bool)Eval("OnlyOne"), but that didn't work also. So how should I write the condition?
Done it like that:
<asp:Label Text='<%# Eval("Quantity") %>' runat="server" ID="QuantityLabel" Visible='<%# Eval("OnlyOne") %>' />
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("Quantity") %>' Visible='<%# !(bool)Eval("OnlyOne") %>' />
<asp:LinkButton ID="LinkButton1" runat="server" Visible='<%# !(bool)Eval("OnlyOne") %>' Text="OK" />
But I am still interested to hear the answer :) .
I want to do something like this:
<MyTemplate>
<span><%# Container.Title %></span>
<MySubTemplate>
<span><%# Container.Username %></span>
</MySubTemplate>
</MyTemplate>
Assuming I have a list of Titles that each have a list of Usernames.. If this is a correct approach how can I do this or what is a better way?
If you have a list of titles, that each have their own list of UserNames, it seems like you want to do something with nested repeaters (or other controls), not templates...
<asp:Repeater ID="rptTitle" runat="server" >
<ItemTemplate>
<%# Eval("Title") %>
<asp:Repeater ID="rptUsers" runat="server" >
<ItemTemplate>
<%# Eval("UserName") %>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
And then bind the rptUsers during the ItemDataBound event of rptTitle...
You can do it this way. You can also use:
Labels
Span runat="server" and add them programmatically
(ghetto) string.replace