Over 10 Million Study Resources Now at Your Fingertips

Download as :
Rating : ⭐⭐⭐⭐⭐
Price : $10.99
Pages: 2

And use this the datasource and call databind


The data that you’re trying to bind is available to the ItemDataBound event as e.Item.DataItem. This returns an Object that you need to cast to the correct type to use. The SqlDataSource, by default, accesses the database and returns a DataSet. Each row from the DataSet passed to the ItemDataBound event passes as a DataRowView, and e.Item.DataItem is cast to the correct type and stored for later use:

In order to data-bind, you need to be able to access the Web controls that make up the row. As you’re actually dealing with a template, the Web controls don’t exist directly on the page, so you can’t access them directly. You need to use the e.Item.FindControl() method to return the Web controls that you want to access, as you do for the two labels that make up the ItemTemplate:

// set the two labels
((Label)e.Item.FindControl("lblName")).Text = objData["PlayerName"].ToString();
((Label)e.Item.FindControl("lblCost")).Text = String.Format("{0:n}", objData["PlayerCost"]);

Player, so you set the ImageUrl of the Image (remember that you need to cast to the correct type) to disk.gif:

// set the correct image
if (objData["PlayerStorage"].ToString() == "Hard Disk") {
((Image)e.Item.FindControl("imgType")).ImageUrl = "./images/disk.gif";

Apart from the instances where you can’t use inline binding, such as you saw with the example of changing the image depending on the type of Player, there really is no functional difference between the two types of binding. The main difference is performance. Inline binding uses reflection to evaluate the arguments that are passed in and to return the results. If you use the ItemDataBound event you’re not using reflection, so it will be quicker.

Inline Binding Alternative

If you’re using the DataSet to provide the data source, you need to cast to a DataRowView:

<%# ((DataRowView)Container.DataItem)["ManufacturerName"] %>

How It Works
Login account
Login Your Account
Add to cart
Add to Cart
Make payment
Document download
Download File
PageId: ELIF53B066
Uploaded by :
Page 1 Preview
and use this the datasource and call databind
Sell Your Old Documents & Earn Wallet Balance