DataBinding:'System.Data.DataRowView'不包含名称为'name'的属性 [英] DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'name'

查看:58
本文介绍了DataBinding:'System.Data.DataRowView'不包含名称为'name'的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Asp.code



Asp.code

<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1" DataTextField="socialname">
                                 <asp:ListItem text="select">Comment using
                             
                             <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:prakashConnectionString %>" SelectCommand="SELECT [socialname] FROM [socialnetwork]">
                             <asp:Label ID="Label3" runat="server" Text="Label">





C#代码





C# code

protected void Bindddl() {

    con.Open();
    SqlCommand cmd = new SqlCommand("select * from socialnetwork", con);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds);
    DropDownList1.DataTextField = "socialname";
    DropDownList1.DataValueField = "name";
    DropDownList1.DataBind();
    con.Close();
}

protected void BindTitle()
{
    if (DropDownList1 != null)
    {
        foreach (ListItem li in DropDownList1.Items)
        {
            li.Attributes["title"] = "social/" + li.Value; // it ll set the value of items in dropdownlist as tooltip

        }
    }
}

protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
{
    BindTitle();
    Label3.Text = DropDownList1.SelectedItem.Text;
    Label3.Text = "Commented by";
}

推荐答案

ConnectionStrings:prakashConnectionString%> SelectCommand = SELECT [socialname] FROM [socialnetwork] >
< asp:标签 ID = Label3 runat = server 文本 = 标签 >
ConnectionStrings:prakashConnectionString %>" SelectCommand="SELECT [socialname] FROM [socialnetwork]"> <asp:Label ID="Label3" runat="server" Text="Label">




C#代码





C# code

protected void Bindddl() {

    con.Open();
    SqlCommand cmd = new SqlCommand("select * from socialnetwork", con);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds);
    DropDownList1.DataTextField = "socialname";
    DropDownList1.DataValueField = "name";
    DropDownList1.DataBind();
    con.Close();
}

protected void BindTitle()
{
    if (DropDownList1 != null)
    {
        foreach (ListItem li in DropDownList1.Items)
        {
            li.Attributes["title"] = "social/" + li.Value; // it ll set the value of items in dropdownlist as tooltip

        }
    }
}

protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
{
    BindTitle();
    Label3.Text = DropDownList1.SelectedItem.Text;
    Label3.Text = "Commented by";
}


我认为你的select语句中不存在name。



所以,解决方案如下。

I think "name" is not exist in your select statement.

So, Solution will be as follow.
DropDownList1.DataValueField = "socialname";


在您的SQL查询中,您的查询为

At your sql query u are query as
SELECT [socialname] FROM [socialnetwork]





但是在绑定时你使用值字段为

DropDownList1.DataValueField =name;



所以更改您的代码或从数据库中检索该名称列,您可以将socialnameas text和name设置为下拉列表的值字段。



But while binding you are using value field as
DropDownList1.DataValueField = "name";

so change your code or retrieve that name column from database and you can set socialnameas text and name as value field of the dropdown.


这篇关于DataBinding:'System.Data.DataRowView'不包含名称为'name'的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆