我不知道標題中究竟寫什麼。如果你認爲它是一個不正確的標題,我會改變它。 繼承人的問題。我將一個下拉列表綁定到一個數據集(一個表),我需要的字段如Name,AddressLine1,AddressLine2,City,Email,Country等等。我想在標籤上顯示這些字段(值)。下面是完整的代碼:將列指定給數據集
public String GetSessionObject()
{
string strSession = "";
if (HttpContext.Current.Session["SessionEmail"] != null)
{
strSession = HttpContext.Current.Session["SessionEmail"].ToString();
}
return strSession;
}
public DataSet BindDropDownListToAUserAddress()
{
DataSet ds = new DataSet();
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"]);
con.Open();
string strQuery = "SELECT *, FirstName +' '+ LastName as FullName from AUserAddress where AUser_ID = (Select ID from AUser where Email='" + GetSessionObject() + "')";
SqlCommand cmd = new SqlCommand(strQuery, con);
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
da.Fill(ds, "AUserAddress");
con.Close();
return ds;
}
ddlName.DataSource = objBindDDL.BindDropDownListToAUserAddress().Tables["AUserAddress"];
ddlName.DataTextField = "FullName";
ddlName.DataBind();
lblDisplayAddressLine1.Text = objBindDDL.BindDropDownListToAUserAddress().Tables["AUserAddress"].Columns.("AddressLine1").ToString();-----------????
這就是我卡住的地方。我需要來自特定列的值才能顯示特定的標籤。我有什麼選擇?請指導....
很抱歉,但我沒有得到你的問題。您是否要在標籤中顯示所選用戶的地址?那麼你應該使用'selectedIndexChanged'事件。什麼是你的DDL的DataValue字段? – Sachin 2013-03-25 10:19:48
看到我會告訴你...我想使用創建的數據集(中間代碼)在標籤上顯示文本(地址,城市,州等)......它不在選定的indexchanged上,它應該在頁面上。 – adityawho 2013-03-25 10:23:26
我已經發布了我的答案,看看那個。 – Sachin 2013-03-25 10:36:26