Subhash Sharma

Subhash Sharma
Subhash Sharma

This is Subhash Sharma(Software Engineer) Blog

Welcome to this blog and find every solution.............

Search This Blog

Software Engineer(Subhash Sharma)

Software Engineer(Subhash Sharma)
Software Engineer

Wednesday, July 28, 2010

Bind DropDown Common Function

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Master"].ConnectionString);
SqlTransaction tran=null ;
SqlCommand cmd;
SqlDataAdapter adp;
DataSet ds;
public void filldropdown(DropDownList ddl, string table, string DataTextField, string DataValueField)
{
adp = new SqlDataAdapter("Select " + DataValueField + "," + DataTextField + " from " + table + " order by '" + DataTextField + "' ", con);
DataSet ds = new DataSet();
adp.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
ddl.Items.Add(ds.Tables[0].Rows[i][DataTextField].ToString());
ddl.Items[i + 1].Value = ds.Tables[0].Rows[i][DataValueField].ToString();

}
}

}

No comments:

Post a Comment