Home > DeveloperSection > Beginner > ListView Control in ASP.Net

ListView Control in ASP.Net


ADO.Net ADO.Net 
Ratings:
0 Comment(s)
 7623  View(s)
Rate this:

ListView Control in ASP.Net


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:ListView ID="ListView1" runat="server" ItemPlaceholderID="itemPlaceholder">

        <LayoutTemplate>

            <table border="0" cellpadding="1">

                <tr style="background-color: #E5E5FE">

                    <th align="left">

       <asp:LinkButton ID="lnkId" runat="server">Id</asp:LinkButton>

                    </th>

                    <th align="left">

       <asp:LinkButton ID="lnkName" runat="server">Name</asp:LinkButton>

                    </th>

                    <th align="left">

       <asp:LinkButton ID="lnkType" runat="server">Type</asp:LinkButton>

                    </th>

                    <th>

                    </th>

                </tr>

                <tr id="itemPlaceholder" runat="server">

                </tr>

            </table>

        </LayoutTemplate>

        <ItemTemplate>

            <tr>

                <td>

   <asp:Label runat="server" ID="lblId"><%#Eval("id") %></asp:Label>

                </td>

                <td>

   <asp:Label runat="server" ID="lblName"><%#Eval("pass")%></asp:Label>

                </td>

                <td>

     <asp:Label runat="server" ID="lblType"><%#Eval("name") %></asp:Label>

                </td>

                <td>

                </td>

            </tr>

        </ItemTemplate>

        <AlternatingItemTemplate>

            <tr style="background-color: #EFEFEF">

                <td>

      <asp:Label runat="server" ID="lblId"><%#Eval("id") %></asp:Label>

                </td>

                <td>

       <asp:Label runat="server" ID="lblName"><%#Eval("pass") %></asp:Label>

                </td>

                <td>

       <asp:Label runat="server" ID="lblType"><%#Eval("name") %></asp:Label>

                </td>

                <td>

                </td>

            </tr>

        </AlternatingItemTemplate>

    </asp:ListView>

protected void Page_Load(object sender, EventArgs e)

    {

        BindData();

    }

    public void 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:DataPager runat="server" ID="EmployeesDataPager" PageSize="1"

        PagedControlID="ListView1" onprerender="EmployeesDataPager_PreRender">

  <Fields>

  <asp:NumericPagerField />

</Fields>

</asp:DataPager>

 

 Write below code in DataPager PreRender event

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


Don't want to miss updates? Please click the below button!

Follow MindStick