Do
various things by JSON in ASP.net -2
Display records in GridView by JSON
Form Source
<asp:GridView ID="gv_Bid_Summary" runat="server" AutoGenerateColumns="False" Width="70%"
DataKeyNames="STTS"
OnRowDataBound="gv_Bid_Summary_RowDataBound">
<Columns>
<asp:BoundField DataField="srNo"
HeaderText="SR
NO." ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center"
Width="100px"></ItemStyle>
</asp:BoundField>
<asp:TemplateField HeaderText="DETAILS">
<ItemTemplate>
<asp:HyperLink ID="hl_Category"
runat="server"
NavigateUrl="#"
OnInit="hl_Category_Init">HyperLink</asp:HyperLink>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center"
/>
<ItemStyle HorizontalAlign="Left"
/>
</asp:TemplateField>
<asp:TemplateField HeaderText="STATUS">
<ItemTemplate>
<asp:Image ID="ImgFlag"
runat="server"
ImageUrl=""
Height="10px"
/>
<asp:HiddenField ID="hf_isFinalized"
Value='<%#
Bind("nCount") %>' runat="server"
/>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"
Width="100px"
/>
<HeaderStyle HorizontalAlign="Center"
/>
</asp:TemplateField>
</Columns>
</asp:GridView>
<%--Add new Button to Bind grid --%>
<asp:Button ID="BtnViewSummary"
runat="server"
Style="height: 26px" Text="Save" ValidationGroup="pdSave"
Width="80px"
OnClientClick="Bid_Summary();
return false;" />
SCRIPT
json2.js – Search on google for Jsfile
<script src="../App_Themes/CGDNA/json2.js"
type="text/javascript">
</script>
<%--important --%>
<script type="text/javascript" language="JavaScript">
function Bid_Summary() {
//alert('hi');
var items = {};
items.BidNo =
$("#<%=hf_BNo.ClientID %>").val();
//
debugger;
$.ajax({
type: "POST",
url: "frmBidInformation.aspx/BIND_FINALIZED_GRID",
data: '{items: ' + JSON.stringify(items) + '}',
contentType: "application/json;
charset=utf-8",
dataType:
"json",
success: function(data) {
//alert(data.d);
OnSuccess(data);
},
failure: function(response) {
alert("Failure : " +
response.d);
},
error: function(response) {
alert("Error : " +
response.d);
}
});
}
function OnSuccess(response) {
var xmlDoc = $.parseXML(response.d);
var xml = $(xmlDoc);
var users = xml.find("Table");
//create a new row from the last row of gridview
var row = $("[id*=gv_Bid_Summary]
tr:last-child").clone(true);
//remove the lst row created by binding the dummy row from
code behind on page load
$("[id*=gv_Bid_Summary] tr").not($("[id*=gv_Bid_Summary] tr:first-child")).remove();
var count = 1;
$.each(users,
function() {
//var users = $(this);
$("td", row).eq(0).html($(this).find("srNo").text());
$("td", row).eq(1).html($(this).find("vLink").text());
if ($(this).find("STTS").text() == "T")
$("td", row).eq(2).html("<img src='../App_Themes/Images/yesstatus.gif'
style='height:10px;border-width:0px;'/>
<input id='hf_isFinalized" + count + "' name='hf_isFinalized' type='hidden' value='"
+ $(this).find("nCount").text()
+ "'/>");
else
$("td", row).eq(2).html("<img src='../App_Themes/Images/nostatus.GIF'
style='height:10px;border-width:0px;'/> <input id='hf_isFinalized"
+ count + "' name='hf_isFinalized'
type='hidden' value='" + $(this).find("nCount").text() + "' />");
$("[id*=gv_Bid_Summary]").append(row);
count =
count + 1;
row = $("[id*=gv_Bid_Summary] tr:last-child").clone(true);
});
}
</script>
Code Behind
public class gvBind
{
public string BidNo {
get; set; }
}
[WebMethod]
public static string
BIND_FINALIZED_GRID(gvBind items)
{
clsFuncctionLib objFunLib = new clsFuncctionLib();
DataSet ds = new DataSet();
string strMessage = "";
objFunLib.objCon.Open();
objFunLib.objSqlCmd = new SqlCommand();
objFunLib.objSqlCmd.CommandType = CommandType.StoredProcedure;
objFunLib.objSqlCmd.Parameters.AddWithValue("@vBidNo",
Convert.ToInt32(items.BidNo));
try
{
ds = clsDatabase.GetDataSet("PROC_GET_MENU_STATUS",
objFunLib.objSqlCmd);
strMessage = ds.GetXml();
}
catch (Exception
ex)
{
strMessage = ex.Message.ToString();
}
return strMessage;//
iCount.ToString();
}
No comments:
Post a Comment