---
title: "Listview databind error"  
description: "Listview databind error"  
author: "marcel ethan"  
published: 2014-02-03  
updated: 2014-02-03  
canonical: https://www.mindstick.com/forum/1940/listview-databind-error  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Listview databind error

I currenty have a [stored procedure](https://www.mindstick.com/articles/803/using-stored-procedure-in-asp-dot-net) that I am running and hoping to bind the [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) from the sp with my list view. However, I am unsure of how to go upon doing this.

Here is my current code. I was [thinking](https://www.mindstick.com/blog/11889/how-to-change-your-thinking-paradigm) it was similar to databinding a [gridview](https://www.mindstick.com/articles/873/update-delete-edit-gridview-in-asp-dot-net) but got lost doing it.

**[HTML](https://www.mindstick.com/articles/1530/design-a-simple-stylish-calculator-using-html-css-and-javascript)**

```
<asp:ListView runat="server">                        <LayoutTemplate>                            <table>                                <tr style="background-color:green">                                    <th><asp:LinkButton ID="lnkid" runat="server">Role ID</asp:LinkButton></th>                                    <th><asp:LinkButton ID="lnkdesc" runat="server">Role Description</asp:LinkButton></th>                                </tr>                            </table>                        </LayoutTemplate>                        <ItemTemplate>                            <tr>                                <td><asp:Label runat="server" ID="lblroleid">Role ID</asp:Label></td>                                <td><asp:Label runat="server" ID="lblroledesc">Role Desc></asp:Label></td>                            </tr>                        </ItemTemplate>                        <AlternatingItemTemplate>                            <tr style="background-color:Aqua">                                <td><asp:Label runat="server" ID="lblroleid">Role ID</asp:Label></td>                                <td><asp:Label runat="server" ID="lblroledesc">Role Desc</asp:Label></td>                            </tr>                        </AlternatingItemTemplate>                    </asp:ListView>
```

## c#

```
protected void roles()    {        txtSearch.Focus();        string[] queryvalue = txtSearch.Text.Split(' ');        SqlConnection myconn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Rollup2ConnectionString"].ConnectionString);        SqlCommand cmd = new SqlCommand();        cmd.CommandType = CommandType.StoredProcedure;        cmd.CommandText = "USP_GET_USER_ROLES";        cmd.Connection = myconn;        cmd.Parameters.Add("@NUID", SqlDbType.VarChar).Value = queryvalue[0].ToString();        myconn.Open();        SqlDataAdapter da = new SqlDataAdapter(cmd);        DataSet ds = new DataSet();        da.Fill(ds);        myconn.Close();        myconn.Dispose();    }
```

## Replies

### Reply by Pravesh Singh

Hi Marcel,\

This should help you out

```
<asp:SqlDataSource ID="sdsYourData" Runat="server"   
ProviderName="System.Data.SqlClient"   
ConnectionString="Server=(local);Database=Northwind;Integrated Security=SSPI;"   
SelectCommand="dbo.YourStoredProcName"    
<SelectParameters>       
<asp:Parameter Name="Param1" Type="String"/>>   
</SelectParameters></asp:SqlDataSource>
```

\
\


---

Original Source: https://www.mindstick.com/forum/1940/listview-databind-error

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
