articles

ListView Control in ASP.Net

Pushpendra Singh17772 08-Nov-2010

The ASP.NET ListView control enables you to bind to data items that are returned from a data source and display them. You can display data in pages. You can display items individually, or you can group them.

The ListView control displays data in a format that you define by using templates and styles. It is useful for data in any repeating structure, similar to the DataList and Repeater controls. However, unlike those controls, with the ListView control you can enable users to edit, insert, and delete data.

BindData in ListView:

 

<asp:ListViewID="ListView1"runat="server"ItemPlaceholderID="itemPlaceholder">
        <LayoutTemplate>
            <tableborder="0"cellpadding="1">
                <trstyle="background-color: #E5E5FE">
                    <thalign="left">
       <asp:LinkButtonID="lnkId"runat="server">Id</asp:LinkButton>
                    </th>
                    <thalign="left">
       <asp:LinkButtonID="lnkName"runat="server">Name</asp:LinkButton>
                    </th>
                    <thalign="left">
       <asp:LinkButtonID="lnkType"runat="server">Type</asp:LinkButton>
                    </th>
                    <th>
                    </th>
                </tr>
                <trid="itemPlaceholder"runat="server">
                </tr>
            </table>
        </LayoutTemplate>
        <ItemTemplate>
            <tr>
                <td>
   <asp:Labelrunat="server"ID="lblId"><%#Eval("id") %></asp:Label>
                </td>
                <td>
   <asp:Labelrunat="server"ID="lblName"><%#Eval("pass")%></asp:Label>
                </td>
                <td>
     <asp:Labelrunat="server"ID="lblType"><%#Eval("name") %></asp:Label>
                </td>
                <td>
                </td>
            </tr>
        </ItemTemplate>
        <AlternatingItemTemplate>
            <trstyle="background-color: #EFEFEF">
                <td>
      <asp:Labelrunat="server"ID="lblId"><%#Eval("id") %></asp:Label>
                </td>
                <td>
       <asp:Labelrunat="server"ID="lblName"><%#Eval("pass") %></asp:Label>
                </td>
                <td>
       <asp:Labelrunat="server"ID="lblType"><%#Eval("name") %></asp:Label>
                </td>
                <td>
                </td>
            </tr>
        </AlternatingItemTemplate>
    </asp:ListView>
protectedvoid Page_Load(object sender, EventArgs e)
    {
        BindData();
    }
    publicvoid BindData()
    {
        ListView1.DataSource = Class1.execute_spfill_grid("insert_reg");
        ListView1.DataBind();
 
    }

 

ListView Control in ASP.Net

ListView Control in ASP.Net

Paging in ListView:
Use Data Pager control for paging in ListView
<asp:DataPagerrunat="server"ID="EmployeesDataPager"PageSize="1"
        PagedControlID="ListView1"onprerender="EmployeesDataPager_PreRender">
  <Fields>
  <asp:NumericPagerField/>
</Fields>
</asp:DataPager>

 

 Write below code in DataPager PreRender event
protectedvoid EmployeesDataPager_PreRender(object sender,  EventArgs e)
    {
        ListView1.DataSource = Class1.execute_spfill_grid("insert_reg");
        ListView1.DataBind();
 
    }


ListView Control in ASP.Net

ListView Control in ASP.Net



Updated 07-Sep-2019

Leave Comment

Comments

Liked By