My goal is to nest a Repeater inside an ASP.Net AJAX Accordion's AccordionPane.
So there is one Accordion which I am programmatically adding AccordionPanes to. The amount of panes I add depends on my particular dataset's count value, usually no more than 5. I've managed to do this successfully.
The thing I am having difficulty with is creating and adding a Repeater per each AccordionPane.
I've glanced over http://iridescence.no/post/Using-Templated-Controls-Programmatically.aspx but this is not exactly what I had in mind. Instead, I would rather declare a single Repeater as static HTML that I could then "clone" when I need. How can I achieve this? Obviously I would want each control's ID (within this declared Repeater) to be generated automatically each time i "clone" it.
The repeater looks like this:
<asp:Repeater ID="rptForum" runat="server">
<ItemTemplate>
<div runat="server" style="border:solid #d3d3d3 1px; border-bottom-width:0px;">
<table width="100%">
<tr><td align="left">
<asp:Label runat="server" Font-Size="12px" />
</td></tr>
<tr><td align="left">
>> <asp:Label runat="server" Font-Size="12px" Text='<%# Eval("query") %>' />
</td></tr>
</table>
</div>
</ItemTemplate>
</asp:Repeater>
I might add more fields to be databound as I progress.
Any ideas appreciated..
You should be able to do that by adding the repeater to the Content template:
<cc1:AccordionPane ID="AccordionPane1" runat="server">
<Header>
Foo
</Header>
<Content>
<asp:Repeater ID="Repeater1" runat="server" ...>
...
</asp:Repeater>
</Content>
</cc1:AccordionPane>
You can do a hierarchical data bind with the accordion, as illustrated here: http://aspalliance.com/1674_complex_data_binding_with_the_accordion_control
Related
I dont know if the my question is good or bad or duplicate but I really want to ask you a favor.
My designer gave me grid design using html tables which looks quite handsome but when I use the same css classes in asp gridview it totally looks different.
Additional Info: In my project I have used Telerik grids. I have tried applying all the css at that too but of no use.
I cant change the designer css because its for all our company.
Now at last I want to use the same table as designer gave me and use it as grid but i really dont know how to fill it from datatable?
1. GridView generates/renders code in which it is difficult to impossible to modify.
2. I would stay away from Telerik as well.
3. Use Bootstrap CSS, you should be very happy with bootstrap css framework as you will get that look above very easily.
With Bootstrap you would use classes like class=table table-striped and you effectively have a nice grid with alternating row colors just like I see in the image that you posted.
With ASP.NET , use Nuget and install Bootstrap. Reference in Masterpage or layout.
I assume that you have styles that overwrite what your designer gave to you. Perhaps also if you are using THEIR stylesheets, make sure to overwrite the default styles. Either OMIT the style reference in master page etc... or place their stylesheet references below the default in say a asp.net web forms or mvc application. ( I assume web forms with masterpage since you are saying Gridview).
You can use ListView to include components. here is the example code for ListView.
<asp:ListView ID="ListView1" GroupPlaceholderID="group" GroupItemCount="1" ItemPlaceholderID="item" runat="server">
<LayoutTemplate>
<table>
<asp:PlaceHolder runat="server" ID="group"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr>
<asp:PlaceHolder runat="server" ID="item"></asp:PlaceHolder>
</tr>
</GroupTemplate>
<ItemTemplate>
<td>
<table cellpadding="2" cellspacing="0" border="1" style="width: 200px; height: 100px">
<tr>
<td>
<span>
<%# Eval("Id") %>
</span>
</td>
</tr>
<tr>
<td>
Name: <span><%# Eval("Field_name_of_your_DB") %></span><br />
Number: <span><%# Eval("Field_name_of_your_DB") %></span><br />
Date: <span><%# Eval("Field_name_of_your_DB", "{0:MM dd, yyyy}") %></span><br />
Comment: <span><%# Eval("Field_name_of_your_DB") %></span><br />
</td>
</tr>
</table>
</td>
</ItemTemplate>
</asp:ListView>
sorry in advance I have searched the whole site but I can not find an answer to this question
I plan to use the listview with checkboxes in every item and one delete button so that I can do a removal to multiple row at once, is there any way that I can start this work?
this is my current code
<asp:ListView ID="ListInbox" runat="server" DataKeyNames="MessageID"
DataSourceID="LinqDataSourceInbox" >
<EmptyDataTemplate>
There is no message
</EmptyDataTemplate>
<ItemTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<asp:CheckBox ID="CheckBoxSelect" runat="server" />
</td>
<td runat="server">
<asp:Panel ID="PanelMsg" runat="server" Width="400px">
<a href='UserProfile.aspx?UserName=<%# Eval("FromUserName") %>'><img src="ProfilePic/<%#Eval("User.ProfilePic") %>" alt='' width="25" /></a>
<a href='UserProfile.aspx?UserName=<%# Eval("FromUserName") %>'><%# Eval("FromUserName") %></a>
write you message:
<a href='ViewMessages.aspx?MsgID=<%# Eval("MessageID") %>'><%# Eval("Subject") %></a>
<%# Eval("MessageTime") %>
</asp:Panel>
</td>
</tr>
</table>
<hr style="text-align:left; width:400px;" />
</ItemTemplate>
<LayoutTemplate>
<div style="min-height:450px;">
<div runat="server" id="itemPlaceholder">
</div>
</div>
</LayoutTemplate>
</asp:ListView>
The questions are
Where the CheckBox put? Selected/Item template?
Where the Delete Button put? Inside/Outside ListView?
Thx in advance..
We do smth similar with a GridView backed with a DataTable, I suppose I can give you a general idea and you can do smth similar.
Create a flag column/ field. e.g: User.SetToDelete
onCheckChanged set this flag to true.
Upon Click of the delete button, iterate the rows and look for items set to be deleted.
As for the suggestion for a simple GUI:
Hope it helps.
I am working with a two nested data repeaters, and I want to allow paging for the outer repeater.
Here is what I have so far:
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="LinqDataSource1" OnItemDataBound="Repeater1_ItemDataBound">
<HeaderTemplate>
<div class="group">
</HeaderTemplate>
<ItemTemplate>
<div class="question"><%#Eval("QText") %></div>
<asp:HiddenField ID="HiddenField1" runat="server" Value='<%# setQID(Eval("QID"))%>' />
<%-- THE INNER REPEATER--%>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="LinqDataSource2">
<HeaderTemplate>
<div class="answer">
</HeaderTemplate>
<ItemTemplate>
<%# (GetAnswer(Eval("AnsQID"))) != 1 ? (displayAnswer(Eval("AText"))) : ""%>
</ItemTemplate>
<FooterTemplate>
</div>
</FooterTemplate>
</asp:Repeater>
<%-- THE INNER REPEATER ENDS HERE--%>
</ItemTemplate>
<FooterTemplate>
</div>
</FooterTemplate>
</asp:Repeater>
I have googled for this, searched everywhere and found a lot of ways to approach this. I am using LinqDatasources and two repeaters. What is the best way to do this ?
To page the outer repeater i have used the method outlined in this post in the past. I don't think it should make much difference to the outcome if your repeater is nested. Your inner repeater will count as one row.
Repeaters generally though don't have great support for paging. You could consider using ListView (if using ASP.Net 3.5 or greater) or GridView (ASP.Net 2.0 or greater) which have more support for paging out of the box.
I have used this control in my Project.
http://www.codeproject.com/KB/custom-controls/CollectionPager.aspx
optional
http://www.codeproject.com/KB/webforms/SQLPager_For_Everything.aspx
and for Nested you have to use Databoud event and bound the child repeater.
I am creating a Facebook Wall like structure and used repeater control for that using C#-Visual Studio 2010 amd Sql Server 2005 as database.
I am unable to display multiline text in repeater control
Script
<asp:TextBox ID="TextBox1" runat="server" Width="100%" TextMode="MultiLine"></asp:TextBox>
<asp:Repeater ID="myrepeater" runat="server">
<HeaderTemplate>
<table width="100%" style="font: 8pt verdana">
<tr style="background-color:#3C78C3">
<th>SCRAPS</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%#DataBinder.Eval(Container,"DataItem.scraps") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
So, When I click on submit button, text stores in DataItem.scraps (which is column in my database table) and displays in repeater control.
But when I am inputting multiline Text in Textbox, it is displayed singleline in repeater control.
I want it to be displayed multiline repeater control.
So what is the problem exactly
1) Is it storing singleline text in database
2) or, repeater control problem
And, how to resolve it?
Please help me.
Thanks in advance,
Nikhil
The repeater control is pretty straight forward. There is no reason you can't control your output very thoroughly, just put everything in your item template:
<asp:Repeater ID="rptWall" runat="server">
<HeaderTemplate>
<h1>The wall<h1>
</HeaderTemplate>
<ItemTemplate>
<hr>
<asp:TextBox id="txtPost" runat="server" textmode="multiline" text='<%#DataBinder.Eval(Container.DataItem, "Posttext")%>'></asp:TextBox>
<hr>
</ItemTemplate>
<FooterTemplate>
<h3>put stuff here to add post</h3>
</FooterTemplate>
</asp:Repeater>
In php you can have the serverside script print back a block of formatted code by using something like
print <<<HERE
<code>
<somemorecode></somemorecode>
</code>
HERE;
What is the asp equivalent (C#)??
It doesn't seem to like when I don't keep all of the string on one line and i'd like to avoid having to concatenate everything as it kind of kills the purpose of preserving the formatting for readability. Here's what I have that it isn't liking. i know why its doing it, but I'd like to know how to achieve what you can in php:
<%
for(int i = 20; i<21;i++){
Response.Write("
<tr>
<td class="style1">
<asp:DropDownList ID="docNumber" runat="server" />
</td>
<td class="style1">
<asp:Label ID="Label1" runat="server" Text="This would be the title of the document." /></td>
<td class="style1">#</td>
<td class="style1">
<asp:DropDownList ID="supervisorName" runat="server" />
</td>
</tr>");
%>
This isn't for anything anyone will ever see. I'm just trying to build a throw away data entry page for myself.
update: nevermind... i just realized this isn't going to work for me as it will duplicate each control id. fail.
At any rate, for future reference. is there a way to do what i was trying to do as far as the code blocks go?
You might consider using an <asp:Repeater /> for this purpose:
<asp:Repeater runat="server" id="repeater1">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td class="style1">
<asp:DropDownList ID="docNumber" runat="server" /></td>
<td class="style1">
<asp:Label ID="Label1" runat="server"
Text="<%# Container.DataItem("DocTitle") %>"/></td>
<td class="style1">#</td>
<td class="style1">
<asp:DropDownList ID="supervisorName" runat="server" /></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
In your code behind, you would then bind this to a list or datasource on page load (or where ever appropriate). Finally check out the ondataitembound action for custom handling of each item as it's bound.
MSDN Repeater - Everything you need to know
<%= Some String Expression Here %>
or
<% code with Response.Write("some string"); %>
the first is better if you want to print a single statement. The second is better if you have more than one expression that prints stuff (if you use loops, if/else, etc.)
Keep in mind that this is considered bad practice and is frowned upon in the ASP.NET Web Forms world. You should be using controls.
If you want to create some more complex layout that repeats something you should use databound controls. For tables use the GridView control, for list of options use DropDownList and for other things use layout use the ListView control (you can use it for tables too). These controls use default formatting or template for each item and are bound to a collection of items via code behind. All this is for ASP.NET Web Forms. If you are using ASP.NET MVC things are done differently.