Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 一旦绑定,网格视图就不会显示来自数据库的数据_C#_Asp.net_Gridview_C# 3.0 - Fatal编程技术网

C# 一旦绑定,网格视图就不会显示来自数据库的数据

C# 一旦绑定,网格视图就不会显示来自数据库的数据,c#,asp.net,gridview,c#-3.0,C#,Asp.net,Gridview,C# 3.0,我有一个网格视图,它在模板字段中有3个下拉列表和3个文本框。在网格视图的顶部,我有两个文本框文本框1和文本框2,在页面加载时初始化这些值。我还有3个按钮用于添加新行、保存和搜索。我希望我的网格视图在单击搜索按钮时显示数据库中的数据,即从表中选择*,其中文本框1和2等于某个值。我的HTML看起来像 请帮助我如何绑定我的gridview,因为在Text=property中,它所说的列名是不存在的,它所说的名为column name的属性。请帮助考虑在SQL查询中使用参数。账单头表格中是否有项目名称

我有一个网格视图,它在模板字段中有3个下拉列表和3个文本框。在网格视图的顶部,我有两个文本框文本框1和文本框2,在页面加载时初始化这些值。我还有3个按钮用于添加新行、保存和搜索。我希望我的网格视图在单击搜索按钮时显示数据库中的数据,即从表中选择*,其中文本框1和2等于某个值。我的HTML看起来像


请帮助我如何绑定我的gridview,因为在Text=property中,它所说的列名是不存在的,它所说的名为column name的属性。请帮助

考虑在SQL查询中使用参数。账单头表格中是否有项目名称列?我已更改查询,从账单头中选择项目名称、子项目、位置、许可证、已应用、修订,其中job='+job+'和leg='+leg+'仍然存在相同的错误@AndreiYes@Andrei项目名称是账单头中的列
    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" Text='<%# Bind("Item_name") %>'   DataValueField="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"   
                         DataValueField = "Sub_item" Text='<%# DataBinder.Eval(Container, "DataItem.Sub_item") %>'  DataTextField = "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" 
            DataTextField="Text" AppendDataBoundItems="true" Text='<%# DataBinder.Eval(Container, "DataItem.Applied") %>'  DataValueField="Value"  />
                </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="ButtonSave" runat="server"  Text="Save" OnClick="Save_Click" />
                    <asp:Button ID="ButtonAdd" runat="server"  Text="Add Row" />
                    <asp:Button ID="search" runat="server"  Text="Search"  OnClick="Search_Click"/>

                </FooterTemplate>
            </asp:TemplateField>
        </Columns>
     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 * from 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();