How To give Pagination to asp:DataList - c#

This is my ASPX code, however, I can't see any way to do Pagination
<asp:DataList ID="dlProjectImages" runat="server" RepeatColumns="3"
RepeatLayout="Table" RepeatDirection="Horizontal" BorderWidth="0px"
HorizontalAlign="Center" >
<ItemStyle />
<ItemTemplate>
<table border="0" cellpadding="0" border="0" align="center" valign="top">
<tr>
<td width="16" align="center" valign="top"></td>
<td width="169" height="132" align="center" valign="middle" class="top-links01">
<a href="Project_Details.aspx?id_Project=<%# Eval("id_Project")%>&type=<%= Request.Params["type"]%>&activity=<%=Request.Params["activity"]%>">
<img id="findme" alt="" height="114" src="<%# Eval("Thumbnail_Image") %>" title="Click To View Project Details" border="0" /></a>
</td>
<td width="16" align="center" valign="top"></td>
</tr>
<tr>
<td align="center" valign="top" colspan="3">
<asp:Label ID="lblProject_name" Font-Bold="true" Text='<%# Eval("Project_Name") %>' CssClass="top-links01" runat="server"></asp:Label><br />
</td>
</tr>
<tr>
<td colspan="3" align="center"><img src="/images/clear.gif" border="0" height="20px" /></td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
What am I missing that will allow me to do pagination?

You can use PagedDataSource to page a data-list. See this article which explain the same in detail.
On the related note, why not use ListView instead - it can be used with DataPager for paging and offers complete control over the markup generated.

Mayu,
I don't think you can do pagination using DataList. You either have to implement it manually by following the article link mentioned by VinayC or switch to GridView as it does pagination for you.
Look at this MSDN documentation

Related

How to keep two buttons for two different functions in an ASP.NET web page?

I want to make a website. Following screenshot are of my Login/Signup link page. When I'm clicking on Login button without giving any data, it is showing me an ALERT. Its OK. But the problem is that, when I'm pressing Register button to go to Signup/Registration page, at that time "Text Boxes" is also showing me this validation. That's why I'm unable to go to Signup/Registration page.
<table id="Table2" runat="server" align="center" style="margin-top:15px; width:72%; height:170px">
<tr style="text-align:center; width:80%; height:8px;">
<td style="font-size:medium; font-family:Courier New; font-weight:bold ;color:#000000; text-align:left ; width:20%; height:8px;">Mobile No</td>
<td style=" width:40%;height:8px"><input type="number" id="mobnum" runat="server" style="width:70%; height:23px" required="required" /></td>
</tr>
<tr style="text-align:center; width:80%; height:8px">
<td style="font-size:medium; font-family:Courier New; font-weight:bold ;color:#000000; text-align:left ; width:30%; height:8px">Password</td>
<td style="width:50%; height:8px"><asp:TextBox id="TextBox8" runat="server" style="width:70%; height:23px;" TextMode="Password" re ></asp:TextBox></td>
</tr>
<tr style="text-align:center; width:80%; height:29px">
<td style="width:30%; height:29px"></td>
<td style="width:50%; height:29px"><asp:Button ID="Button2" runat="server" ValidationGroup="IsValid" height="30px" width="100px" BackColor="#006400" BorderColor="White" BorderStyle="None" ForeColor="White" Text="Login" Font-Bold="true" /></td>
</tr>
</table>
<table id="Table4" runat="server" align="center" style="margin-top:15px; width: 72%; height:170px">
<tr style="text-align:center; width:100%; height:8px;">
<td style="width:100%; height:10px; text-align:center"><asp:Button ID="Button1" runat="server" PostBackUrl="~/Signup.aspx" CausesValidation="false" height="30px" width="100px" BackColor="#006400" BorderColor="White" BorderStyle="None" ForeColor="White" Text="Register" Font-Bold="true" OnClick="Button1_Click" /></td>
</tr>
<tr style="text-align:center; width:80%; height:22px;">
<td style="width:100%; height:22px"></td>
</tr>
</table>
You need to group those validations per page (or) based on different actions. In essence you should look for Specifying Validation Groups
There are two ways you can handle this situation;
1. In regester/signup button set CauseValidation to false.
Set ValidationGroup property of Login button and give same ValidationGroup name to all validators.
Just add the attribute CausesValidation="false" to your Register button.
Like this
<asp:Button runat="server" OnClick="OnClick" CausesValidation="false"/>
That will skip any validation on your page and allow you to go to your registration page.

asp.net how to pass list of items to eval function?

this is my code to view products as list view inside each item in list view i want to view list of items how can i do this? i can not understand the concept of the eval function and i want to know if i can pass to it list items from code behind without data Bind or it basically depends on data-bind ?
<asp:ListView ID="mylistView" runat="server" GroupItemCount="3">
<EmptyDataTemplate>
<table id="Table2" runat="server">
<tr>
<td>
No data was returned.
</td>
</tr>
</table>
</EmptyDataTemplate>
<EmptyItemTemplate>
<td id="Td3" runat="server" />
</EmptyItemTemplate>
<GroupTemplate>
<tr id="itemPlaceholderContainer" runat="server">
<td id="itemPlaceholder" runat="server">
</td>
</tr>
</GroupTemplate>
<ItemTemplate>
<table border="0" width="300" style="display: inline-block; background-color: Lime;">
<tr>
<td>
&nbsp
</td>
<td>
<a href='ContactUs.aspx'>
<image src='productsImg/<%# Eval("Pic_Path") %>' width="100" height="75" border="0">
</a>&nbsp
</td>
<td>
<a><b style="text-decoration: underline;">
<%# Eval("MenuName") %></b> </a>
<br />
want to view here list of items
I
</td>
</tr>
</table>
</ItemTemplate>
<LayoutTemplate>
<table id="Table1" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table id="groupPlaceholderContainer" runat="server">
<tr id="groupPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr id="Tr2" runat="server">
<td id="Td2" runat="server">
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
this is code behind...
dataSource.ConnectionString = connetionString;
dataSource.SelectCommand = "SELECT * FROM tbl_WebMenu where MenuID like'3_';";
mylistView.DataSource = dataSource;
mylistView.DataBind();
thanks in advance.
Eval is used to bind to an UI control that is supposedly read only. it can be used to set any type of property of control.
The complete syntax is "Databinder.Eval", it has to be used in conjunction with databind.
Look at this example.
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblRead" runat="server" Text='<%# Eval("FieldName") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
you can even set a property of control using eval. it provides flexibility.
But there is a downside of eval as it uses reflection to evaluate the expression.
Read more here http://msdn.microsoft.com/en-us/library/4hx47hfe.aspx#remarksToggle

The TargetControlID of 'HoverMenuExtender2' is not valid. A control with ID 'cable' could not be found

When I am applying the column ID into targetconrtolID of Hovermenuextender its not working and error coming is
The TargetControlID of 'HoverMenuExtender2' is not valid. A control with ID 'cable' could not be found.
I need to display my sub menu on the column ending
the code written is here
<cc1:HoverMenuExtender ID="HoverMenuExtender2" runat="server" PopupControlID="ProjectMenu" TargetControlID="cable" PopupPosition="Bottom" >
</cc1:HoverMenuExtender>
<td align="center" style="border: medium solid White" class="style5" id="cable">
<asp:LinkButton ID="lblmenudashboard" runat="server" Font-Bold="False" Font-Underline="False"
ForeColor="white" OnClick="lblmenudashboard_Click">Dashboard</asp:LinkButton>
</td>
<asp:Panel ID="ProjectMenu" runat="server" Visible="true" Width="210px">
<table cellpadding="0" cellspacing="0" class="style8" align="center">
<tr>
<td align="center">
<asp:LinkButton ID="lblsubMenu_Star" runat="server" Font-Bold="False" Font-Underline="False"
ForeColor="white"> Project0</asp:LinkButton>
</td>
</tr>
<tr>
<td align="center">
<asp:LinkButton ID="lblsubMenu_Udaan" runat="server" Font-Bold="False" Font-Underline="False"
ForeColor="white"> Project1</asp:LinkButton>
</td>
</tr>
</table>
</asp:Panel>
I have applied the scriptManager. Also Let me know how can I select that hovermenu so that I can open tab from their itself.

ValidatorCalloutExtender and ModalPopupExtender Issues on MasterPage

I have just created a website with a MasterPage. I have two conditions that will illustrate my problem:
Condition 1:
I have added a ModalPopupExtender on website.master. It has three fields and each field has a RequiredFieldValidator and a ValidatorCalloutExtender.
Condition 2:
I have a few different pages where you can click on a registration link. When you click the registration link, a registration form will appear. This form also has RequiredFieldValidators and ValidatorCalloutExtenders for each field.
Problem:
If I open a registration form and want to place my feedback, I click on the feedback button. The feedback modal popup displays. If I click on the submit button without filling the feedback form, it should give me the error in ValidatorCalloutExtender format on the ModalPopupExtender panel. However, it doesnt show me any error but the ValidatorCalloutExtender does show on the registation form along with respective validation.
<cc1:ModalPopupExtender CancelControlID="lnk_cancel" ID="popup_change_password" BackgroundCssClass="modalBackground"
runat="server" TargetControlID="ImageButton1" PopupControlID="panel_change_password">
</cc1:ModalPopupExtender>
<asp:Panel ID="panel_change_password" runat="server" Style="display: none; height: 400px;
width: 400px; padding-left:30px; background-repeat:no-repeat;" BackImageUrl="~/Images/background.gif">
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td colspan="3" valign="top">
<table cellpadding="0" cellspacing="0" width="400px">
<tr>
<td align="right">
<asp:ImageButton ID="lnk_cancel" runat="server" ImageUrl="Images/close.gif" Height="30px"
Width="30px" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="lbl_new_password" runat="server" Text="Your feedback is important to us."
CssClass="login_font1"></asp:Label>
</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>
<tr>
<td>
<asp:Label ID="lbl_name" runat="server" Text="Name" CssClass="Label_Styles"></asp:Label>
</td>
<td>
:
</td>
<td>
<asp:TextBox ID="txt_name" runat="server" CssClass="Textbox_Styles"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>
<tr>
<td>
<asp:Label ID="lbl_email" runat="server" Text="Email Address" CssClass="Label_Styles"></asp:Label>
</td>
<td>
:
</td>
<td>
<asp:TextBox ID="txt_email" runat="server" CssClass="Textbox_Styles"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>
<tr>
<td>
<asp:Label ID="lbl_comment" runat="server" Text="Comments" CssClass="Label_Styles"></asp:Label>
</td>
<td>
:
</td>
<td>
<asp:TextBox ID="txt_comment" runat="server" CssClass="Textbox_Styles" Height="120px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>
</table>
</asp:Panel>
Put the above code in an UpdatePanel with UpdateMode="Conditional" and ChildrenAsTriggers="False".
So it will look something like :
<asp:UpdatePanel ID="sbsModalExtenderUpdatePanel" runat="server" UpdateMode="Conditional"
Visible="False" ChildrenAsTriggers="False">
<ContentTemplate>
<asp:Panel ID="StepByStepBookingPanel" runat="server" Enabled="false" EnableViewState="false"
Style="display: block" CssClass="mediumModalPopup" ScrollBars="Auto" Width="800px"
Height="300px" ViewStateMode="Enabled">
<div id="clientCoordDiv" runat="server">
<table id="StepByStepTable" runat="server">
etc...
</table>
</div>
</asp:Panel>
<ajax:ModalPopupExtender ID="mpeStepByStepBooking" runat="server" BackgroundCssClass="modalBackground"
PopupControlID="StepByStepBookingPanel" CancelControlID="BtnCancel" OnCancelScript="ClearStepByStepPopup"
TargetControlID="hdnStepByStepButton" DropShadow="true" BehaviorID="modalwithinput" />
<asp:CompareValidator ID="ClientCoordinatorCompareValidator" runat="server" ErrorMessage="Please select a Client Coordinator"
ControlToValidate="ddlClientCoordinator" Display="None" Operator="NotEqual" SetFocusOnError="True"
Type="Integer" ValueToCompare="0" ValidationGroup="SelectionRequired">
</asp:CompareValidator>
<asp:CompareValidator ID="CVOCoordinatorCompareValidator" runat="server" ErrorMessage="Please select a CVO Coordinator"
ControlToValidate="ddlCVOCoordinator" Display="None" Operator="NotEqual" ValueToCompare="0"
Type="Integer" SetFocusOnError="True" ValidationGroup="SelectionRequired">
</asp:CompareValidator>
<ajax:ValidatorCalloutExtender ID="CompareClientCoordinatorExt" runat="server" Enabled="True"
TargetControlID="ClientCoordinatorCompareValidator" BehaviorID="ClientValidatorExt">
</ajax:ValidatorCalloutExtender>
<ajax:ValidatorCalloutExtender ID="CVOCoordinatorCompareValidatorExt" BehaviorID="CVOValidatorExt"
runat="server" Enabled="True" TargetControlID="CVOCoordinatorCompareValidator">
</ajax:ValidatorCalloutExtender>
</ContentTemplate>
</asp:UpdatePanel>
This will keep the dialog up while you validate it. Unfortunately, I do not have the full solution since my validator messages are not displaying. So far, from what I am getting on the Net it is a problem with the Ajax library. Ugly!
Oh well, hope this helps someone...

FileUpload not working in update panel(modal popup extender)

i am developing web application and contain modal popup extender in which update panel made and it contain file upload control but file upload control not working in it.
This is my modal popup which contain fileupload control
and my modal popup source code
<cc1:ModalPopupExtender ID="AddNews" runat="server" PopupControlID="pnlPopUp1" BehaviorID="AddNews"
TargetControlID="btnNews" BackgroundCssClass="modalBackground">
</cc1:ModalPopupExtender>
<asp:Panel ID="pnlPopUp1" runat="server" CssClass="modalPopup" Height="450px" Width="660px"
Style="display:none; z-index: 100000">
<asp:UpdatePanel ID="Upanel1" runat="server">
<ContentTemplate>
<div>
<table cellpadding="0" cellspacing="0" width="100%">
<tr style="height: 35px;">
<td style="width:170px">
</td>
<td style="text-align: center">
<h1>
Add News</h1>
</td>
<td style="text-align: right">
<asp:ImageButton ID="ImageButton2" AlternateText="Close Image" runat="server" ImageUrl="~/images/delete_32i.GIF"
OnClientClick="return closePopup('News')" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblAddNewsError" runat="server" Text="" ForeColor="Red"></asp:Label>
</td>
</tr>
<tr>
<td>News Title:</td><td>
<asp:TextBox ID="txtNewTitle" Width="250px" runat="server" MaxLength="500"></asp:TextBox>
</td><td>
<asp:RequiredFieldValidator ID="rfvNewsTitle" runat="server"
ControlToValidate="txtNewTitle" ErrorMessage="*" ToolTip="Enter news title"
ValidationGroup="AddNews"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Upload News Video</td><td>
<asp:FileUpload ID="FileUpload1" runat="server" />
</td><td><asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server" ControlToValidate="FileUpload1"
ErrorMessage="Invalid video File"
ValidationExpression="^([0-9a-zA-Z_\-~ :\\])+(.avi|.AVI|.wmv|.WMV|.flv|.FLV|.mpg|.MPG|.mp4|.MP4)$"
ToolTip="Only allow avi, wmv, flv, mpg, mp4 formats video files"
ValidationGroup="AddNews"></asp:RegularExpressionValidator></td>
</tr>
<tr style="height: 5px">
<td>
</td>
</tr>
</table>
<div>
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="width: 675px">
<FCKeditorV2:FCKeditor ID="FCKAddNewsContent" basepath="~/fckeditor/" runat="server" Height="300px"></FCKeditorV2:FCKeditor>
</td>
<td valign="top">
</td>
</tr>
<tr>
<td style="text-align:right">
<asp:Button ID="btnAddNews" runat="server" Text="Add News"
onclick="btnAddNews_Click" ValidationGroup="AddNews" />
<asp:Button ID="btnClose"
runat="server" Text="Close" OnClientClick="return closePopup('News')"
CausesValidation="False" /></td><td></td>
</tr>
</table>
</div>
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnAddNews" />
</Triggers>
</asp:UpdatePanel>
</asp:Panel>
as you see my one button also mentioned in postback trigger as i click on this button the result which i got is
can anyone help me out from this problem.
only one thing i just need in web.config and make it working
<httpRuntime executionTimeout="90" maxRequestLength="2000000" useFullyQualifiedRedirectUrl="false" requestLengthDiskThreshold="8192"/>
Point up my answer if you got your solution.
You can set Triggers on update panel. After that you can get file at server side.
<Triggers>
<ajax:PostBackTrigger ControlID="btnAddNews" />
</Triggers>
Hope it will help.

Categories