i have a datalist with paging on products page (please see code below) when user clicks any product on product page he is directed to productdescription page which has a back button which will take the user back to the previous page. My problem is when i
click a product in the secondpage of productspage i am redirected to productdescription page now the problem comes when i click the back button to go back i keep getting error page not found. the back button works fine for any product listed in firstpage of
products page. I hope i have explained in detail. And also can you tell me how to do paging in datalist using page numbers like (1,2,3,4) what i have now has (First, Next, Prevoius, Last) which i wanted to change to number list if possible
Me.DataList1.DataSource = mydt
Me.DataList1.DataBind() End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Page.IsPostBack Then BindData()
End If
End Sub
Protected Sub dgPager_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
e.Item.Visible = False
End If
End Sub
Protected Sub dgPager_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Me.dgPager.CurrentPageIndex = e.NewPageIndex
BindData()
End Sub ASPX page
Lorenzo Battaglia
Ceo President, LandLogic IT s.r.l.
Address : via G. Di Vittorio 29
City: Corato (Bari) Italy
Postal Code: 70033
Web: http://www.landlogic.it
Support: http://assistenza.landlogic.it
Me.DataList1.DataSource = mydt
Me.DataList1.DataBind() End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Page.IsPostBack Then BindData()
End If
End Sub
Protected Sub dgPager_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
e.Item.Visible = False
End If
End Sub
Protected Sub dgPager_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Me.dgPager.CurrentPageIndex = e.NewPageIndex
BindData()
End Sub ASPX page
Lorenzo Battaglia
Ceo President, LandLogic IT s.r.l.
Address : via G. Di Vittorio 29
City: Corato (Bari) Italy
Postal Code: 70033
Web: http://www.landlogic.it
Support: http://assistenza.landlogic.it
I am getting an error on this line (Compiler Error Message: CS1502: The best overloaded method match for 'System.Data.Common.DbDataAdapter.Fill(System.Data.DataTable, System.Data.IDbCommand, System.Data.CommandBehavior)' has some invalid
arguments). Where i am going wrong?
Lorenzo Battaglia
Ceo President, LandLogic IT s.r.l.
Address : via G. Di Vittorio 29
City: Corato (Bari) Italy
Postal Code: 70033
Web: http://www.landlogic.it
Support: http://assistenza.landlogic.it
I figured that out see below, but iam getting error in this line
if (e.Row.RowType == ListItemType.Item | e.Row.RowType == ListItemType.AlternatingItem)
error (CS0019: Operator '==' cannot be applied to operands of type 'System.Web.UI.WebControls.DataControlRowType' and 'System.Web.UI.WebControls.ListItemType')
Sharonrao123
Member
32 Points
268 Posts
Number paging Datalist problem
Mar 08, 2007 06:30 AM|LINK
Hello All,
i have a datalist with paging on products page (please see code below) when user clicks any product on product page he is directed to productdescription page which has a back button which will take the user back to the previous page. My problem is when i click a product in the secondpage of productspage i am redirected to productdescription page now the problem comes when i click the back button to go back i keep getting error page not found. the back button works fine for any product listed in firstpage of products page. I hope i have explained in detail. And also can you tell me how to do paging in datalist using page numbers like (1,2,3,4) what i have now has (First, Next, Prevoius, Last) which i wanted to change to number list if possible
Cheers, Shilpa.
code for datapaging:
public
partial class products_1 : System.Web.UI.Page{
_data a = new _data();
int CategoryID = 1;
protected void Page_Load(object sender, EventArgs e){
if (Request.QueryString["p"] != null){
CategoryID =
Convert.ToInt32(Request.QueryString["p"].ToString());}
if (!(IsPostBack)){
intPageSize.Text =
"8";intCurrIndex.Text =
"0";DisplayProducts(CategoryID);
DisplayCategory(CategoryID);
}
//string VisitorID = Session["VisitorID"].ToString();
//lblVisitorID.Text = VisitorID.ToString();
//lblVisitorID.Text = Request.Cookies["HttpBrowserCookieCheck"].Value.ToString();}
protected void DisplayProducts(int cid){
DataSet ProductList = new DataSet();System.Data.SqlClient.
SqlConnection Con = new System.Data.SqlClient.SqlConnection();Con.ConnectionString =
ConfigurationManager.AppSettings["ConnectionString"];
string cmd = "Exec dbo.BMC_Display_ProductList " + cid;Con.Open();
System.Data.SqlClient.
SqlCommand Cmd = new System.Data.SqlClient.SqlCommand(cmd, Con);
SqlDataAdapter da = new SqlDataAdapter(Cmd);
//if (!(IsPostBack))
//{da.Fill(ProductList);
intRecordCount.Text = ProductList.Tables[0].Rows.Count.ToString();
ProductList =
null;ProductList =
new DataSet();
//}da.Fill(ProductList,
Int32.Parse(intCurrIndex.Text), Int32.Parse(intPageSize.Text), "BMC_t_Product");dList.DataSource = ProductList.Tables[0].DefaultView;
dList.DataBind();
PrintStatus();
if (Con.State == ConnectionState.Open)Con.Close();
Cmd =
null;Con =
null;}
protected void ShowFirst(object sender, EventArgs e){
intCurrIndex.Text =
"0";DisplayProducts(CategoryID);
}
protected void ShowPrevious(object sender, EventArgs e){
intCurrIndex.Text =
Convert.ToString(Int32.Parse(intCurrIndex.Text) - Int32.Parse(intPageSize.Text));
if (Int32.Parse(intCurrIndex.Text) < 0){
intCurrIndex.Text =
"0";}
DisplayProducts(CategoryID);
}
protected void ShowNext(object sender, EventArgs e){
if (Int32.Parse(intCurrIndex.Text) + 1 < Int32.Parse(intRecordCount.Text)){
intCurrIndex.Text =
Convert.ToString(Int32.Parse(intCurrIndex.Text) + Int32.Parse(intPageSize.Text));}
DisplayProducts(CategoryID);
}
protected void ShowLast(object sender, EventArgs e){
int tmpInt;tmpInt =
Int32.Parse(intRecordCount.Text) % Int32.Parse(intPageSize.Text);
if (tmpInt > 0){
intCurrIndex.Text =
Convert.ToString(Int32.Parse(intRecordCount.Text) - tmpInt);}
else{
intCurrIndex.Text =
Convert.ToString(Int32.Parse(intRecordCount.Text) - Int32.Parse(intPageSize.Text));}
DisplayProducts(CategoryID);
}
protected void PrintStatus(){
//lblStatus.Text = "Total Products:<b>" + intRecordCount.Text;lblStatus.Text =
"<b>Showing Page:<b> ";lblStatus.Text +=
Convert.ToString(Int32.Parse(intCurrIndex.Text) / Int32.Parse(intPageSize.Text) + 1);lblStatus.Text +=
"</b> of <b>";
if (Int32.Parse(intRecordCount.Text) % Int32.Parse(intPageSize.Text) > 0){
lblStatus.Text +=
Convert.ToString(Int32.Parse(intRecordCount.Text) / Int32.Parse(intPageSize.Text) + 1);}
else{
lblStatus.Text +=
Convert.ToString(Int32.Parse(intRecordCount.Text) / Int32.Parse(intPageSize.Text));}
lblStatus.Text +=
"</b>";}
Ramzi.Aynati
Contributor
2240 Points
531 Posts
Re: Number paging Datalist problem
Mar 08, 2007 08:26 AM|LINK
As i understand ur page loads correctly , but the prblem occurs when u hit the back button,
Can u please provide u code for back button ?
Ramzi
--------------------------------------------
Dont Forget to mark the post as answered once replied.
Sharonrao123
Member
32 Points
268 Posts
Re: Number paging Datalist problem
Mar 08, 2007 09:18 PM|LINK
hi Ramzi,
This is the code for back button, Cheers, Shilpa.
<input id="Button1" type="button" value="Back to Product List" onclick="javascript:history.go(-1)" class ="btn"/>
Lorenzo Batt...
Member
135 Points
37 Posts
Re: Number paging Datalist problem
Mar 08, 2007 10:29 PM|LINK
View this code
CODE
Sub BindData()
Dim mydt As New yourdatable()
Dim tba As New yourobjectTableAdapters.yourtableadaper()
tba.Fill(mydt, MedgPager.CurrentPageIndex * Me.dgPager.PageSize , Me.dgPager.PageSize)
Me.dgPager.VirtualItemCount = yourqueryrecordcount
Me.dgPager.DataSource = mydt
Me.dgPager.DataBind()
Me.DataList1.DataSource = mydt
Me.DataList1.DataBind()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Page.IsPostBack Then
BindData()
End If
End Sub
Protected Sub dgPager_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
e.Item.Visible = False
End If
End Sub
Protected Sub dgPager_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
Me.dgPager.CurrentPageIndex = e.NewPageIndex
BindData()
End Sub
ASPX page
<form id="form1" runat="server">
<asp:DataList ID="DataList1" runat="server" RepeatColumns="4" RepeatDirection="Horizontal">
<ItemTemplate>
<%# Eval("YourDataField") %><br />
</ItemTemplate>
</asp:DataList>
<asp:DataGrid ID="dgPager" runat="server" AllowPaging="True" AutoGenerateColumns="False" GridLines="None" PageSize="8" ShowHeader="False" OnPageIndexChanged="dgPager_PageIndexChanged" OnItemCreated="dgPager_ItemCreated" AllowCustomPaging="True">
<PagerStyle Mode="NumericPages" />
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</form>
Ceo President, LandLogic IT s.r.l.
Address : via G. Di Vittorio 29
City: Corato (Bari) Italy
Postal Code: 70033
Web: http://www.landlogic.it
Support: http://assistenza.landlogic.it
Sharonrao123
Member
32 Points
268 Posts
Re: Number paging Datalist problem
Mar 08, 2007 10:43 PM|LINK
Hello,
But i am using a datalist because i have to display the products in 5 columns. please see code below. Cheers, Shilpa.
<asp:DataList ID="dList" Runat="server" Width="130px" RepeatDirection="Horizontal" RepeatColumns="5"EnableViewState
="true" RepeatLayout="Table"><
ItemTemplate><
table width="80" border="0" cellpadding="0" cellspacing="0"> <tr> <td valign="top" align="center"class="box" height="80" style="width: 82px"> <a href="product_detail.aspx?p=<%# Eval("ProductID") %>"> <img src="<%# Eval("imageurl") %>" width="79" height="80" border="0"></a></td> </tr> <tr> <td style="width: 82px; height: 12px"> </td> </tr> <tr valign="top" align="left"> <td align="center" class="txt-1bold" style="width: 82px"> $<%# Eval("Price") %></td> <td> </td> </tr> <tr valign="top"> <td align="left" class="txt-main" height="30" style="width: 82px"> <%# Eval("ProductName") %> </td> </tr></
table></
ItemTemplate></
asp:DataList>Sharonrao123
Member
32 Points
268 Posts
Re: Number paging Datalist problem
Mar 08, 2007 10:43 PM|LINK
Hello,
But i am using a datalist because i have to display the products in 5 columns, is it possible through datagrid. please see code below. Cheers, Shilpa.
<asp:DataList ID="dList" Runat="server" Width="130px" RepeatDirection="Horizontal" RepeatColumns="5"EnableViewState
="true" RepeatLayout="Table"><
ItemTemplate><
table width="80" border="0" cellpadding="0" cellspacing="0"> <tr> <td valign="top" align="center"class="box" height="80" style="width: 82px"> <a href="product_detail.aspx?p=<%# Eval("ProductID") %>"> <img src="<%# Eval("imageurl") %>" width="79" height="80" border="0"></a></td> </tr> <tr> <td style="width: 82px; height: 12px"> </td> </tr> <tr valign="top" align="left"> <td align="center" class="txt-1bold" style="width: 82px"> $<%# Eval("Price") %></td> <td> </td> </tr> <tr valign="top"> <td align="left" class="txt-main" height="30" style="width: 82px"> <%# Eval("ProductName") %> </td> </tr></
table></
ItemTemplate></
asp:DataList>Lorenzo Batt...
Member
135 Points
37 Posts
Re: Number paging Datalist problem
Mar 08, 2007 10:47 PM|LINK
Add near your datalist a datagrid for only number pager
CODE
Sub BindData()
Dim mydt As New yourdatable()
Dim tba As New yourobjectTableAdapters.yourtableadaper()
tba.Fill(mydt, MedgPager.CurrentPageIndex * Me.dgPager.PageSize , Me.dgPager.PageSize)
Me.dgPager.VirtualItemCount = yourqueryrecordcount
Me.dgPager.DataSource = mydt
Me.dgPager.DataBind()
Me.DataList1.DataSource = mydt
Me.DataList1.DataBind()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Page.IsPostBack Then
BindData()
End If
End Sub
Protected Sub dgPager_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
e.Item.Visible = False
End If
End Sub
Protected Sub dgPager_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
Me.dgPager.CurrentPageIndex = e.NewPageIndex
BindData()
End Sub
ASPX page
<form id="form1" runat="server">
<asp:DataList ID="DataList1" runat="server" RepeatColumns="4" RepeatDirection="Horizontal">
<ItemTemplate>
<%# Eval("YourDataField") %><br />
</ItemTemplate>
</asp:DataList>
<asp:DataGrid ID="dgPager" runat="server" AllowPaging="True" AutoGenerateColumns="False" GridLines="None" PageSize="8" ShowHeader="False" OnPageIndexChanged="dgPager_PageIndexChanged" OnItemCreated="dgPager_ItemCreated" AllowCustomPaging="True">
<PagerStyle Mode="NumericPages" />
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</form>
Ceo President, LandLogic IT s.r.l.
Address : via G. Di Vittorio 29
City: Corato (Bari) Italy
Postal Code: 70033
Web: http://www.landlogic.it
Support: http://assistenza.landlogic.it
Sharonrao123
Member
32 Points
268 Posts
Re: Number paging Datalist problem
Mar 08, 2007 11:20 PM|LINK
hello,
I am getting an error on this line (Compiler Error Message: CS1502: The best overloaded method match for 'System.Data.Common.DbDataAdapter.Fill(System.Data.DataTable, System.Data.IDbCommand, System.Data.CommandBehavior)' has some invalid arguments). Where i am going wrong?
da.Fill(mydt, this.dgPager.CurrentPageIndex*this.dgPager.PageSize, this.dgPager.PageSize);
Code:
public
partial class ProductTest : System.Web.UI.Page{
_data a = new _data(); protected void Page_Load(object sender, EventArgs e){
if (!(IsPostBack)){
DisplayProduct();
}
}
protected void DisplayProduct(){
int CategoryID;CategoryID = 1;
//if (Request.QueryString["p"] != null) //{CategoryID =
Convert.ToInt32(Request.QueryString["p"].ToString()); // }System.Data.SqlClient.
SqlConnection Con = new System.Data.SqlClient.SqlConnection();Con.ConnectionString =
ConfigurationManager.AppSettings["ConnectionString"];System.Data.SqlClient.
SqlCommand Cmd = new System.Data.SqlClient.SqlCommand();Cmd.Connection = Con;
Cmd.CommandType =
CommandType.StoredProcedure;Cmd.Parameters.Add(
"@CategoryID", SqlDbType.Int);Cmd.Parameters[
"@CategoryID"].Value = CategoryID;Con.Open();
Cmd.CommandText =
"dbo.BMC_Display_ProductList"; SqlDataAdapter da = new SqlDataAdapter(Cmd); DataTable mydt = new DataTable();da.Fill(mydt,
this.dgPager.CurrentPageIndex*this.dgPager.PageSize, this.dgPager.PageSize); int nRowCount = mydt.Rows.Count(); this.dgPager.VirtualItemCount = nRowCount; this.dgPager.DataSource = mydt; this.dgPager.DataBind(); this.dList.DataSource = mydt; this.dList.DataBind();
if (Con.State == ConnectionState.Open){
Con.Close();
Cmd =
null;Con =
null;}
}
protected void dgPager_ItemCreated(object sender, GridViewRowEventArgs e){
if (e.Item.ItemType == ListItemType.Item | e.Item.ItemType == ListItemType.AlternatingItem){
e.Item.Visible =
false;}
}
protected void dgPager_PageIndexChanged(object sender, GridViewPageEventArgs e){
this.dgPager.CurrentPageIndex = e.NewPageIndex;DisplayProduct();
}
}
Lorenzo Batt...
Member
135 Points
37 Posts
Re: Number paging Datalist problem
Mar 08, 2007 11:40 PM|LINK
Change da.Fill(mydt, this.dgPager.CurrentPageIndex*this.dgPager.PageSize, this.dgPager.PageSize);
to
Dataset mydataset = new Dataset;
da.Fill(mydataset, this.dgPager.CurrentPageIndex*this.dgPager.PageSize, this.dgPager.PageSize,"yourNameTable");
Ceo President, LandLogic IT s.r.l.
Address : via G. Di Vittorio 29
City: Corato (Bari) Italy
Postal Code: 70033
Web: http://www.landlogic.it
Support: http://assistenza.landlogic.it
Sharonrao123
Member
32 Points
268 Posts
Re: Number paging Datalist problem
Mar 08, 2007 11:44 PM|LINK
hello,
I figured that out see below, but iam getting error in this line if (e.Row.RowType == ListItemType.Item | e.Row.RowType == ListItemType.AlternatingItem)
error (CS0019: Operator '==' cannot be applied to operands of type 'System.Web.UI.WebControls.DataControlRowType' and 'System.Web.UI.WebControls.ListItemType')
Code
protected void dgPager_ItemCreated(object sender, GridViewRowEventArgs e){
if (e.Row.RowType == ListItemType.Item | e.Row.RowType == ListItemType.AlternatingItem){
e.Row.Visible =
false;}
}
System.Data.SqlClient.
SqlConnection Con = new System.Data.SqlClient.SqlConnection();Con.ConnectionString =
ConfigurationManager.AppSettings["ConnectionString"];System.Data.SqlClient.
SqlCommand Cmd = new System.Data.SqlClient.SqlCommand();Cmd.Connection = Con;
Cmd.CommandType =
CommandType.StoredProcedure;Cmd.Parameters.Add(
"@CategoryID", SqlDbType.Int);Cmd.Parameters[
"@CategoryID"].Value = CategoryID;Con.Open();
Cmd.CommandText =
"name"; SqlDataAdapter da = new SqlDataAdapter(Cmd); DataSet mydt = new DataSet();da.Fill(mydt);
int maxrecords = (this.dgPager.CurrentPageIndex * this.dgPager.PageSize);da.Fill(mydt, maxrecords,
this.dgPager.PageSize, "name"); int nRowCount = mydt.Tables[0].Rows.Count; this.dgPager.VirtualItemCount = nRowCount; this.dgPager.DataSource = mydt.Tables[0].DefaultView; this.dgPager.DataBind(); this.dList.DataSource = mydt.Tables[0].DefaultView; this.dList.DataBind();