Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populate a GridView from a return dataset

Status
Not open for further replies.

RaulMA

Programmer
Apr 4, 2006
19
US
How can I populated a GridView located in a aspx page

from this class located in another utility project.


public dsCompany selectCompany(string region, string type, string status, string shortname)
{


try
{
SqlDataAdapter da = new SqlDataAdapter("SearchCompany", sqlConn);
da.SelectCommand.CommandType = CommandType.StoredProcedure;


SqlParameter paramRegionName = new SqlParameter("@Region_Name", SqlDbType.VarChar, 40);
paramRegionName.Value = region;
da.SelectCommand.Parameters.Add(paramRegionName);

SqlParameter paramType = new SqlParameter("@Type", SqlDbType.VarChar, 20);
paramType.Value = type;
da.SelectCommand.Parameters.Add(paramType);

SqlParameter paramStatus = new SqlParameter("@Client_Active_Status", SqlDbType.VarChar, 30);
paramStatus.Value = status;
da.SelectCommand.Parameters.Add(paramStatus);

SqlParameter paramShortName = new SqlParameter("@Short_Name_1", SqlDbType.VarChar, 30);
paramShortName.Value = shortname;
da.SelectCommand.Parameters.Add(paramShortName);


dsCompany ds = new dsCompany();
da.Fill(ds, "Companies");
return ds;
}

catch (Exception ex)
{
return null;
}
finally
{
sqlConn.Close();
}


}

Thanks

 
1. Get a copy of the DLL on your computer if you don't already have one
2. Add a reference to that DLL in your new project
3. Create a new instance of the class (if needed) and call the function (passing it any needed parameters)
4. Set the .DataSource of your gridview to the returned dataset
5. YourGridView.Databind();

That should do it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top