I know how to fetch the records from DB,But i want to ask u just small thing.
SQL TABLE
roll name marks
1 Ritu 10
2 Sneha 20
3 Ruchi 30
CODE BEHIND PAGE
Default.aspx
protected void Page_Load(object sender, EventArgs e)
{
cmbRoll.Items.Add("--Select--");
cmbRoll.Items.Add("1");
cmbRoll.Items.Add("2");
cmbRoll.Items.Add("3");
cmbRoll.Attributes.Add("onChange", "javascript:return check()");
}
JS CODE
<title>Untitled Page</title>
<script type ="text/javascript" language ="javascript">
var xmlHttp;
var WholeString;
var col_array;
function check()
{
var Roll=document.getElementById("<%=cmbRoll.ClientID %>").value;
//checkXHR("Retrieve.aspx?Roll=" + Roll + "&sid="+Math.random());
checkXHR("Retrieve.aspx?Roll=" + Roll );
WholeString=document.getElementById("hd1").value;
alert (WholeString); //Result of Particular roll No that is fetched from DB thru AJAX
col_array=WholeString.split("^^^^");
for (i = 0; i <= col_array.length; i++)
{
document.getElementById("txtName").value=col_array[1];
document.getElementById("txtMarks").value=col_array[2];
}
xmlHttp=null;
return true;
}
function checkXHR(url)
{
try
{
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.open("GET",url,false);
xmlHttp.onreadystatechange=statechanged;
xmlHttp.send(null);
}
function statechanged()
{
if(xmlHttp.readyState==4)
{
document.getElementById("hd1").value = xmlHttp.responseText;
}
else
{
document.getElementById("hd1").value="";
}
}
Retrieve.aspx
protected void Page_Load(object sender, EventArgs e)
{
string a;
string b;
string c;
SqlDataAdapter da = new SqlDataAdapter("select * from [Information] where upper(roll)='" +
Request["Roll"].ToUpper() + "'", conn);
DataSet ds = new DataSet();
da.Fill(ds);
foreach(DataRow row in ds.Tables[0].Rows)
{
a = row[0].ToString();
b = row[1].ToString();
c = row[2].ToString();
Response.Write(a + "^^^^" + b + "^^^^" + c);
}
I take hidden field in Default.aspx & as u know response.write to hidden field..SO in Default.aspx I m getting my result back in variable in the line
WholeString=document.getElementById("hd1").value;
Now I have employee info in database & i want to bind it to the Gridview using AJAX...Even for that i have to return value in the above way or there is other way out..
Plz help me out!!!