'System.Data.DataRowView'不包含名为'Item_name'的属性

时间:2014-03-26 14:28:28

标签: c# asp.net gridview

我一次又一次地收到这个错误。我希望我的搜索按钮在单击时在网格视图中显示数据。

<asp:gridview ID="Gridview1" runat="server" 
ShowFooter="True" 

    AutoGenerateColumns="false" 

    onselectedindexchanged="Gridview1_SelectedIndexChanged" BackColor="White" 
        BorderColor="#336666" BorderStyle="Double" BorderWidth="3px" CellPadding="4" 
        GridLines="Horizontal">
        <Columns>
            <asp:BoundField DataField="RowNumber" HeaderText="Row Number" />
            <asp:TemplateField HeaderText="Item name">
                <ItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" Height="25px" Width="119px" 
          DataTextField = "Item_name"  DataValueField = "Item_name" SelectedValue='<%# Eval("Item_name") %>'    
                         AppendDataBoundItems="true">
                    </asp:DropDownList>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Sub item">
                <ItemTemplate>
                    <asp:DropDownList ID="DropDownList2" runat="server" Height="25px" Width="119px" 
               AppendDataBoundItems="true"   DataTextField = "Sub_item"  DataValueField = "Sub_item"
                          SelectedValue='<%# DataBinder.Eval(Container, "DataItem.Sub_item") %>'  
                           />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Location">
                <ItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Location") %>' ></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Permit number">
                <ItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server"  Text='<%# DataBinder.Eval(Container, "DataItem.Permit_no") %>' ></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Applied">
                <ItemTemplate>
                    <asp:DropDownList ID="DropDownList3" runat="server"

            Height="25px" Width="119px" 
            AppendDataBoundItems="true"  
             DataValueField = "Applied"   SelectedValue='<%# DataBinder.Eval(Container, "DataItem.Applied") %>' DataTextField = "Applied"  />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Revision">
                <ItemTemplate>
                    <asp:TextBox ID="TextBox3" runat="server"  Text='<%# DataBinder.Eval(Container, "DataItem.Revision") %>' ></asp:TextBox>
                </ItemTemplate>
                <FooterStyle HorizontalAlign="Right" />
                <FooterTemplate>

                    <asp:Button ID="search" runat="server"  Text="Search"  OnClick="Search_Click"/>

我的按钮代码是

 if (TextBox4.Text != null && TextBox5.Text != null)
        {
            string job = TextBox4.Text.ToString();
            string leg = TextBox5.Text.ToString();
            string connString = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
            using (var conn = new SqlConnection(connString))
            using (var cmd = conn.CreateCommand())
            {
                Response.Write(job);
                Response.Write(leg);
                conn.Open();
                SqlCommand comand = new SqlCommand("SELECT [Item_name],[Sub_item],[Location],[Permit_no],[Applied],[Revision],[RowNumber] FROM [ADS].[dbo].[Billing_heads] where job# = '" + job + "' AND leg#='" + leg + "' ", conn);
                // try
                //{

                SqlDataAdapter adp = new SqlDataAdapter(comand);
                DataSet ds = new DataSet();
                adp.Fill(ds);
                //gvPros is the ID of GridView.
                Gridview1.DataSource = ds;
                Gridview1.DataBind();
                }

当我的页面加载时,它给了我这个错误。我已经匹配了我的专栏名称拼写,但我仍然使用它。请查看并帮助我。

0 个答案:

没有答案