473,395 Members | 1,443 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

fill/populate grid using javascript/ajax

11
Hi,
friends i have this code of ajax to populate statedropdownlist on countrydropdownlist selectedindex changed, it is working fine
now i want to populate gridview through this code can anybody help me


Expand|Select|Wrap|Line Numbers
  1. var val, xmlHttp, xmlDoc, xmlUrl;
  2.  
  3.                 val = document.all.item("ddlCountry").options[document.all.item("ddlCountry").selectedIndex].value;
  4.                     document.all.item("ddlCountry").options[0] = new Option ("Select", "0");
  5.                 xmlUrl = "StateFill.aspx";
  6.  
  7.                 xmlDoc = "&";
  8.                 xmlDoc= xmlDoc + escape("param") + "=" + escape("getState") + "&";
  9.                 xmlDoc= xmlDoc + escape("SCode") + "=" + escape(val);
  10.  
  11.                 if ( navigator.appName == "Netscape" )
  12.                     xmlHttp = new XMLHttpRequest();
  13.                 else
  14.                     xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  15.  
  16.                 xmlHttp.open ("POST", xmlUrl, false)
  17.                 xmlHttp.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded")
  18.                 xmlHttp.send(xmlDoc)
  19.  
  20.                 var v, i;
  21.                 if (xmlHttp.status != "500")
  22.                 {
  23.                     v = xmlHttp.responseText
  24.                 }
  25.                 else
  26.                 {
  27.                     alert("Error Downloading State Information.");
  28.                 }
  29.  
  30.                 document.all.item("ddlState").disabled = false;
  31.                 for (i = document.all.item("ddlState").options.length; i >= 0; i--)
  32.                     document.all.item("ddlState").options[i] = null;                
  33.  
  34.                 document.all.item("ddlState").options[0] = new Option ("All", "0");
  35.                 //alert(document.all.item("ddlState").value);
  36.                 if (v.length > 0)
  37.                 {
  38.  
  39.                     var catArray, j, selindex;
  40.                     catArray = v.split("#~");
  41.                     j = 1;
  42.                     selindex = 0;
  43.                     for(i = 0; i < catArray.length; i = i + 2)
  44.                     {
  45.                         document.all.item("ddlState").options[j] = new Option (catArray[i+1], catArray[i]);
  46.                         j = j + 1;
  47.                     }            
  48.                 }
  49.             }
  50.             else
  51.             {
  52.                 document.all.item("ddlState").disabled = true;
  53.                 for (i = document.all.item("ddlState").options.length; i >= 0; i--)
  54.                     document.all.item("ddlState").options[i] = null;
  55.             }
Dec 4 '07 #1
3 2374
acoder
16,027 Expert Mod 8TB
Where's the code for the grid?

Note: don't use document.all. It's non-standard and does not work in most browsers. Use document.getElementById() instead making sure that you've set IDs to your elements.
Dec 4 '07 #2
sattu
11
Hi,
friends i have this code of ajax to populate statedropdownlist on countrydropdownlist selectedindex changed, it is working fine
now i want to populate gridview through this code can anybody help me

i have taken state and country dropdownlist on page which has this javascript code, Onpageload countrydropdownlist is filling and "countrydropdownlist's autopostback=fasle"
and my server side code to fillup statedropdownlist is on pageload of "StateFill.aspx"


Expand|Select|Wrap|Line Numbers
  1. var val, xmlHttp, xmlDoc, xmlUrl;
  2.  
  3.                 val = document.all.item("ddlCountry").options[document.all.item("ddlCountry").selectedIndex].value;
  4.                     document.all.item("ddlCountry").options[0] = new Option ("Select", "0");
  5.                 xmlUrl = "StateFill.aspx";
  6.  
  7.                 xmlDoc = "&";
  8.                 xmlDoc= xmlDoc + escape("param") + "=" + escape("getState") + "&";
  9.                 xmlDoc= xmlDoc + escape("SCode") + "=" + escape(val);
  10.  
  11.                 if ( navigator.appName == "Netscape" )
  12.                     xmlHttp = new XMLHttpRequest();
  13.                 else
  14.                     xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  15.  
  16.                 xmlHttp.open ("POST", xmlUrl, false)
  17.                 xmlHttp.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded")
  18.                 xmlHttp.send(xmlDoc)
  19.  
  20.                 var v, i;
  21.                 if (xmlHttp.status != "500")
  22.                 {
  23.                     v = xmlHttp.responseText
  24.                 }
  25.                 else
  26.                 {
  27.                     alert("Error Downloading State Information.");
  28.                 }
  29.  
  30.                 document.all.item("ddlState").disabled = false;
  31.                 for (i = document.all.item("ddlState").options.length; i >= 0; i--)
  32.                     document.all.item("ddlState").options[i] = null;                
  33.  
  34.                 document.all.item("ddlState").options[0] = new Option ("All", "0");
  35.                 //alert(document.all.item("ddlState").value);
  36.                 if (v.length > 0)
  37.                 {
  38.  
  39.                     var catArray, j, selindex;
  40.                     catArray = v.split("#~");
  41.                     j = 1;
  42.                     selindex = 0;
  43.                     for(i = 0; i < catArray.length; i = i + 2)
  44.                     {
  45.                         document.all.item("ddlState").options[j] = new Option (catArray[i+1], catArray[i]);
  46.                         j = j + 1;
  47.                     }         
  48.                 }
  49.             }
  50.             else
  51.             {
  52.                 document.all.item("ddlState").disabled = true;
  53.                 for (i = document.all.item("ddlState").options.length; i >= 0; i--)
  54.                     document.all.item("ddlState").options[i] = null;
  55.             }
Expand|Select|Wrap|Line Numbers
  1.  protected void Page_Load(object sender, EventArgs e)
  2.     {
  3.         if (Request.Params["param"].ToString() == "getState")
  4.         {
  5.             string CntId = Request.Params["SCode"]; //.Item["SCode"];
  6.             Class1 obj = new Class1();
  7.  
  8.            // OnLineStore.Comm.PopulateDb locobj = new OnLineStore.Comm.PopulateDb();
  9.  
  10.             string str;
  11.             str = string.Empty;
  12.             System.Data.SqlClient.SqlDataReader LOC_dr;
  13.             LOC_dr = obj.getdata("select intStateTerritoryId,txtStateTerritory from tblMstStateTerritory where intCountryId=" + CntId.ToString() + " Order By txtStateTerritory");
  14.  
  15.             //LOC_dr = locobj.GetReader("Select StateId,StateName >From OS_StateMaster Where CountryId=" + CntId + " Order By StateName");
  16.  
  17.             if (LOC_dr.HasRows)
  18.             {
  19.                 while (LOC_dr.Read())
  20.                     str = str + LOC_dr[0] + "#~" + LOC_dr[1] + "#~";
  21.  
  22.             }
  23.             if (str != "")
  24.                 str = str.Substring(0, str.Length - 2);
  25.             LOC_dr.Close();
  26.             LOC_dr = null;
  27.             Response.Write(str);
  28.         }
Dec 5 '07 #3
acoder
16,027 Expert Mod 8TB
I have merged the threads. Please do not double post.
Dec 5 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Kate | last post by:
Hi, we are now developing complex business application using Ajax framework. Could anyone point me to the editable javascript grid control which supports XML loading. Good javascript API would be...
2
by: Woody Splawn | last post by:
I have a question about technique with regard to filling drop downs. I have a Winform that has several different tabs and tables associated with it. In an effort to keep the load time small I...
2
by: Fabio Mastria | last post by:
Hi all! In a my simple project I use callback to fill a dropdownlist with xml data returned by a web service, based on a value which is input via another dropdownlist. NOTE: I can't use...
106
by: bonneylake | last post by:
Hey Everyone, Well i don't know if my question should be in javascript/ajax or coldfusion, i figure this is more of a coldfusion question. But if this is in the wrong section let me know an all...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.