我不知道究竟要写什么标题。如果你认为它的标题不正确,我会改变它。 这是问题所在。我将下拉列表绑定到数据集(表),我需要字段,如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();-----------????
这是我被困的地方。我需要特定列的值才能使用特定标签。我有什么选择?请指导......
答案 0 :(得分:0)
我理解你的问题,因为你可以做到这一点
// Get User's Details
DataSet ds=BindDropDownListToAUserAddress();
// Now from this dataset you can get the specific column like this
if(ds!=null && ds.Tables.Count>0)
{
// I am assuming that your table contains single row of specific user
string AddressLine1= ds.Tables[0].Rows[0]["AddressLine1"].ToString();
string AddressLine2= ds.Tables[0].Rows[0]["AddressLine2"].ToString();
}