0

Hi I have a user control inside repater item template .I want to hide the user controls column based on certain values coming in the string.Below are my code

<asp:Repeater runat="server" ID="MyRepeater" OnItemDataBound="MyRepeater_ItemDataBound">
                    <ItemTemplate>
                        <uc2:UCToolEventSummary runat="server" ID="UCSummary"
                            TaskId='<%#Eval("TaskId")%>'
                            SystemName='<%#Eval("SystemName")%>'
                            ResourceName='<%#Eval("ToolName")%>'
                            Requestor='<%#Eval("Requestor")%>'
                            CategoryName='<%#Eval("CategoryName")%>'
                    </ItemTemplate>
                </asp:Repeater>

I want to hide the columns based on a string list

list<string> columnsHidden = "SystemName,CategoryName"

So systemname and categoryName should be hidden in the user control

I tried below approach in item databound event but could not able to do that

 protected void MyRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
     List<String> columnsList = new List<String>();
                columnsList = "SystemName,CategoryName";
    
                if (e.Item.ItemType == ListItemType.Item ||
            e.Item.ItemType == ListItemType.AlternatingItem)
                {
                   
    
                    var control = e.Item.FindControl("UCSummary");
                    foreach (String columnName in columnsList)
                    {
    
                    }
                }
}

My Usercontrol code is below

    <table class="table table-bordered">
    <tr class="row">
        <td class="col25">
            Task Id: <%=TaskId %>
        </td>
        <td  class="col25">
            System Name: <%=SystemName %>
        </td>
         <td  class="col25">
            Task Status: <%=TaskStatus %>
        </td >
          <td  class="col25">
            Requestor:  <%=Requestor %>
        </td>

 <td  class="col25">
            Request Type: <%=CategoryName %> 
        </td>
    </tr>
    </table>

Can anybody help me on this? Thank you

sandeep.mishra
  • 825
  • 4
  • 19
  • 40

1 Answers1

0

You have in your markup added some custom attributes with the columns you need. Thus, on item data bound you should be able to grab/get that control, and then hide/show other columns (controls) in that repeater.

And I don't see the need for a for each loop. The item data bound fires ONE time for each row on data bind. Thus:

var UCToolEventSummary UC = e.Item.FindControl("UCSummary");
if UC.Attributes.item("CategoryName") = "zoo" {
    get other controls - hide or show them - use style in place of visible
Albert D. Kallal
  • 42,205
  • 3
  • 34
  • 51