How do i write a method for this code
Dear friends how do i write a method for the code marked in red as it is repeating. I want to write a method and call it in place of the code given in red.. Can u`ll plzzz help
===============================
string menuType;
GblDefinition obj = new GblDefinition();
protected void Page_Load(object sender, EventArgs e)
{
menuType = Request.QueryString["type"];
if (!Page.IsPostBack)
{
if (menuType == "city")
{
lbltitle.Text = "City Details";
BoundField field = new BoundField();
field.DataField = "cityid";
field.HeaderText = "City ID";
DataControlField col = field;
GVDetails.Columns.Add(col);
field = new BoundField();
field.DataField = "cityname";
field.HeaderText = "City";
col = field;
GVDetails.Columns.Add(col);
DataSet ds1 = obj.LoadDataSet("Select * from city_master");
GVDetails.DataSource = ds1.Tables[0];
GVDetails.DataBind();
}
else if (menuType == "state")
{
lbltitle.Text = "State Details";
BoundField field = new BoundField();
field.DataField = "stateid";
field.HeaderText = "State ID";
DataControlField col = field;
GVDetails.Columns.Add(col);
field = new BoundField();
field.DataField = "statename";
field.HeaderText = "State";
col = field;
GVDetails.Columns.Add(col);
DataSet ds2 = obj.LoadDataSet("select * from state_master");
GVDetails.DataSource=ds2.Tables[0];
GVDetails.DataBind();
}
else if(menuType=="country")
{
lbltitle.Text = "Country Details";
BoundField field = new BoundField();
field.HeaderText = "Country ID";
field.DataField = "countryid";
DataControlField col = field;
GVDetails.Columns.Add(col);
field = new BoundField();
field.DataField = "countryname";
field.HeaderText = "Country";
col = field;
GVDetails.Columns.Add(col);
DataSet ds3 = obj.LoadDataSet("select * from country_master");
GVDetails.DataSource=ds3.Tables[0];
GVDetails.DataBind();
}
else if(menuType=="category")
{
lbltitle.Text = "Category Details";
BoundField field = new BoundField();
field.HeaderText = "Category ID";
field.DataField = "categoryid";
DataControlField col = field;
GVDetails.Columns.Add(col);
field = new BoundField();
field.DataField = "categoryname";
field.HeaderText = "Category";
col = field;
GVDetails.Columns.Add(col);
DataSet ds4 = obj.LoadDataSet("select * from category_master");
GVDetails.DataSource=ds4.Tables[0];
GVDetails.DataBind();
}
else if(menuType=="designation")
{
lbltitle.Text = "Desination Details";
BoundField field = new BoundField();
field.HeaderText = "Designation ID";
field.DataField = "designationid";
DataControlField col = field;
GVDetails.Columns.Add(col);
field = new BoundField();
field.HeaderText = "Designation";
field.DataField = "designation";
col = field;
GVDetails.Columns.Add(col);
DataSet ds5 = obj.LoadDataSet("select * from designation_master");
GVDetails.DataSource=ds5.Tables[0];
GVDetails.DataBind();
}
}
=================================