|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionAs we all know, the usage of the Eval and Bind methods can be expensive. Controls that use this method with Data-Binding Expressions are There are ways to lower the cost of usage of the In this example, we are not going to use the Why Using the codeWe are going to have protected void Page_Load(object sender, EventArgs e)
{
if (ProductsListView.EditItem == null)
{
ProductsListView.DataSource = LoadDataSet();
ProductsListView.DataBind();
}
}
As you can see, we are checking if this is “view mode” or “edit mode” to bind the right data to the protected void ProductsListView_ItemDataBound(object sender, ListViewItemEventArgs e)
{
ListViewDataItem dataItem = (ListViewDataItem)e.Item;
DataRowView drv = (DataRowView)dataItem.DataItem;
if (ProductsListView.EditItem == null)
{
Label companyName = (Label)e.Item.FindControl("CompanyName");
companyName.Text = drv["CompanyName"].ToString();
Label city = (Label)e.Item.FindControl("City");
city.Text = drv["City"].ToString();
Label customerID = (Label)e.Item.FindControl("CustomerID");
customerID.Text = drv["CustomerID"].ToString();
}
...
Here, we are again checking which template is being rendered, because if we are in “view mode”, and we are looking for Now, all data from the The Edit button’s protected void ProductsListView_ItemEditing(object sender, ListViewEditEventArgs e)
{
ProductsListView.EditIndex = e.NewEditIndex;
ProductsListView.DataBind();
}
Now, we are setting the ...
else if (ProductsListView.EditItem != null)
{
if (dataItem.DisplayIndex == ProductsListView.EditIndex)
{
TextBox nameTextBox = (TextBox)e.Item.FindControl("CompanyTextBox");
nameTextBox.Text = drv["CompanyName"].ToString();
TextBox cityTextBox = (TextBox)e.Item.FindControl("CityTextBox");
cityTextBox.Text = drv["City"].ToString();
TextBox customerID = (TextBox)e.Item.FindControl("CustomerIDTextBox");
customerID.Text = drv["CustomerID"].ToString();
}
}
}
This code is the second part of “ Now, protected void ProductsListView_ItemUpdating(object sender, ListViewUpdateEventArgs e)
{
TextBox nameTextBox=(TextBox)ProductsListView.EditItem.FindControl("CompanyTextBox");
TextBox cityTextBox=(TextBox)ProductsListView.EditItem.FindControl("CityTextBox");
TextBox customerID=(TextBox)ProductsListView.EditItem.FindControl("CustomerIDTextBox");
Update(nameTextBox.Text, cityTextBox.Text, customerID.Text);
ProductsListView.EditIndex = -1;
ProductsListView.DataSource = LoadDataSet();
ProductsListView.DataBind();
}
Now that we are in the “edit mode”, we are looking for Using values from Clicking on the Cancel button with fire the protected void ProductsListView_ItemCanceling(object sender, ListViewCancelEventArgs e)
{
ProductsListView.EditIndex = -1;
ProductsListView.DataSource = LoadDataSet();
ProductsListView.DataBind();
}
Same story applies for
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||