Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting DataItems from Repeaters 1

Status
Not open for further replies.

TeaAddictedGeek

Programmer
Apr 23, 1999
271
US
I'm trying to access a dataitem's value that is bound to a Repeater, but it seems that the only examples I've found that work for what I'm trying to do are in VB. For instance:

If e.Item.DataItem("amount") > 50 Then

I need to access the DataItem using similar syntax but can't seem to find the C# equivalent.

The data being used is a DataTable within a DataSet. Very basic, since I don't have it hooked up to a database yet. Just trying to get the initial logic working first. Here's part of it:

DataSet ds = new DataSet();
DataTable dt = ds.Tables.Add("Cities");
dt.Columns.Add("City", Type.GetType("System.String"));
dt.Columns.Add("Zone", Type.GetType("System.String"));

DataRow dr = dt.NewRow();
dr[0] = "Boston";
dr[1] = "1A";
dt.Rows.Add(dr);
[...]
rtASAP.DataSource = ds;
rtASAP.DataMember = "Cities";
rtASAP.DataBind();

What I'm looking to do is access the Column City's value from the DataBind above within the ItemDataBound event.

Thanks in advance!

"The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs."
-Joseph Weizenbaum
 
Code:
protected void Page_Init(object sender, EventArgs e)
{
   rtASAP.OnItemDataBound += new EventHandler(rtASAP_ItemDataBount);
}

protected void Page_Load(object sender, EventArgs e)
{
  if(!Page.IsPostback)
  {
     DataSet ds = new DataSet();
     DataTable dt = ds.Tables.Add("Cities");
     dt.Columns.Add("City", typeof(string));
     dt.Columns.Add("Zone", typeof(string));
     dt.Rows.Add(object[] { "Boston", "1A" });
     dt.Rows.Add(object[] { "NY City", "2B" });

     rtASAP.DataSource = ds;
     rtASAP.DataMember = "Cities";
     rtASAP.DataBind();
  }
}
protected void rtASAP_ItemDataBount(object sender, RepeaterItemEventArgs e)
{
   if (e.Row.RowIndex > -1)
   {
      DataRowView data = (DataRowView)e.Row.DataItem;
      string city = (string)data["City"];
   }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thanks! That worked.

"The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs."
-Joseph Weizenbaum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top