Gridview nested in Repeater Data Issue

Last post 02-19-2008 2:53 PM by kgarl. 2 replies.

Sort Posts:

  • Gridview nested in Repeater Data Issue

    11-28-2007, 11:52 AM
    • Loading...
    • kgarl
    • Joined on 12-28-2006, 11:32 AM
    • Dallas, TX
    • Posts 9
    I am trying to datasource a gridview within a repeater. I am having issues passing the data from the repeater to the gridview (either to source it manually or set the Gridview's SQLDataSource attributes wtihin the Repeater_ItemDataBound event.)
    The XML will look similar to this (all dummy data):

    <root>
       <
    Unit type="District" number="221">
          <
    Employee name="Joe Smith" unitType="Store" unitNum="2213" reviewStatus="Pending" empNum="12345"></Employee>
          <
    Employee name="James Jones" unitType="Store" unitNum="2365" reviewStatus="Pending" empNum="23654"></Employee>
       </Unit>
       <
    Unit type="District" number="254">
          <
    Employee name="Rosie Worcester" unitType="Store" unitNum="2369" reviewStatus="Pending" empNum="26358"></Employee>
          <
    Employee name="George Washington" unitType="Area" unitNum="254" reviewStatus="Pending" empNum="95682"></Employee>
       </Unit>
    </
    root>

    I need an asp:Label within the repeater to load the <Unit> type and number and then pass the employee information to the gridview. Any suggestions on how I might do this? I cannot directly access the Gridview or SQLDataSource within the Repeater_ItemDataBound event.

    Thanks in advance!!

    K. Garl

  • Re: Gridview nested in Repeater Data Issue

    11-28-2007, 3:08 PM
    Answer
    • Loading...
    • codeasp
    • Joined on 06-16-2004, 9:19 PM
    • Posts 2,153

    Check this article.  It shows how to use the xmldatasource with nested databound controls.

    http://aspnet.4guysfromrolla.com/articles/092706-1.aspx

  • Re: Gridview nested in Repeater Data Issue

    02-19-2008, 2:53 PM
    Answer
    • Loading...
    • kgarl
    • Joined on 12-28-2006, 11:32 AM
    • Dallas, TX
    • Posts 9
    Here is what I ended up doing:

    In the Page_Load:

    //Define repeater event handler before databinding
    MyReviewsRpt.ItemDataBound += new RepeaterItemEventHandler(MyReviewsRpt_ItemDataBound);
    //Load repeater with XML file
    XmlReader XmlReader = controller.GetMyReviewsXML(emp.EmpID);
    DataSet ds = new DataSet();
    if (XmlReader == null)
      {
        NoReviewsLbl.Visible =
    true;
      }
    else
      {
        ds.ReadXml(XmlReader);
        MyReviewsRpt.DataSource = ds;
        MyReviewsRpt.DataBind();
      }


    In the Repeater's Item Data Bound event:

    protected void MyReviewsRpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
    RepeaterItem item = e.Item;
    if ((item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingItem))
      {
         
    //Find Nested GridView
         
    MyReviewsGrid = (GridView)item.FindControl("MyReviewsGrid");
         
    //Find Unit Type/Unit Number for individual items
         
    HeaderUnitNum = (Label)item.FindControl("HeaderUnitNum");
          HeaderUnitType = (
    Label)item.FindControl("HeaderUnitType"); 
         
    CollapsiblePanelExtender = (AjaxControlToolkit.CollapsiblePanelExtender)item.FindControl("CollapsiblePanelExtender");

    if (emp.UnitType == "HR" || emp.UnitType == "President" || emp.UnitType == "HRField")
      {
         OverallSalaryWSLink.Visible =
    false;
      }

       //Create GridView event handler after control definition but before binding
      
    MyReviewsGrid.RowDataBound += new GridViewRowEventHandler(MyReviewsGrid_RowDataBound);
       MyReviewsGrid.DataBound +=
    new EventHandler(MyReviewsGrid_DataBound);
      
    //Load Data from XML File
      
    DataRowView drv = (DataRowView)item.DataItem;
       MyReviewsGrid.DataSource = drv.CreateChildView(
    "Unit_Employee");
       MyReviewsGrid.DataBind();
    }

     I had never tried to bind to a control created by another in this fashion. I have a repeater that repeats gridviews within a collapsible panel. Very clean!

    Filed under: , ,
Page 1 of 1 (3 items)
Microsoft Communities
Page view counter