Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.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# 无法将ArrayList值绑定到GridView_C#_Asp.net_Gridview - Fatal编程技术网

C# 无法将ArrayList值绑定到GridView

C# 无法将ArrayList值绑定到GridView,c#,asp.net,gridview,C#,Asp.net,Gridview,数组列表值未绑定到Gridview,它始终返回消息: 在所选数据源上找不到名为“CUSTOMER_name”的字段或属性 我有GridView作为 <asp:GridView ID="GdVClient" runat="server" AllowPaging="True" CellPadding="4" ForeColor="#333333" GridLines="Vertical" Style="width: 700px; height:

数组列表值未绑定到Gridview,它始终返回消息:

在所选数据源上找不到名为“CUSTOMER_name”的字段或属性

我有GridView作为

<asp:GridView ID="GdVClient" runat="server" 
    AllowPaging="True"
    CellPadding="4" 
    ForeColor="#333333" 
    GridLines="Vertical" 
    Style="width: 700px; height: auto;">
    <Columns>
        <asp:BoundField DataField="CUSTOMER_NAME" />
    </Columns>
</asp:GridView>
CutomerService.cs:

[WebMethod(Description = "GetCustomerDetail1")]
public ArrayList GetCustomerDetail()
{
    DataSet dsCustomer = new DataSet();
    Hashtable htDetails = new Hashtable();
    ArrayList alDetails = new ArrayList();

    String sqlCustomer = "SELECT [CUSTOMER_NAME]FROM [SAMPLE].[dbo].  [CUSTOMER]";
    dsCustomer = SqlHelper.ExecuteDataset(SampleProjectConn.SPConn,     CommandType.Text, sqlCustomer);

    foreach(DataRow row in dsCustomer.Tables[0].Rows)
    {
        htDetails = new Hashtable();
        foreach(DataColumn col in dsCustomer.Tables[0].Columns)
        {
            htDetails.Add(Convert.ToString(col.ColumnName),  Convert.IsDBNull(row[col.ColumnName]) ? string.Empty : Convert.ToString(row[col.ColumnName]));
        }
        alDetails.Add(htDetails);
    }

    return alDetails;
}

如何将该值绑定到GridView?请帮忙。谢谢。

您还在使用.NET 1.1吗?或者为什么不使用通用集合?另外,不要在ASP.NET中使用静态连接(
SampleProjectConn.SPConn
)。否则你会遇到麻烦。相反,总是在使用它的地方打开/关闭它,最好使用
using
-语句。您的
ExecuteDataset
方法也可能引入sql注入问题。始终使用sql参数而不是字符串连接。您可以直接返回datatable或dataset,并将其绑定到Gridview。为什么需要arraylist?@DMayuri我无法编辑数据集值,因此我将值添加到哈希表中,而不是通过数组集合返回。但在上面的代码中,我没有编辑任何字段。您是否仍在使用.NET 1.1或为什么不使用通用集合?另外,不要在ASP.NET中使用静态连接(
SampleProjectConn.SPConn
)。否则你会遇到麻烦。相反,总是在使用它的地方打开/关闭它,最好使用
using
-语句。您的
ExecuteDataset
方法也可能引入sql注入问题。始终使用sql参数而不是字符串连接。您可以直接返回datatable或dataset,并将其绑定到Gridview。为什么需要arraylist?@DMayuri我无法编辑数据集值,因此我将值添加到哈希表中,而不是通过数组集合返回。但在上面的代码中,我没有编辑任何字段。
[WebMethod(Description = "GetCustomerDetail1")]
public ArrayList GetCustomerDetail()
{
    DataSet dsCustomer = new DataSet();
    Hashtable htDetails = new Hashtable();
    ArrayList alDetails = new ArrayList();

    String sqlCustomer = "SELECT [CUSTOMER_NAME]FROM [SAMPLE].[dbo].  [CUSTOMER]";
    dsCustomer = SqlHelper.ExecuteDataset(SampleProjectConn.SPConn,     CommandType.Text, sqlCustomer);

    foreach(DataRow row in dsCustomer.Tables[0].Rows)
    {
        htDetails = new Hashtable();
        foreach(DataColumn col in dsCustomer.Tables[0].Columns)
        {
            htDetails.Add(Convert.ToString(col.ColumnName),  Convert.IsDBNull(row[col.ColumnName]) ? string.Empty : Convert.ToString(row[col.ColumnName]));
        }
        alDetails.Add(htDetails);
    }

    return alDetails;
}