1

Array List value not binding to Gridview,It always return message:

A field or property with the name 'CUSTOMER_NAME' was not found on the selected data source.

I have GridView as

<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>

DisplayCustomer.aspx.cs:

protected void GetCustomer(object sender, EventArgs e)
{
     CutomerService cs    = new CutomerService();
     ArrayList alCustomer = cs.GetCustomerDetail();

     GdVClient.DataSource = alCustomer;
     GdVClient.DataBind();
}

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;
}

How can I bind the value to the GridView? Please help. Thank you.

naveen
  • 53,448
  • 46
  • 161
  • 251
  • Are you still using .NET 1.1 or why don't you use generic collections? – Tim Schmelter Jan 15 '16 at 12:03
  • Also, dont use a static connection(`SampleProjectConn.SPConn`) in ASP.NET. Otherwise you'll encounter [various issues and exceptions](http://stackoverflow.com/questions/9705637/executereader-requires-an-open-and-available-connection-the-connections-curren). Instead always open/close it where you use it, best by using the `using`-statement. Your `ExecuteDataset` method can also introduce a possibe sql-injection issue. Always use sql parameters instead of string concatenation. – Tim Schmelter Jan 15 '16 at 12:05
  • You can directly return datatable or dataset and can bind it to Gridview. Why do you need arraylist? – D Mayuri Jan 15 '16 at 12:07
  • @DMayuri I cant edit Dataset values so i am adding the values to hash table than returning through array collection.but in above code i didn't edited any field. – user2114045 Jan 18 '16 at 03:29

0 Answers0