0

我不知道在标题中具体写什么。如果您认为它的标题不正确,我会更改它。这是问题所在。我正在将下拉列表绑定到数据集(表),我需要从其中需要名称、地址行 1、地址行 2、城市、电子邮件、国家/地区等字段......并且我想在标签上显示这些字段(值)。这是完整的代码:

        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();-----------???? 

这就是我卡住的地方。我需要来自特定列的值才能显示在特定标签上。我有什么选择?请指导....

4

1 回答 1

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();
   }
于 2013-03-25T10:36:04.180 回答