I have a repeater in an ASP.NET website that I want to only show the 3 record
Repeater:
<asp:Repeater ID="repNews" runat="server" DataSourceID="EntityDataSource1">
<ItemTemplate>
<ul>
<li><a href='<%# Eval("news_link")%>' > <asp:Label ID="lblNews" runat="server" Text='<%# Eval("news_title")%>' /></a></li>
</ul>
</ItemTemplate>
and The entity Model
</asp:Repeater>
<asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=AGIP_dbEntities" DefaultContainerName="AGIP_dbEntities" EnableFlattening="False" EntitySetName="tbl_news" >
</asp:EntityDataSource>
thanks guys but i try this and this work
Select="top(2) it.news_title,it.news_link"
add it in entitydatasoruce
will be like this
<asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=AGIP_dbEntities" DefaultContainerName="AGIP_dbEntities" EnableFlattening="False" EntitySetName="tbl_news" Select="top(2) it.news_title,it.news_link">
</asp:EntityDataSource>
Related
Need a small help.
I'm having a table which is having links stored in some of the columns. I'm binding the table with a GridView present on my page. I need the cells of GridView to act as a link.
I have tried this code.
<asp:GridView runat="server" ID="gvAutomationTesting" CssClass="table table-bordered table-hover table-responsive" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Link 01" SortExpression="Link01">
<ItemTemplate>
<asp:LinkButton ID="lb01" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Link01") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The output which i'm getting is having a tag but without href attribute because of which even if i try to click it is not redirecting to the desired page.
hope below code snippets will help you, using templatefield you can assign the link button to grid column
<div>
<asp:GridView id="mygrid">
<asp:TemplateField headertext="number" datatype="string" filterexpression="CUSTOMERNUMBER"
sortexpression="CUSTOMERNUMBER">
<itemtemplate>
<asp:LinkButton ID="lnkbtn" runat="server" Text='<%# DataBinder.Eval(container.DataItem, "CUSTOMERNUMBER") %>' />
<%--CUSTOMERNUMBER is your DB column name--%>
</itemtemplate>
</asp:TemplateField>
<asp:boundfield headertext="Customer" datafield="CUSTOMERNAME" datatype="string" filterexpression="CUSTOMERNAME"
sortexpression="CUSTOMERNAME">
</asp:boundfield>
</asp:GridView>
</div>
Replace
<asp:LinkButton ID="lb01" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Link01") %>' />
by
<a ID="lb01" runat="server" href='<%# DataBinder.Eval(Container.DataItem, "Link01")' ><%# DataBinder.Eval(Container.DataItem, "Link01") %> </a>
I need help, I have a DataPager inside the update panel and and working well, but when I refresh page or going on back button form some other page DataPager reset always to the first page.
For example if I was on the tenth page and refresh page, data pager reset to first.
Is there any way to keep the current page on data pager?
My code is:
<asp:SqlDataSource ID="SqlDataSource1" EnableCaching="True" CacheDuration="4000" CacheExpirationPolicy="Sliding"
runat="server" ConnectionString="<%$ ConnectionStrings:blabla %>" SelectCommand=""></asp:SqlDataSource>
<asp:UpdatePanel ID="UpdatePanelnajgornji" runat="server" >
<ContentTemplate>
<asp:ListView ID="ListView1" runat="server" ondatabound="ListView1_DataBound" DataSourceID="SqlDataSource1">
<ItemTemplate>
<asp:HyperLink ID="HyperLink2" Visible='<%# !(Eval("Slika") is DBNull) %>' runat="server" NavigateUrl='<%# Eval("Link") %>' title='<%# Eval("Naslov") %>'>
<asp:Image ID="Image1" runat="server" AlternateText='<%# Eval("Naslov") %>' ImageUrl='<%# Eval("Slika") %>' /></asp:HyperLink>
</ItemTemplate>
</asp:ListView>
<br />
<asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1">
<Fields>
<asp:NextPreviousPagerField />
</Fields>
</asp:DataPager>
</ContentTemplate>
</asp:UpdatePanel>
Browser refresh creates new objects (and thus clears the state of the DataPager). You need to save the current page either in the Session or the ViewState, then initialize the control using those values if they exist in the codebehind. Store the values in an unload event listener.
Here is my markup:
<asp:TemplateField HeaderText="Loss" SortExpression="Loss"
HeaderStyle-CssClass="StrongText" HeaderStyle-Font-Bold="true"
HeaderStyle-Font-Size="Medium" HeaderStyle-ForeColor="Blue"
HeaderStyle-Font-Underline="true" HeaderStyle-VerticalAlign="Bottom"
ItemStyle-Width="3%" ItemStyle-HorizontalAlign="Left"
ItemStyle-VerticalAlign="Bottom" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:HyperLink runat="server" ID="HyperLink8"
NavigateUrl='<%#"db_LossofPay.aspx?UserID="+ Eval("User ID")%>'
Text='<%# Eval("Loss","{0}")%>'
ForeColor="BLUE" Target="_blank"></asp:HyperLink>
<asp:Label ID="lblLoss" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Could you please help me with this? In BoundField I wrote DataFormatString="{0:N2}" which works fine, but I got stuck when using in hyperlink (template field)
Try with this:
<asp:HyperLink runat="server" ID="HyperLink8"
NavigateUrl='<%#"db_LossofPay.aspx?UserID="+ Eval("User ID")%>'
Text='<%# Eval("Loss","{0:#,##0.00}") %>' ForeColor="BLUE" Target="_blank" />
Try
Text='<%# String.Format("{0:N2}", DataBinder.Eval(Container.DataItem, "Loss"))%>'
Like the title says, i would like to bind data from my usercontrol to my page's EntityDataSource. I tried this:
in my user control:
<asp:Textbox runat="server" id="mytxtbox" Text='<%# Bind("myField") %>
In my asp page:
<% Register TagPrefix="uc" TagName="myControl" src="~/MyControl.ascx" %>
...
<asp:EntityDataSource ID="EDS" runat="server" ....></asp:EntityDataSource
<asp:FormView id="FormView1" runat="server" DataKeyNames="id" DataSourceId="EDS">
<EditItemTemplate>
<uc:myControl runat="server" id="customControl"/>
...
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
<uc:myControl runat="server" id="customControl"/>
...
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
<uc:myControl runat="server" id="customControl"/>
...
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" />
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete"/>
</ItemTemplate>
</asp:formview>
Using this method, i was able to display my user control's fields properly (with the appropriate content from by database), but i cannot insert/Update data.
Have your tried detailsview/gridview in VS2010. I use gridview to display and then link it to detailsview by passing value where I can edit/delete records in VS2010.
This can be a big help
Click here
Also, check this out Click
1 I suggest you to find your control on Page_Init, so you pass your DataSource (DataTable or other)
var control = (UserControl)this.FindControl("id");
control.Property = .....;
2 You declare for example an public property on your control
3 And you bind your control in his code behind.
Nota : If you have grid control in your userControl you can use ItemDataBound
I am rendering data using Repeater control.
Let's say there are 2 fields in the data source: productName and ProductID
In the following code:
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<%#Eval("productName")%> <br/>
<asp:HyperLink ID="lnkDetails" runat="server" NavigateUrl="~/Details.aspx?ID=">See Details</asp:HyperLink>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
What do I need to modify in
<asp:HyperLink ID="lnkDetails" runat="server" NavigateUrl="~/Details.aspx?ID=">See Details</asp:HyperLink>
to include value retreived from the ProductID in the link NavigateUrl="~/Details.aspx?ID="
NavigateUrl="~/Details.aspx?ID=<%# Eval("productID") %>" should work...
... but it doesn't!
The most elegant way should be:
<asp:HyperLink ID="lnkDetails" runat="server" NavigateUrl='<%# Eval("ProductID", "~/Details.aspx?ID={0}") %>'>See Details</asp:HyperLink>