Friday, December 20, 2013

Bind gridview

<%@ Page Title="" Language="C#" MasterPageFile="~/admin/AdminMaster.master" AutoEventWireup="true"
CodeFile="vproduct.aspx.cs" Inherits="admin_vproduct" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="../ASPSnippets_Pager.min.js" type="text/javascript"></script>
<%-- <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>--%>
<%-- <script src="../js/jquery-1.7.1.min.js" type="text/javascript"></script>--%>
<%-- <script src="kj.js" type="text/javascript"></script>--%>
<script type="text/javascript">
function DelProduct(ProductId) {
$.ajax({
type: "POST",
url: "vproduct.aspx/DelProduct",
data: '{ProductId: ' + ProductId + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess1,
failure: function (response) {
},
error: function (response) {
}
});
}
function OnSuccess1(response) {
var pg = document.getElementById('ctl00_ContentPlaceHolder1_hdpaging').value;
GetProduct(pg);
}
function ActiveProduct(ProductId) {
$.ajax({
type: "POST",
url: "vproduct.aspx/ActiveProduct",
data: '{ProductId: ' + ProductId + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess1,
failure: function (response) {

},
error: function (response) {

}
});
}

$(function () {
GetProduct(1);
});
$(".Pager .page").live("click", function () {
GetProduct(parseInt($(this).attr('page')));
 
});
function GetProduct(pageIndex) {
document.getElementById('ctl00_ContentPlaceHolder1_hdpaging').value = pageIndex.toString();
$.ajax({
type: "POST",
url: "vproduct.aspx/GetProduct",
data: '{pageIndex: ' + pageIndex + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
}
function GetProduct1(pageIndex) {
var strSearch = document.getElementById('ctl00_ContentPlaceHolder1_txtSearch').value;
document.getElementById('ctl00_ContentPlaceHolder1_hdpaging').value = pageIndex.toString();
$.ajax({
type: "POST",
url: "vproduct.aspx/GetProduct1",
data: '{pageIndex: ' + pageIndex + ',strSearch:"' + strSearch + '"}',
contentType: "application/json; charset=utf-8",
dataType: "Text json",
success: OnSuccess,
failure: function (response) {
alert("f");
},
error: function (response) {
alert("E");
}
});
}
function OnSuccess(response) {
var xmlDoc = $.parseXML(response.d);
var xml = $(xmlDoc);
var customers = xml.find("Products");
var row = $("[id*=gvProducts] tr:last-child").clone(true);
$("[id*=gvProducts] tr").not($("[id*=gvProducts] tr:first-child")).remove();
$.each(customers, function () {
var customer = $(this);
var x = $(this).find("ProductID").text();
var xx = $(this).find("ProductCode").text();
$("td", row).eq(0).html($(this).find("ProductID").text());
$("td", row).eq(1).html($(this).find("ProductCode").text());
var img = new Image();
var imgstatus;
if ($(this).find("Isactive").text() == 'true') {
imgstatus = "<img src='Adminimages/tick.gif' onClick='ActiveProduct(this.id);' id=" + x.toString() + " />";
} else {
imgstatus = "<img src='Adminimages/cross.gif' onClick='ActiveProduct(this.id);' id=" + x.toString() + " />";
}
$("td", row).eq(2).html(imgstatus);
var imgdel = "<img src='Adminimages/Delete.jpg' onClick='DelProduct(this.id);' id=" + x.toString() + " />";
$("td", row).eq(3).html(imgdel);
var lnkEdit = "<a href=Addproduct.aspx?pcid=" + x.toString() + ">Edit</a>";
$("td", row).eq(4).html(lnkEdit);
$("[id*=gvProducts]").append(row);
row = $("[id*=gvProducts] tr:last-child").clone(true);
});
var pager = xml.find("Pager");
$(".Pager").ASPSnippets_Pager({
ActiveCssClass: "current",
PagerCssClass: "pager",
PageIndex: parseInt(pager.find("PageIndex").text()),
PageSize: parseInt(pager.find("PageSize").text()),
RecordCount: parseInt(pager.find("RecordCount").text())
 
});
};
$(document).ready(function () {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "CountryDetails.asmx/LoadCountry",
data: "{}",
dataType: "json",
success: function (Result) {
$.each(Result.d, function (key, value) {
alert(value.CategoryId);
$("#ddlCountry").append($("<option></option>").val(value.CategoryId).html(value.CategoryName));
});
},
error: function (Result) {
alert("Error");
}
});
});
</script>
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
.Pager span
{
text-align: center;
color: #999;
display: inline-block;
width: 20px;
background-color: #A1DCF2;
margin-right: 3px;
line-height: 150%;
border: 1px solid #3AC0F2;
 
 
}
 
.Pager a
 
 
{
text-align: center;
display: inline-block;
width: 20px;
background-color: #3AC0F2;
color: #fff;
border: 1px solid #3AC0F2;
margin-right: 3px;
line-height: 150%;
text-decoration: none;
 
 
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<table cellspacing="0" cellpadding="0" width="100%" border="0">
<tr>
<td colspan="2" align="left">

<table cellspacing="0" cellpadding="4" width="100%" border="0">
<tbody>
<tr>
<td align="left">

<table class="form-panel" cellspacing="0" cellpadding="3" width="100%" align="center"
border="0">
<tbody>
<tr>
<td class="form-head" valign="top" align="left" colspan="2">
View Product
</td>
</tr>
<tr>
<td align="left">
<fieldset>
<legend style="width: 100px; color: #000000" class="form-label">Select Product</legend>
<table cellspacing="0" cellpadding="3" border="0">
<tbody>
<tr style="display:none;">
<td style="width: 160px" class="form-label" align="right">
Product Brand :
</td>
<td>
<asp:DropDownList ID="ddlBrand" runat="server"
Width="230px" CssClass="form-text"
>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Display="None"
InitialValue="0" ValidationGroup="GroupOne" ErrorMessage="Please select the product Brand"
ControlToValidate="ddlBrand">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td style="width: 160px" class="form-label" align="right">
Product Category :
</td>
<td>
<asp:DropDownList ID="ddlCountry" runat="server" />
<asp:DropDownList ID="ddlCategory" runat="server"
Width="230px" CssClass="form-text">
</asp:DropDownList>

</td>
</tr>
<tr>
<td style="width: 160px" class="form-label" align="right">
Product SubCategory :
</td>
<td>
<asp:DropDownList ID="ddlSubcategory" runat="server"
Width="230px" CssClass="form-text">
</asp:DropDownList>
</td>
</tr>
<tr>
<td style="width: 162px" class="form-label" align="right">
Product SubSubCategory :
</td>
<td>
<asp:DropDownList ID="ddlSubSubCategory" CssClass="form-text" runat="server" Width="230px" >
</asp:DropDownList>
</td>
</tr>
</tbody>
</table>
</fieldset>
<br />
</td>
<td align="left" valign="middle">
<fieldset style="height: 40px">
<legend style="color: #000000" class="form-label">Search Product</legend>
<asp:TextBox Style="width: 320px" ID="txtSearch" runat="server"></asp:TextBox>
<cc1:TextBoxWatermarkExtender ID="TBWExtProduct" runat="server" TargetControlID="txtSearch"
WatermarkCssClass="watermark" WatermarkText="ProductCode , ProductName">
</cc1:TextBoxWatermarkExtender>
<input type=button ID="btnSearch" onClick="GetProduct1(1);" value="Search"
/>
<input type=button ID="btnShowAll" onClick="GetProduct(1);" value="Show All"
/>
</fieldset>
<br />
</td>
</tr>
</tbody>
</table>

</td>
</tr>
<tr>
<td>
<asp:Label ID="lblError" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<td><table cellspacing="0" cellpadding="4" width="100%" border="0">
<tbody>
<tr>
<td width="10%"></td><td width="80%">

<asp:GridView ID="gvProducts" runat="server" AutoGenerateColumns="false" RowStyle-BackColor="#A1DCF2"
HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White">
<Columns>
<asp:BoundField ItemStyle-Width="150px" DataField="ProductID" HeaderText="ProductID" />
<asp:BoundField ItemStyle-Width="150px" DataField="ProductCode" HeaderText="Product Code" />
<asp:BoundField ItemStyle-Width="150px" DataField="Isactive" HeaderText="Status" />
<asp:BoundField ItemStyle-Width="150px" DataField="Del" HeaderText="Delete" />
<asp:BoundField ItemStyle-Width="150px" DataField="Edt" HeaderText="Edit" />
</Columns>
</asp:GridView>
<asp:HiddenField ID="hdpaging" runat="server" />
<br />
<div class="Pager"></div>
</td><td width="10%"></td>

</tr></tbody></table>
</td>
</tr>
</tbody>
</table>

</td>
</tr>
</table>
</asp:Content>

No comments:

Post a Comment