C# : Tutorial of Asp.net with c# and example

Example and code about windows application, web application, SQL, C#, WPF etc which is helpful to developer and programer.

Search This Blog

Data bind in asp.net using Listview control instead of eval method

♠ Posted by Unknown in , at Friday, August 15, 2014

Use and Importance of List View Control 

Data Binding in aps.net without Eval Bind method

The use of the Eval and Bind methods can be complicated.

This method with Data-Binding Expressions are GridView,, Repeater, and ListView. These are actually Data-Bound controls which can be bound to Data Source controls such as SqlDataSource.

Here ways to reduce the complexity of usage of the Eval method.

example of Without eval. If you are using eval method to bind data for large web applications with millions of clicks per minute, the Eval method isn’t really the perfect solution. There is everything hard-coded in HTML.

In this example, we are not going to use the Eval or Bind methods, nor are we are going to use Data Source controls. We are going to do everything from the server side.

ListView : This control has some very important event that we are going to heavily manipulate - ItemDataBound. It has templates, e.g., ItemTemplate and EditItemTemplate. Our example is going to bind the data from a DataSet, edit this data, and update it.

protected void Page_Load(object sender, EventArgs e)
    if (ListView.EditItem == null)
        ListView.DataSource = LoadDataSet();

We are take Label controls in the ItemTemplate and TextBox controls in the EditItemTemplate. In the “edit mode”, every Label is going to be switched with a TextBox.

protected void Item_ListView_ItemDataBound(object sender, ListViewItemEventArgs e)

    ListViewDataItem dataItem = (ListViewDataItem)e.Item;
    DataRowView datarow_view = (DataRowView)dataItem.DataItem;
    if (ProductsListView.EditItem == null)

        Label organization = (Label)e.Item.FindControl("organization");
        organization.Text = datarow_view["organization"].ToString();

        Label city = (Label)e.Item.FindControl("City");
        city.Text = datarow_view["City"].ToString();

        Label clientId = (Label)e.Item.FindControl("clientId");
        clientId.Text = datarow_view["clientId"].ToString();


Improve Your Answer as comment below.

If our post is useful please share and comment on our post for more post and detail Visit :



Post a Comment