如何在ASP.NET中进行ListView DataSource的自定义绑定



我有一个列表视图数据源,该数据源从表中获取数据,该数据具有劳力,名字,姓氏,手机号码。我有另一个表格用角色名称映射劳力。

在ASP.NET表单中,我将数据源绑定到了检索RoalId,first Name和姓氏的表。我正在使用后端编程来这样做。

我的问题是,我如何在listView中显示rolename而不是ralesid。

我的后端代码就像这个

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        this.BindListView();
    }
}
private void BindListView()
{
    string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
    {
        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.CommandText = "SELECT roleId, fName, lname,mobilenumber Country FROM Admin";
            cmd.Connection = con;
            using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
            {
                DataTable dt = new DataTable();
                sda.Fill(dt);
                lvCustomers.DataSource = dt;
                lvCustomers.DataBind();
            }
        }
    }
}

显然,这返回了整数的作用,现在我想显示角色名称而不是角色。我可以从roletable中获得rolename,其中roletable用rolename映射roalid。

在下面使用内在加入。这是一个简单的修复,而不是在获取数据后更新数据。

"从管理中选择rolename,fname,lname,mobilenumber country a a a a.roleid上的内在roletable r = roleid = r.roleid";

最新更新