| Author: ANIL PANDEY 29 Aug 2008 | Member Level: Diamond | Rating: Points: 6 |
hi,
u can refer the following code..
SqlConnection con = new SqlConnection(strConStr); SqlCommand cmd = new SqlCommand(); DataSet ds = new DataSet(); string strQuery = string.Empty; int lintUID = Convert.ToInt32(Session["UID"].ToString());
strQuery = "Select Colname from tbLeaveDetails where UID='" + lintUID + "' order by DateFrom "; con.Open(); cmd.Connection = con; cmd.CommandType = CommandType.Text; cmd.CommandText = strQuery; SqlDataAdapter ada = new SqlDataAdapter(strQuery,con); ada.Fill(ds);
cmbLeaves.DataSource = ds; cmbLeaves.DataBind();
//Closing the conection con.Close(); cmd.Dispose(); con.Dispose();
Thanks Anil
Thanks & Regards Anil Kumar Pandey
|
| Author: D.Jeya kumar(JK) 29 Aug 2008 | Member Level: Diamond | Rating: Points: 6 |
Hi,
Try the below code.it will bind the single column for the Both the text and as well as value field.
string strConStr = "someconneection"; SqlConnection conn = new SqlConnection(strConStr); SqlCommand cmd = new SqlCommand(); DataSet ds = new DataSet();
strQuery = "Select Columnname from Tblname where Userid=" + Userid + ""; con.Open(); cmd.Connection = con; cmd.CommandType = CommandType.Text; cmd.CommandText = strQuery; SqlDataAdapter ada = new SqlDataAdapter(strQuery, conn); ada.Fill(ds);
cmbLeaves.DataSource = ds; cmbLeaves.DataBind();
cons.Close(); cmd.Dispose(); con.Dispose();
DropDownList1.DataSource = ds.Tables[0]; DropDownList1.DataBind();
DropDownList1.DataTextField = "Columnname"; DropDownList1.DataValueField = "Columnname";
Regards JK
|
| Author: Ritesh N. Jain 29 Aug 2008 | Member Level: Gold | Rating: Points: 4 |
Little modification in above code,Assign DataTextField property before calling DataBind Method,and in case you are not going to use DataValueField there is no need to assign that property as it will uncessarily postback data to client.
DropDownList1.DataSource = ds.Tables[0]; DropDownList1.DataTextField = "Columnname"; DropDownList1.DataBind();
|