Click here to Skip to main content
15,886,100 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Actually from my web service i am return the drop down values and binding in asp.net but in my asp.net page i am having two drop downs with different values now what i am doing is i am calling two different methods to return two lists but i am thinking to call only one method and return two different list from one call to service is it possible now Below is my code.

C#
public List<GrpUsersResp> GroupAllReferrals(GrpUsersReq Req)
        {

            using (SqlConnection con = new SqlConnection(con1))
            {
                SqlCommand cmd = new SqlCommand("Sp_Groups", con);
                cmd.CommandType = CommandType.StoredProcedure;
                //cmd.Parameters.Add("@PNMode", SqlDbType.NVarChar, 50).Value = "Groups";
                cmd.Parameters.Add("@GMode", SqlDbType.NVarChar, 50).Value = "GrpAllRefUsers";
                cmd.Parameters.Add("@GroupID", SqlDbType.NVarChar, 50).Value = Req.GroupID;
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                da.Fill(ds);
                
		DataTable dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    GrpUsersResp cls = new GrpUsersResp();
                    cls.UserID = dr["userid"].ToString();
                    cls.UserName = dr["UserName"].ToString();
                    GrpAllRefUsers.Add(cls);

                }

		DataTable dt = ds.Tables[1];
                foreach (DataRow dr in dt.Rows)
                {
                    GrpUsersResp cls = new GrpUsersResp();
                    cls.UserID = dr["userid"].ToString();
                    cls.UserName = dr["UserName"].ToString();
                    GrpReferrals.Add(cls);

                }

            }

	//But Here i want return two values how is it possible
            return GrpAllRefUsers;
        }
Posted
Comments
Guruprasad.K.Basavaraju 18-Apr-14 18:26pm    
are both lists are of same type ?
ntitish 21-Apr-14 0:01am    
Yes.

You could do a super list class

C#
public class returnList
{
    public List<GrpUsersResp> GrpUsersResp;
    public List<GrpUsersResp2> GrpUsersResp2;
}


// Then assign lists from method return values
returnList toReturn = new returnList(){GrpUsersResp = GroupAllReferrals(Req), GrpUsersResp2 = GroupAllReferrals2(Req2)};
 
Share this answer
 
Return as
Tuple<list><grpusersresp>,List<grpusersresp>></grpusersresp></grpusersresp></list>

or create a class with two properties public AllRefUsers and Referrals and use it as return type.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900