Tuesday, October 2

How to return List of Array


Introduction:-

                     Here I have explained how to return array list in webmethod.

Description:-


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;
}

 Here is the image which will shows that it is returning 4 records as array list during debug mode.


Code snipets
 


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.

ShibashishMnty
shibashish mohanty