SelectCommand="SELECT TOP 4[Id], [Date], [Title], [PictureUrl], [Description],[VideoUrl], [Author], [Type] FROM [News] ORDER BY [Date] DESC , [Id] DESC">
</asp:SqlDataSource>
I would like to use a button which will enables the Datalist to display 8items.
Well, the problem is with your query itself. You are asking for only the top four records. Why do you want 4 empty rows in your datalist? If you want 8, then SELECT TOP 8. Am I understanding you correctly or are you trying to do something else?
But I want to have a button "More Titles" when clicked on this button, the Datalist will display 8Items instead of 4items
Hello,
I think since you wanna dynamically change your SQL statement——you have to dynamically databind to the data presentation control by referring this below:
1)Remove using DataSource first.
2)Then you should dynamically data-binding in the button's click:
using(SqlDataAdapter adapter = new SqlDataAdapter("select TOP 8 * from xxx","connection string here"))
{
DataTable dt = new DataTable();
adapter.Fill(dt);
//Do binding……
}
Marked as answer by Gracien on Nov 27, 2012 04:27 PM
Gracien
Member
42 Points
125 Posts
SelectCommand
Nov 26, 2012 05:52 PM|LINK
Hi
I'm displaying 4items on a datalist using the SqlDataSource
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:News %>"
SelectCommand="SELECT TOP 4[Id], [Date], [Title], [PictureUrl], [Description],[VideoUrl], [Author], [Type] FROM [News] ORDER BY [Date] DESC , [Id] DESC">
</asp:SqlDataSource>
I would like to use a button which will enables the Datalist to display 8items.
Any idea about how to do this?
protected void MoreTitle_Click(object sender, EventArgs e)
{
// any codes here?
}
bbcompent1
All-Star
32992 Points
8508 Posts
Moderator
Re: SelectCommand
Nov 26, 2012 06:00 PM|LINK
Well, the problem is with your query itself. You are asking for only the top four records. Why do you want 4 empty rows in your datalist? If you want 8, then SELECT TOP 8. Am I understanding you correctly or are you trying to do something else?
Gracien
Member
42 Points
125 Posts
Re: SelectCommand
Nov 26, 2012 06:24 PM|LINK
something else
for the moment i'm displaying the 2items without any problem.
But I want to have a button "More Titles" when clicked on this button, the Datalist will display 8Items instead of 4items
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: SelectCommand
Nov 27, 2012 05:49 AM|LINK
Hello,
I think since you wanna dynamically change your SQL statement——you have to dynamically databind to the data presentation control by referring this below:
1)Remove using DataSource first.
2)Then you should dynamically data-binding in the button's click:
using(SqlDataAdapter adapter = new SqlDataAdapter("select TOP 8 * from xxx","connection string here")) { DataTable dt = new DataTable(); adapter.Fill(dt); //Do binding…… }