Hi Im a newbie in asp.net, im a php programmer though, and i've been working on a pop up div with a search engine on it, in php i have no problem working with json but in asp it took me already two days to find a similar problem, yet no luck. I hope you can help me..
heres my code
//HTML
i have a dropdown and a textbox for input of the keyword
<table id="filterContainer">
<tr>
<td>
Filter By:
<asp:DropDownList ID="DropDownList3" name="filter" runat="server" >
<asp:listitem text="Please Select.." value=""></asp:listitem> <asp:listitem text="Id" value="id"></asp:listitem>
<asp:listitem text="Program Title" value="title"></asp:listitem>
<asp:listitem text="Customer Name" value="name"></asp:listitem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
Filter Key:
<asp:TextBox ID="FilterKey" name="filterKey" runat="server"></asp:TextBox>
</td>
</tr>
</table>
//My grid for the display of data
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" CssClass="Grid" class="fixedTable" AutoGenerateColumns="false" AlternatingRowStyle-BackColor = "#C2D69B" ShowHeader = "false">
<Columns>
<asp:BoundField DataField="Title" HeaderText="Title" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="DTASA_Amount" DataFormatString="{0:n2}" HeaderText="Amount" />
<asp:BoundField DataField="DTASA_Accrued" DataFormatString="{0:n2}" HtmlEncode = False HeaderText="Accrued" />
<asp:BoundField DataField="DTASA_Balance" HtmlEncode = False HeaderText="Balance" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
//JS
$('#FilterKey').on('change', function() {
var key = $(this).val();
var filter = $('#DropDownList3').val();
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "dtasa.aspx/GetDtasaRecordN",
data: "{'Key':'" + key + ", 'Filter':'" + filter + "'}",
dataType: "json",
success: function (result) {
alert('success');
}
});
})
//c#
I dont know exactly how to do it on c# file, what i want is to pass the variable on js here and get the data on database and display it on a gridview
protected void GetDtasaRecordNOld(string filterKey, string filter)
{
//object sender, EventArgs e
DataSet ds = new DataSet();
DataTable dt = new DataTable();
String strSQL = "";
Hashtable htParameter = new Hashtable();
//String FilterKey = "TLC";
//String filter = "title";
htParameter.Add("filterKey", filterKey); //FilterKey.Text
htParameter.Add("filter", filter);//DropDownList3.SelectedValue
try
{
strSQL = oSQLS.GetDtasaRecN(htParameter);
ds = oDataEnc.PerformMultipleQuery(strSQL);
dt = ds.Tables[0];
GridView1.DataSource = dt;
GridView1.DataBind();
}
catch (Exception ex)
{
this.lblError.Text = "DefinePageLoad : " + ex.Message;
ex = null;
}
}