Aniruddh Kewat

Aniruddh Kewat

  • NA
  • 30
  • 19.8k

click on link button is not working

Jun 18 2015 8:57 AM
i have a datalist which gets populated depending on the selection through,link button and radio buttons.....the link button passes the categoryid parameter,radio button-rblbrands passes the brand parameter and last radio button-rblpricerange passes the price parameter....
when the page loads,and i scroll selecting any thing,the scroll works fine...but when i click any link button second time,the categoryid,PageIndex and the PageCount doesn't changes,it holds the value of previos selection ..PageCount is output parameter,depending upon the data populated in the datalist....and if there any good way to shorten my stored procedure.....its very large....
here's my code,hope u understand....,
thanks in advance.......
My Stored Procedure
ALTER PROCEDURE Getproducts
@PageIndex INT
,@PageSize INT
,@CategoryId int
,@Brands nvarchar(50)= null
,@Price int
,@PageCount INT OUTPUT
AS
BEGIN
DECLARE @RecordCount INT
DECLARE @pricestart INT
DECLARE @priceend INT
if(@Price = 1)
begin
set @pricestart = 1
set @priceend = 2000
end
if(@Price = 2)
begin
set @pricestart = 2001
set @priceend = 5000
end
if(@Price = 3)
begin
set @pricestart = 5001
set @priceend = 10000
end
if(@Price = 4)
begin
set @pricestart = 10001
set @priceend = 18000
end
if(@Price = 5)
begin
set @pricestart = 18001
set @priceend = 25000
end
if(@Price = 6)
begin
set @pricestart = 25001
set @priceend = 35000
end
if(@Price = 7)
begin
set @pricestart = 35001
set @priceend = 50000
end
/*On page Load*/
IF(@CategoryId = 0 and @Brands is null)
if(@Price = 0)
begin
SET NOCOUNT ON;
SELECT ROW_NUMBER() OVER
(
ORDER BY [ProductId] ASC
)AS RowNumber
,[ProductId],[Name],[Description],[ImageUrl],[Price],[categotyId],[quantity] INTO #PageloadResults
FROM [Products]
SELECT @RecordCount = COUNT(*) FROM #PageloadResults
SET @PageCount = CEILING(CAST(@RecordCount AS DECIMAL(10, 2)) / CAST(@PageSize AS DECIMAL(10, 2)))
PRINT @PageCount
SELECT * FROM #PageloadResults
WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1
DROP TABLE #PageloadResults
end
else
begin
SET NOCOUNT ON;
SELECT ROW_NUMBER() OVER
(
ORDER BY [ProductId] ASC
)AS RowNumber
,[ProductId],[Name],[Description],[ImageUrl],[Price],[categotyId],[quantity] INTO #LoadpriceResults
FROM [Products] where Price between @pricestart and @priceend
SELECT @RecordCount = COUNT(*) FROM #LoadpriceResults
SET @PageCount = CEILING(CAST(@RecordCount AS DECIMAL(10, 2)) / CAST(@PageSize AS DECIMAL(10, 2)))
PRINT @PageCount
SELECT * FROM #LoadpriceResults
WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1
DROP TABLE #LoadpriceResults
end
/*if category id is selected*/
ELSE IF(@CategoryId != 0 and @Brands is null)
if(@Price = 0)
begin
SET NOCOUNT ON;
SELECT ROW_NUMBER() OVER
(
ORDER BY [ProductId] ASC
)AS RowNumber
,[ProductId],[Name],[Description],[ImageUrl],[Price],[categotyId],[quantity] INTO #CategoryIdResults
FROM [Products] where Categotyid = @CategoryId
SELECT @RecordCount = COUNT(*) FROM #CategoryIdResults
SET @PageCount = CEILING(CAST(@RecordCount AS DECIMAL(10, 2)) / CAST(@PageSize AS DECIMAL(10, 2)))
PRINT @PageCount
SELECT * FROM #CategoryIdResults
WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1
DROP TABLE #CategoryIdResults
end
else if(@Price != 0)
begin
SET NOCOUNT ON;
SELECT ROW_NUMBER() OVER
(
ORDER BY [ProductId] ASC
)AS RowNumber
,[ProductId],[Name],[Description],[ImageUrl],[Price],[categotyId],[quantity] INTO #CategoryIdpriceResults
FROM [Products] where Categotyid = @CategoryId and Price between @pricestart and @priceend
SELECT @RecordCount = COUNT(*) FROM #CategoryIdpriceResults
SET @PageCount = CEILING(CAST(@RecordCount AS DECIMAL(10, 2)) / CAST(@PageSize AS DECIMAL(10, 2)))
PRINT @PageCount
SELECT * FROM #CategoryIdpriceResults
WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1
DROP TABLE #CategoryIdpriceResults
end
/*Brands is selected*/
IF(@CategoryId != 0 and @Brands is not null)
if(@Price = 0)
begin
SET NOCOUNT ON;
SELECT ROW_NUMBER() OVER
(
ORDER BY [ProductId] ASC
)AS RowNumber
,[ProductId],[Name],[Description],[ImageUrl],[Price],[categotyId],[quantity] INTO #BrandsResults
FROM [Products] where CategotyId = @CategoryId and Name LIKE @Brands + '%'
SELECT @RecordCount = COUNT(*) FROM #BrandsResults
SET @PageCount = CEILING(CAST(@RecordCount AS DECIMAL(10, 2)) / CAST(@PageSize AS DECIMAL(10, 2)))
PRINT @PageCount
SELECT * FROM #BrandsResults
WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1
DROP TABLE #BrandsResults
end
else
begin
SET NOCOUNT ON;
SELECT ROW_NUMBER() OVER
(
ORDER BY [ProductId] ASC
)AS RowNumber
,[ProductId],[Name],[Description],[ImageUrl],[Price],[categotyId],[quantity] INTO #BrandspriceResults
FROM [Products] where Categotyid = @CategoryId and Name LIKE @Brands + '%' and Price between @pricestart and @priceend
SELECT @RecordCount = COUNT(*) FROM #BrandspriceResults
SET @PageCount = CEILING(CAST(@RecordCount AS DECIMAL(10, 2)) / CAST(@PageSize AS DECIMAL(10, 2)))
PRINT @PageCount
SELECT * FROM #BrandspriceResults
WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1
DROP TABLE #BrandspriceResults
end
END
My code ;
<script type="text/javascript">
//global variables
var pageIndex = 1;
var pageCount;
var categoryid = 0;
var brandtext = null;
var pricevalue = 0;
$(document).ready(function () {
$(window).scroll(function () {
if ($(window).scrollTop() == $(document).height() - $(window).height()) {
GetRecords();
}
});
$('.clbtnmenu').click(function () {
categoryid = $(this).data('id');
pageIndex = 1;
});
});
function GetRecords() {
pageIndex++;
/*retrieving Text from rblbrands if checked*/
if ($('#<%=rblbrands.ClientID %> input:checked').val() != null) {
var checked_radiobrands = $("[id*=rblbrands] input:checked");
//brandsvalue = checked_radiobrands.val();
brandtext = checked_radiobrands.closest("td").find("label").html();
}
if ($('#<%=rblpricerange.ClientID %> input:checked').val() != null) {
var checked_radioprice = $("[id*=rblpricerange] input:checked");
pricevalue = checked_radioprice.val();
//pricetext = checked_radioprice.closest("td").find("label").html();
}
alert('PageIndex : ' + pageIndex + ' , Page Count : ' + pageCount + ' , CategoryId : ' + categoryid + " , BrandText : " + brandtext + " , PriceValue :" + pricevalue);
if (pageIndex == 2 || pageIndex <= pageCount) {
$("#loader").show();
$.ajax({
type: "POST",
url: "WebForm1.aspx/GetCustomers",
data: JSON.stringify({ 'pageindex': pageIndex, 'categoryid': categoryid, 'brand': brandtext, 'price': pricevalue }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert('Hell 1');
},
error: function (response) {
alert('Hell 2');
}
});
}
}
function OnSuccess(response) {
var xmlDoc = $.parseXML(response.d);
var xml = $(xmlDoc);
pageCount = parseInt(xml.find("PageCount").eq(0).find("PageCount").text());
var customers = xml.find("Customers");
var repeatColumns = parseInt("<%=dlCustomers.RepeatColumns == 0 ? 1 : dlCustomers.RepeatColumns %>");
var rowCount = Math.ceil(customers.length / repeatColumns);
var i = 0;
while (i < repeatColumns * rowCount) {
var row = $("[id*=dlCustomers] tr").eq(0).clone(true);
for (var j = 0; j < repeatColumns; j++) {
var customer = $(customers[i]);
if (customer.length == 0) {
//alert('Bingo');
$("table:last", row).remove();
} else {
$(".name", row).eq(j).html(customer.find("Name").text());
$(".productId", row).eq(j).html(customer.find("ProductId").text());
$(".description", row).eq(j).html(customer.find("Description").text());
$(".imageUrl", row).eq(j).html(customer.find("ImageUrl").text());
$(".image", row).eq(j).attr("src", 'Images/' + customer.find("ImageUrl").text());
$(".price", row).eq(j).html(customer.find("Price").text());
$(".quantity", row).eq(j).html(customer.find("Quantity").text());
}
i++;
}
$("[id*=dlCustomers]").append(row);
}
//$("[id*=dlCustomers] tr").eq(0).remove();
$("[id*=dlCustomers]").show();
$("#loader").hide();
}
</script>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div id="main" style="width: 70%; margin: 0 auto; background-color:Aqua">
<div id="header">
<ul>
<li>
<asp:LinkButton CssClass="clbtnmenu" ID="LinkButton1" runat="server" data-id="1"
CommandArgument="1" OnClick="lbtnmenu_click">Mobile</asp:LinkButton></li>
<li>
<asp:LinkButton CssClass="clbtnmenu" ID="LinkButton2" runat="server" data-id="2"
CommandArgument="2" OnClick="lbtnmenu_click">Shoes</asp:LinkButton></li>
<li>
<asp:LinkButton CssClass="clbtnmenu" ID="LinkButton3" runat="server" data-id="3"
CommandArgument="3" OnClick="lbtnmenu_click">Bags</asp:LinkButton></li>
<li>
<asp:LinkButton CssClass="clbtnmenu" ID="LinkButton4" runat="server" data-id="4"
CommandArgument="4" OnClick="lbtnmenu_click">Clothing</asp:LinkButton></li>
</ul>
</div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<div id="content" style="width: 100%">
<div id="leftcontent" style="width: 15%; float: left;">
<div id="divbrands">
<asp:Label CssClass="clblpricebrands" ID="lblbrands" runat="server" Text="BRANDS"></asp:Label>
<asp:RadioButtonList CssClass="crblpricebrands" ID="rblbrands" runat="server" AutoPostBack="True"
RepeatLayout="Table"
onselectedindexchanged="rblbrands_SelectedIndexChanged">
</asp:RadioButtonList>
</div>
<div id="divpricerange">
<asp:Label CssClass="clblpricebrands" ID="lblpricerange" runat="server" Text="Price Range"></asp:Label>
<asp:RadioButtonList CssClass="crblpricebrands" ID="rblpricerange" runat="server"
AutoPostBack="True" Font-Size="1em" Width="100%"
onselectedindexchanged="rblpricerange_SelectedIndexChanged">
<asp:ListItem Value="1">Rs.2000 and Below</asp:ListItem>
<asp:ListItem Value="2">Rs.2001-Rs.5000</asp:ListItem>
<asp:ListItem Value="3">Rs.5001-Rs.10000</asp:ListItem>
<asp:ListItem Value="4">Rs.10001-Rs.18000</asp:ListItem>
<asp:ListItem Value="5">Rs.18001-Rs.25000</asp:ListItem>
<asp:ListItem Value="6">Rs.25001-Rs.35000</asp:ListItem>
<asp:ListItem Value="7">Rs.35001 and Above</asp:ListItem>
</asp:RadioButtonList>
</div>
</div>
<div id="rightcontent" style="width: 85%; float: left;">
<div id="dvCustomers" style="width: 100%;overflow: auto; background-color: Black;">
<asp:DataList ID="dlCustomers" runat="server" RepeatLayout="Table" RepeatColumns="4"
RepeatDirection="Horizontal" CellPadding="0" CellSpacing="0" BackColor="Aqua"
Width="100%">
<ItemStyle Width="25%" />
<ItemTemplate>
<table cellpadding="0" cellspacing="0" border="0" style="width: 100%; height: 300px;
border: 2px solid Blue; background-color: Green; text-align: center">
<tr>
<td>
<b><u><span class="name">
<%# Eval("Name") %></span></u></b>
</td>
</tr>
<tr>
<td>
<b>Productid: </b><span class="productId" style="font-size: 20px; color: Yellow;
font-weight: 500;">
<%# Eval("Productid") %></span><br />
<b>Description </b><span class="description">
<%# Eval("Description") %></span><br />
<b>ImageUrl: </b><span class="imageUrl">
<%# Eval("ImageUrl")%></span><br />
<img class="image" alt='' src="Images/<%# Eval("ImageUrl")%>" width="160px" height="320px" /><br />
<b>Price: </b><span class="price">
<%# Eval("Price")%></span>
<img alt="" src="star-icon.png" />
<b>Quantity: </b><span class="quantity">
<%# Eval("Quantity")%></span><br />
<button onclick="return false;">
Add To Cart</button>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</div>
<img id="loader" alt="" src="loader.gif" style="display: none; height: 50px; margin-left: 45%" />
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>

Answers (6)