I want to bind my dataliadt with scroll event .. i got the solution in the article ..
http://www.aspsnippets.com/Articles/Load-data-while-Scrolling-Page-down-with-jQuery-AJAX-and-ASPNet.aspx
but my binding method is also associated with some control of page so i cant use sotred procedure as suggested in article ....... how i have to bind my datalist ?
here is code ..
<asp:DataList ID="DataList1" RepeatColumns="4" RepeatLayout="table"
RepeatDirection="horizontal" runat="server"
onitemdatabound="DataList1_OnItemDataBound" >
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<table class="item_wrap" id="tbl" >
<tr style="height:20px">
<td >
<asp:Label ID="Label4" runat="server" Text='<%#Eval("Adiscount","{0}% Off")%>'
CssClass="discoutimage" Width="65px" Height="20px" Visible="False">/asp:LinkButton>
</td>
</tr>
<tr style=" height:60px">
<td align="center" >
<asp:Image ID="sh1" Height="175px" Width="140px" runat ="server"
ImageUrl='<%#Eval("produrl")%>' CssClass="item_pic" />
</td>
</tr>
<tr style="height:15px; padding-left:10px">
<td valign="top" style="padding-right:5px">
<asp:Label ID="l1" runat="server" Text='<%#Eval("prodname")%>' Height="25px" CssClass="item_title" ></asp:Label>
</td>
</tr>
<tr style=" height:15px" valign="top">
<td style="color:#fa7a0a" valign="top">
<asp:Label ID="rs" runat="server" CssClass="rs" Text="Rs."></asp:Label>
<asp:Label ID="l2" runat="server" Text='<%#Eval("Aprice")%>' CssClass="apirce" >
</asp:Label>
</asp:Label>
<asp:HiddenField ID="HiddenField6" Value='<%#Eval("prodprice")%>' runat="server" />
</td>
<td >
<asp:Label ID="l3" runat="server" Text='<%#Eval("productid")%>' Visible="False"></asp:Label></td>
</tr>
<tr style="height:30px; padding-left:15px">
<td valign="middle">
<asp:LinkButton ID="ii" runat="server" Text="Add To Cart"
CssClass="ImageButton" Height="20px" Width="90px" EnableViewState="True"
/>
</td>
</tr>
</table>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:DataList>
and this is code for my binding at pageload
Getbind();
}
protected DataTable Getbind()
{
string search = Request.QueryString["searchString"];
string catid = Request.QueryString["item"];
string text = DropDownList1.SelectedItem.ToString();
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["eshopConnectionString"].ConnectionString);
SqlDataAdapter adp = new SqlDataAdapter();
con.Open();
if (text == "Highest Discount")
{
if (Request.QueryString["searchString"] != null)
{
SqlCommand cmd1 = new SqlCommand("select * from products where prodname like '%" + search + "%' order by productid", con);
SqlDataAdapter adp1 = new SqlDataAdapter();
adp1.SelectCommand = cmd1;
DataTable ds1 = new DataTable();
adp1.Fill(ds1);
double[] ar = new double[ds1.Rows.Count];
string[] ar1 = new string[ds1.Rows.Count];
for (int i = 0; i <= ds1.Rows.Count - 1; i++)
{
double temp1 = double.Parse(ds1.Rows[i]["prodprice"].ToString());
double temp2 = double.Parse(ds1.Rows[i]["discount"].ToString());
temp1 = (temp1 * (1 - (temp2 / 100)));
ar[i] = temp1;
}
for (int k = 0; k <= ds1.Rows.Count - 1; k++)
{
string s = ds1.Rows[k]["productid"].ToString();
ar1[k] = s;
}
for (int j = 0; j <= ds1.Rows.Count - 1; j++)
{
SqlCommand cmd2 = new SqlCommand("update products set prodprice='" + ar[j] + "',discount='" + 0 + "' where productid='" + ar1[j] + "'", con);
cmd2.ExecuteNonQuery();
}
SqlCommand cmd = new SqlCommand("select * from products where prodname like '%" + search + "%' order by discount", con);
//adp.SelectCommand = cmd;
//adp.Fill(ds);
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
pgsource.DataSource = dt.DefaultView;
pgsource.AllowPaging = true;
pgsource.PageSize = 16;
pgsource.CurrentPageIndex = CurrentPage;
ViewState["totpage"] = pgsource.PageCount;
DataList1.DataSource = pgsource;
DataList1.DataBind();
doPaging();
}
else
{
SqlCommand cmd1 = new SqlCommand("select * from products where cartid='" + catid + "' order by productid", con);
SqlDataAdapter adp1 = new SqlDataAdapter();
adp1.SelectCommand = cmd1;
DataTable ds1 = new DataTable();
adp1.Fill(ds1);
double[] ar = new double[ds1.Rows.Count];
string[] ar1 = new string[ds1.Rows.Count];
for (int i = 0; i <= ds1.Rows.Count - 1; i++)
{
double temp1 = double.Parse(ds1.Rows[i]["prodprice"].ToString());
double temp2 = double.Parse(ds1.Rows[i]["discount"].ToString());
temp1 = (temp1 * (1 - (temp2 / 100)));
ar[i] = temp1;
}
for (int k = 0; k <= ds1.Rows.Count - 1; k++)
{
string s = ds1.Rows[k]["productid"].ToString();
ar1[k] = s;
}
for (int j = 0; j <= ds1.Rows.Count - 1; j++)
{
SqlCommand cmd2 = new SqlCommand("update products set prodprice='" + ar[j] + "',discount='" + 0 + "' where productid='" + ar1[j] + "'", con);
cmd2.ExecuteNonQuery();
}
SqlCommand cmd = new SqlCommand("select * from products where cartid='" + catid + "' order by discount", con);
//adp.SelectCommand = cmd;
//adp.Fill(ds);
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
pgsource.DataSource = dt.DefaultView;
pgsource.AllowPaging = true;
pgsource.PageSize = 16;
pgsource.CurrentPageIndex = CurrentPage;
ViewState["totpage"] = pgsource.PageCount;
DataList1.DataSource = pgsource;
DataList1.DataBind();
doPaging();
//DataList1.DataSource = ds;
//DataList1.DataBind();
}
}
if (text == "Price: High To Low")
{
if (Request.QueryString["searchString"] != null)
{
SqlCommand cmd = new SqlCommand("select * from products where prodname like '%" + search + "%' order by prodprice desc", con);
//adp.SelectCommand = cmd;
//adp.Fill(ds);
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
pgsource.DataSource = dt.DefaultView;
pgsource.AllowPaging = true;
pgsource.PageSize = 16;
pgsource.CurrentPageIndex = CurrentPage;
ViewState["totpage"] = pgsource.PageCount;
DataList1.DataSource = pgsource;
DataList1.DataBind();
doPaging();
}
else
{
SqlCommand cmd = new SqlCommand("select * from products where cartid='" + catid + "' order by prodprice desc", con);
//adp.SelectCommand = cmd;
//adp.Fill(ds);
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
pgsource.DataSource = dt.DefaultView;
pgsource.AllowPaging = true;
pgsource.PageSize = 16;
pgsource.CurrentPageIndex = CurrentPage;
ViewState["totpage"] = pgsource.PageCount;
DataList1.DataSource = pgsource;
DataList1.DataBind();
doPaging();
//DataList1.DataSource = ds;
//DataList1.DataBind();
}
}
if (text == "Price: Low To High")
{
if (Request.QueryString["searchString"] != null)
{
SqlCommand cmd = new SqlCommand("select * from products where prodname like '%" + search + "%' order by prodprice", con);
//adp.SelectCommand = cmd;
//adp.Fill(ds);
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
pgsource.DataSource = dt.DefaultView;
pgsource.AllowPaging = true;
pgsource.PageSize = 16;
pgsource.CurrentPageIndex = CurrentPage;
ViewState["totpage"] = pgsource.PageCount;
DataList1.DataSource = pgsource;
DataList1.DataBind();
doPaging();
}
else
{
SqlCommand cmd = new SqlCommand("select * from products where cartid='" + catid + "' order by prodprice", con);
//adp.SelectCommand = cmd;
//adp.Fill(ds);
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
pgsource.DataSource = dt.DefaultView;
pgsource.AllowPaging = true;
pgsource.PageSize = 16;
pgsource.CurrentPageIndex = CurrentPage;
ViewState["totpage"] = pgsource.PageCount;
DataList1.DataSource = pgsource;
DataList1.DataBind();
doPaging();
}
}
con.Close();
return ds;
}