protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
bindDropDown();
}
}
public void bindDropDown()
{
//string[,] arr_Place = {
// {"Delhi","India"},
// {"Newyork","America"},
// {"Taiwan","China"},
// {"Colombo","Srilanka"},
// {"Lahore","Pakistan"},
// };
DataSet dsdata = new DataSet();
dsdata = GetData();
int rowcount = Convert.ToInt32(dsdata.Tables[0].Rows.Count);
int colcount = 2;
string [,] arr_Place = new String[rowcount,colcount];
string a = String.Empty;
string b = String.Empty;
// FILL THE ARRAY WITH THE DATA
for (int i = 0; i < dsdata.Tables[0].Rows.Count; i++)
{
a = dsdata.Tables[0].Rows[i][0].ToString();
b = dsdata.Tables[0].Rows[i][1].ToString();
arr_Place[i, 0] = a;
arr_Place[i, 1] = b;
}
// NOW AFTER FILLING , BIND THE ARRARY WITH THE DROPDOWNLIST
string str = String.Empty;
for (int i = 0; i < arr_Place.GetLength(0); i++)
{
str = arr_Place[i, 0].ToString() + " ---> " + arr_Place[i, 1].ToString();
DropDownList1.Items.Add(str);
// DropDownList1.Items.Add(new ListItem(arr_Place[i, 0], arr_Place[i, 1]));
}
DropDownList1.Items.Insert(0, "--select one--");
}
public DataSet GetData()
{
// [Usp_checkCountyAvailable_Test]
DataSet ds = new DataSet();
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["cn"].ConnectionString.ToString();
SqlDataAdapter adp = new SqlDataAdapter("Usp_checkCountyAvailable_Test", con);
adp.Fill(ds);
return ds;
}
0 comments:
Post a Comment