I hope that someone can help me. I've created a datagrid with a list of cities. The datagrid renders a different list depending of the button 'letter' chosen. This is working fine.
However, instead of having an endless list of cities - I would like to have a paging (10 cities by page rendered) and there is my problem, when I click on a next page, nothing happens ....
here's my code .. can anyone help me in figuring out where I do it wrong ?
Sub Page_Load(Src As Object, E As EventArgs)
If Not IsPostBack Then
End If
End Sub
sub binddata(letter)
dim myconnection as oledbconnection
myconnection= new oledbconnection(ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_Conn2"))
myconnection.open
dim mycommand as oledbcommand
mycommand = new oledbcommand("SELECT City.CityID, City.cityname, City.Country, Country.CountryName FROM Country INNER JOIN City ON Country.CountryID = City.Country WHERE ((City.Cityname) Like @City) AND ((City.Country) Like @Country) ORDER BY City.cityname",
myconnection)
Dim s As String
s = Request.QueryString("countryid")
dim ds as dataset= new dataset()
dim da as oledbdataadapter = new oledbdataadapter
da.selectcommand=mycommand
mycommand.parameters.add("@city", txtletter.text+"%")
mycommand.parameters.add("@Country", s)
da.fill(ds)
MyDataGrid.datasource = ds
MyDataGrid.databind()
end sub
sub binddata2(letter)
dim myconnection as oledbconnection
myconnection= new oledbconnection(ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_Conn2"))
myconnection.open
dim mycommand as oledbcommand
mycommand = new oledbcommand("SELECT City.CityID, City.cityname, City.Country, Country.CountryName FROM Country INNER JOIN City ON Country.CountryID = City.Country WHERE ((City.Country) Like @Country) ORDER BY City.cityname", myconnection)
Dim s As String
s = Request.QueryString("countryid")
dim ds as dataset= new dataset()
dim da as oledbdataadapter = new oledbdataadapter
da.selectcommand=mycommand
mycommand.parameters.add("@Country",s)
da.fill(ds)
MyDataGrid.datasource = ds
MyDataGrid.databind()
end sub
sub testen1 (src as object, e as eventargs)
txtletter.text=btna.text
binddata(txtletter.text)
end sub
sub testen2 (src as object, e as eventargs)
txtletter.text=btnB.text
binddata(txtletter.text)
end sub
sub testen3 (src as object, e as eventargs)
txtletter.text=btnC.text
binddata(txtletter.text)
end sub
ide m for all the other 23 letters of the alphabet :-)
sub testenAlles (src as object, e as eventargs)
txtletter.text=btnALLES.text
binddata2("City.City")
end sub
sub Page_Change (sender as object, e as datagridpagechangedeventargs)
Mydatagrid.CurrentpageIndex=e.NewPageIndex
databind
end sub
</script>
Thanks in advance
Nancy
Marked as answer by Nancita on Jun 07, 2012 03:41 PM
Hi in this case you have to store the letter in view state when user click the particular letter button. and in paging event after assigning a new page index u should call binddata(letter) sub . eg when user click button 'A' u call binddata("A") and store
A in view state , now if user click on page number again call binddata(ViewState["Letter"].ToString()) inside paging event. this will solve your problem
Try setting the DataSource to ds.Tables[0].DefaultView.
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
Nancita
Member
86 Points
53 Posts
Datagrid Paging
Apr 26, 2012 03:05 PM|LINK
Dear All,
I hope that someone can help me. I've created a datagrid with a list of cities. The datagrid renders a different list depending of the button 'letter' chosen. This is working fine.
However, instead of having an endless list of cities - I would like to have a paging (10 cities by page rendered) and there is my problem, when I click on a next page, nothing happens ....
here's my code .. can anyone help me in figuring out where I do it wrong ?
my datagrid :
<asp:DataGrid
ID="MyDatagrid"
AutoGenerateColumns="false"
AllowPaging="true"
CellPadding="3"
CellSpacing="0"
gridline="Both"
PagerStyle-Mode="NumericPages"
PagerStyle-HorizontalAlign="Center"
PagerStyle-PageButtonCount="10"
PageSize="10" runat="server"
OnPageIndexChanged="Page_Change">
<headerstyle HorizontalAlign="left" BackColor="#31317F" ForeColor="#FFFFFF" Font-Name="Trebuchet MS" Font-Bold="false" Font-Size="11" />
<itemstyle BackColor="#E9E9E7" Font-Name="Trebuchet MS" Font-Size="10" />
<alternatingitemstyle BackColor="#C8C7C3" Font-Name="Trebuchet MS" Font-Size="10" />
<footerstyle HorizontalAlign="center" BackColor="#E8EBFD" ForeColor="#3D3DB6" Font-Name="Verdana, Arial, Helvetica, sans-serif" Font-Bold="true" Font-Size="10" />
<pagerstyle BackColor="white" Font-Name="Verdana, Arial, Helvetica, sans-serif" Font-Size="10" />
<columns>
<asp:HyperLinkColumn
HeaderText="City"
Visible="True"
DataTextField="Cityname"
DataNavigateUrlField="Cityid"
DataNavigateUrlFormatString="branches.aspx?Cityid={0}"/>
</columns>
</asp:DataGrid>
my script - I am using VB
Sub Page_Load(Src As Object, E As EventArgs)
If Not IsPostBack Then
End If
End Sub
sub binddata(letter)
dim myconnection as oledbconnection
myconnection= new oledbconnection(ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_Conn2"))
myconnection.open
dim mycommand as oledbcommand
mycommand = new oledbcommand("SELECT City.CityID, City.cityname, City.Country, Country.CountryName FROM Country INNER JOIN City ON Country.CountryID = City.Country WHERE ((City.Cityname) Like @City) AND ((City.Country) Like @Country) ORDER BY City.cityname", myconnection)
Dim s As String
s = Request.QueryString("countryid")
dim ds as dataset= new dataset()
dim da as oledbdataadapter = new oledbdataadapter
da.selectcommand=mycommand
mycommand.parameters.add("@city", txtletter.text+"%")
mycommand.parameters.add("@Country", s)
da.fill(ds)
MyDataGrid.datasource = ds
MyDataGrid.databind()
end sub
sub binddata2(letter)
dim myconnection as oledbconnection
myconnection= new oledbconnection(ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_Conn2"))
myconnection.open
dim mycommand as oledbcommand
mycommand = new oledbcommand("SELECT City.CityID, City.cityname, City.Country, Country.CountryName FROM Country INNER JOIN City ON Country.CountryID = City.Country WHERE ((City.Country) Like @Country) ORDER BY City.cityname", myconnection)
Dim s As String
s = Request.QueryString("countryid")
dim ds as dataset= new dataset()
dim da as oledbdataadapter = new oledbdataadapter
da.selectcommand=mycommand
mycommand.parameters.add("@Country",s)
da.fill(ds)
MyDataGrid.datasource = ds
MyDataGrid.databind()
end sub
sub testen1 (src as object, e as eventargs)
txtletter.text=btna.text
binddata(txtletter.text)
end sub
sub testen2 (src as object, e as eventargs)
txtletter.text=btnB.text
binddata(txtletter.text)
end sub
sub testen3 (src as object, e as eventargs)
txtletter.text=btnC.text
binddata(txtletter.text)
end sub
ide m for all the other 23 letters of the alphabet :-)
sub testenAlles (src as object, e as eventargs)
txtletter.text=btnALLES.text
binddata2("City.City")
end sub
sub Page_Change (sender as object, e as datagridpagechangedeventargs)
Mydatagrid.CurrentpageIndex=e.NewPageIndex
databind
end sub
</script>
Thanks in advance
Nancy
sarathi125
Star
13599 Points
2691 Posts
Re: Datagrid Paging
Apr 26, 2012 04:03 PM|LINK
Hi Nancy,
Try this link
http://myaspsnippets.blogspot.in/2010/10/how-to-show-only-10-records-in-gridview.html
Remember to click Mark as Answer on the post that helps to others.
My Blog :MyAspSnippets
sagarbandal
Member
56 Points
10 Posts
Re: Datagrid Paging
Apr 26, 2012 04:17 PM|LINK
Hi in this case you have to store the letter in view state when user click the particular letter button. and in paging event after assigning a new page index u should call binddata(letter) sub . eg when user click button 'A' u call binddata("A") and store A in view state , now if user click on page number again call binddata(ViewState["Letter"].ToString()) inside paging event. this will solve your problem
superguppie
All-Star
48225 Points
8679 Posts
Re: Datagrid Paging
May 01, 2012 03:27 PM|LINK
Try setting the DataSource to ds.Tables[0].DefaultView.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.