Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
-Dman100-
Posting Yak Master
210 Posts |
Posted - 2007-02-05 : 15:09:26
|
I have a gridview control nested in a repeater. I have a method that returns an ArrayList, which I have binded to the Repeater.Here is the method:public static ArrayList GetArchiveYears(string newsType) { ArrayList a = new ArrayList(); try { // Create DataBase Instance Database db = DatabaseFactory.CreateDatabase("conn"); DbCommand dbCommand = db.GetStoredProcCommand("dbo.spGetAllPressReleaseArchiveYears"); db.AddInParameter(dbCommand, "type", DbType.String, newsType); using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { while (dataReader.Read()) { PressRelease e = new PressRelease(); e.release_year = Convert.ToInt32(dataReader["release_date"]); a.Add(e); } } } catch (Exception ex) { ErrorAndException.last_exception_msg = ex.ToString(); } return a; }I have a second method that is binded to the gridview. What I want to do is pass the years that are returned from my first method as an ArrayList as an argument into the second method.Here is the second method: public static ArrayList GetArchivePressReleasesByYear(Int32 Year, String newsType) { ArrayList a = new ArrayList(); try { // Create DataBase Instance Database db = DatabaseFactory.CreateDatabase("conn"); DbCommand dbCommand = db.GetStoredProcCommand("dbo.spGetArchivePressReleasesByYear"); db.AddInParameter(dbCommand, "year", DbType.String, Year); db.AddInParameter(dbCommand, "type", DbType.String, newsType); using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { while (dataReader.Read()) { PressRelease e = new PressRelease(); e.press_release_id = Convert.ToInt32(dataReader["press_release_id"]); e.description = dataReader["description"].ToString(); e.headline = dataReader["headline"].ToString(); e.release_date = Convert.ToDateTime(dataReader["release_date"]); e.press_release_type_id = Convert.ToInt32(dataReader["press_release_type_id"]); e.contents = dataReader["contents"].ToString(); a.Add(e); } } } catch (Exception ex) { ErrorAndException.last_exception_msg = ex.ToString(); } return a; }Here is my code-behind where I call the two methods and bind them to the controls:protected void Page_Load(object sender, EventArgs e){ //here is the call to my first method that is binded to the repeater this.Repeater1.DataSource = PressReleaseDAO.GetArchiveYears("archive"); this.Repeater1.DataBind();}protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e){ GridView GridView2 = new GridView(); GridView2 = ((GridView)(e.Item.FindControl("GridView2"))); if (!(GridView2 == null)) { // Here is the call to my second method, which I currently just have a hard-coded value of "2005" for the first argument //I want to pass in the year values returned from my first method GridView2.DataSource = PressReleaseDAO.GetArchivePressReleasesByYear(2005, "archive"); GridView2.DataBind(); }}I haven't been able to figure out how to pass the ArrayList as an argument to the second method. Can I use e.Item.DataItem to obtain the "year" and pass that year as the parameter into my second method? Will the itemDataBound event fire for each year? If so, can anyone explain how to accomplish this?Thanks. |
|
|
|
|
|
|