DataBinding Radiobutton组

时间:2014-12-12 07:14:36

标签: c# asp.net .net

我将数据绑定到单选按钮,但错误:DataBinding:'System.Char'不包含名为'ProfileRbnName'的属性..

和我的Db表是 的 Profile_RbnFilter 列是 ID,ProfileRbnName

   SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString());
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetGridData();
            RadioButton_Bind();
        }

    }
    public void GetGridData()
    {
        DataTable tableObject = new DataTable();
        string sqlstr = "select a.SID as ProfileID,a.StaffName as Name,b.Designation,a.Staffqualification as Qualification,a.Uploadphoto as ImageUrl,case a.Status when '1' then 'Active' when '2' then 'InActive' end as Status,convert(varchar(12),a.date,101) as Date from Adding_New_Staff a join Dental_Designation b on a.StaffDesignation=b.Did order by a.sid";
        tableObject = DAL.getData(sqlstr);
        GridProfile.DataSource = tableObject;
        GridProfile.DataBind();

    }
    private void RadioButton_Bind()
    {
        string cmdstr = "select ID,ProfileRbnName from Profile_RbnFilter";
        DataSet ds = new DataSet();
        SqlDataAdapter adp = new SqlDataAdapter(cmdstr, con);
        adp.Fill(ds);
        RbnFilter.DataSource = cmdstr;
        RbnFilter.DataValueField = "ID";
        RbnFilter.DataTextField = "ProfileRbnName";
        RbnFilter.DataBind();
    }
[<span style="font-size: 14px; font-weight: normal;">
                <asp:RadioButtonList ID="RbnFilter" runat="server" 
                RepeatDirection="Horizontal" OnSelectedIndexChanged="rbnSearchby_SelectedIndexChanged"
                    RepeatLayout="Flow" AutoPostBack="True">
                    <asp:ListItem Text="All" Value="10" Selected="true" />
                    <asp:ListItem Text="Doctors" Value="11" />
                    <asp:ListItem Text="Dental Hygienist & Assistants" Value="12" />
                    <asp:ListItem Text="Nurses" Value="13" />
                    <asp:ListItem Text="Front Office" Value="14" />
                </asp:RadioButtonList>
            </span>]
        </h1>
    </div>
    <div>
    <asp:GridView ID="GridProfile" runat="server" AutoGenerateColumns="False" 
            Width="100%" ShowHeaderWhenEmpty="True" class="Grid">
    <Columns>
    <asp:TemplateField HeaderText="Profile ID">
    <ItemTemplate>
        <asp:Label ID="lblProfileID" runat="server" Text='<%# Eval("ProfileID") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Name">
    <ItemTemplate>
        <asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Designation">
    <ItemTemplate>
        <asp:Label ID="lblDesignation" runat="server" Text='<%# Eval("Designation") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Qualification">
    <ItemTemplate>
        <asp:Label ID="lblQualification" runat="server" Text='<%# Eval("Qualification") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Image Url">
    <ItemTemplate>
        <asp:Label ID="lblImageUrl" runat="server" Text='<%# Eval("ImageUrl") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
   <asp:TemplateField HeaderText="Status">
    <ItemTemplate>
        <asp:Label ID="lblStatus" runat="server" Text='<%# Eval("Status") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
     <asp:TemplateField HeaderText="Date">
    <ItemTemplate>
        <asp:Label ID="lbldate" runat="server" Text='<%# Eval("Date") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>

1 个答案:

答案 0 :(得分:0)

 private void RadioButton_Bind()
    { cmdstr = "select ID,ProfileRbnName from Profile_RbnFilter";
        DataSet ds = new DataSet();
        SqlDataAdapter adp = new SqlDataAdapter(cmdstr, con);
        adp.Fill(ds);
        RbnFilter.DataSource = ds.Tables[0];
        RbnFilter.DataValueField = "ID";
        RbnFilter.DataTextField = "ProfileRbnName";
        RbnFilter.DataBind();
    };