Introduction:-
Here I have explained how to return array
list in webmethod.
Description:-
In my previous article I have
explained AutoComplete text using Jquery and web services , How to bind state by selecting country dropdownlist using webmethod in Asp.net , How to select, update, insert data in database using Json, Jquery and Webservices , Ajax tab inside a gridview , Data binding in dropdownlist using Jquery , How to calculate differencebetween two dates using JQuery?
Here I am going to explain how return array list. If you
are using Ajax method to bind a
dropdownlist or any grid controls, then you
have to return some value from webmethod.
Where as you must return a list value to your
ajax success function to bind that control.
For this I am using here array list as return value.
Here is the web method I have used for this example:-
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat =
ResponseFormat.Json)]
public ArrayList
GetBranchForClassCourse(int classCourseId)
{
instituteBO
iBO = new instituteBO();
iBO.Operation = "GetSyllabusBranchNm";
iBO.ClsCrsID = Convert.ToInt32(classCourseId);
DataTable
dataTable = iBO.GetSyllabusBranchNm(iBO);
ArrayList
list = new ArrayList();
for (int i
= 0; i < dataTable.Rows.Count; i++)
{
list.Add(new ListItem(dataTable.Rows[i][1].ToString(),
dataTable.Rows[i][0].ToString()));
}
return
list;
}
If you have any question please feel free to comment here.
Hope you will like this article.
Keep coding……
Thanks Shibashish Mohanty
No comments:
Post a Comment
Please don't spam, spam comments is not allowed here.