0

basically i am trying to populate a departments table and based on, say the change date, create a button for whatever departments fall within a certain date range. Problem is, the button creates but there is no data,

heres what i have so far - onPageLoad i bind the datasource which all works and displays until i try iTemDataBound

ASP.net

<asp:Repeater ID="DepartmentsList" runat="server" OnItemDataBound="DepartmentsList_ItemDataBound"/>
<HeaderTemplate>
     <table id="grouptable" class="table table-bordered table-striped"> 
      <thead>
              <tr>
          <th>Send</th>
          <th>ID</th>
          <th>Name</th>
          <th>Last Modified</th>
          <th>Actions</th>
          </tr>
           </thead>
           <tbody>
</HeaderTemplate>
<ItemTemplate>
              <tr>
                  <td>
                  <input type="checkbox" name="SendSelect[]" value="<%# Eval("Dept_ID") %>"</input></td>
                  <td><%# Eval("Dept_ID") %></td>
                  <td><a href="<%# Eval("gURL") %>"><%# Eval("DESC") %></a> </td>
                  <td><asp:Label ID="chg_date" runat="server" Text='<%# Eval("chg_date") %>'></asp:Label></td>
                  <td><a class="btn btn-info" href="<%# Eval("gURL") %>"><i class="icon-pencil icon-white"></i> Edit </a>&nbsp;&nbsp<asp:Button ID="bcastBtn" runat="server" Text="Send Now" CssClass="btn btn-danger" /> </td>
              </tr>
</ItemTemplate>
<FooterTemplate>
      </tbody>
      </table>
</FooterTemplate>
</asp:Repeater>

c# code

protected void DepartmentsList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            RepeaterItem item = e.Item;
            if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem) 
            {
                return;
            }
            else
            {
                Repeater bcastbuttonControl = (Repeater)item.FindControl("bcastBtn");
                Repeater DepartmentsList = (Repeater)item.FindControl("chg_date");

                //Coding for date validation to go here - at the minute just checking based on empty or null
                if (String.IsNullOrEmpty(chg_date.Text))
                {
                    bcastBtn.Visible = false;

                }
                else
                {
                    bcastBtn.Visible = true;
                }

            }
        }
burning_LEGION
  • 13,246
  • 8
  • 40
  • 52
JazziJeff
  • 721
  • 4
  • 17
  • 35

1 Answers1

2
Repeater bcastbuttonControl = (Repeater)item.FindControl("bcastBtn");
Repeater DepartmentsList = (Repeater)item.FindControl("chg_date");

I think there's a problem with the above code. You should be casting the first to a button and the second to a textbox (or whatever control it is but it sure is not a repeater) your data might be disappering when you add the onitemdatabound because of an invalid cast exception here

RepeaterItem item = e.Item;

remove the above code and instead simply use:

Label chg_date = (Label)e.Item.FindControl("chg_date");

and if that doesn't work either can you post your page_Load code?

Mutu Yolbulan
  • 1,052
  • 1
  • 8
  • 21
  • I agree that code is probably not right, but I would have thought something like that would have thrown a visible exception not one that is swallowed. – mclark1129 Aug 14 '12 at 11:58
  • tried making the change to Button bcastbuttonControl = (Button)item.FindControl("bcastBtn"); Label DepartmentsList = (Label)item.FindControl("chg_date"); and made no difference-its nearly as if its not seeing the dataset at all – JazziJeff Aug 14 '12 at 12:01
  • can you make the changes I just posted? – Mutu Yolbulan Aug 14 '12 at 12:08
  • 1
    'DepartmentList' is the name of your repeater, so you can't use it to cast a label into. Try renaming that variable name `Label chg_date = (Label) e.Item.FindControl("chg_date");` – mclark1129 Aug 14 '12 at 12:12