Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在ASP中继器中使用if-else语句_C#_Asp.net - Fatal编程技术网

C# 在ASP中继器中使用if-else语句

C# 在ASP中继器中使用if-else语句,c#,asp.net,C#,Asp.net,我使用一个项目转发器来显示保存在数据库中的表单列表。我可以使用DataBinder很好地抓取所有表单,但是每个表单都是按部门分类的,我想为每个部门放一个标题。到目前为止,我有一个名为“Form”的对象,其中包含ID、名称、链接和部门(字符串)。我想按部门订购表格,当新部门出现时,请放置适当的标题 这就是我想让它看起来的样子: 这是标题的外观: <a name="1"><img src="images/divider_accounting.gif" alt="" height=

我使用一个项目转发器来显示保存在数据库中的表单列表。我可以使用DataBinder很好地抓取所有表单,但是每个表单都是按部门分类的,我想为每个部门放一个标题。到目前为止,我有一个名为“Form”的对象,其中包含ID、名称、链接和部门(字符串)。我想按部门订购表格,当新部门出现时,请放置适当的标题

这就是我想让它看起来的样子:

这是标题的外观:

<a name="1"><img src="images/divider_accounting.gif" alt="" height="26px" width="480px"></a>


我需要知道如何检查部门是不是与前一个相同,并添加正确的标题图像。有什么建议吗?

有两种相对简单的方法来实现这一点

  • 如果您确定传入的数据总是排序的,并且是线性的,那么您可以通过一些简单的调整来做到这一点。在itemtemplate中创建条件可见的元素,并控制行数据绑定事件中的可见性

    <asp:Repeater ID="rptItemList" runat="server" OnItemDataBound="rptItemListOnItemDataBound" OnItemCommand="rptItemListOnItemCommand">
    <ItemTemplate>
        <asp:Panel runat="server" id="departmentHeaderPanel" Visible="false">
            <a name="1"><img src="images/divider_accounting.gif" alt="" height="26px" width="480px"></a>
        </asp:Panel>  
    
        <div class="form col-sm-12"> 
            <a href="<%#DataBinder.Eval(Container.DataItem,"Link").ToString() %>"><%#DataBinder.Eval(Container.DataItem,"Name").ToString() %></a>  
    
            <asp:Panel ID="pnlAdmin" runat="server" Visible="false">
                <asp:HyperLink ID="lnkEdit" runat="server" ResourceKey="EditItem.Text" Visible="false" Enabled="false" />
                <asp:LinkButton ID="lnkDelete" runat="server" ResourceKey="DeleteItem.Text" Visible="false" Enabled="false" CommandName="Delete" />
            </asp:Panel>
        </div>
    </ItemTemplate>
    
    
    

    ///将最后一个部门定义为属性或字段。
    var lastnowndepartment=“”;
    void ItemDataBound(对象发送方,RepeaterItemEventArgs e){
    如果(e.Item.ItemType==ListItemType.Item){
    var departmentHeaderPanel=(面板)e.Item.FindControl(“departmentHeaderPanel”);
    var currentForm=(Form)e.Item.DataItem;
    if(当前表单.部门LastKnown部门)
    {
    lastKnownDepartment=currentForm.department;
    departmentHeaderPanel.Visible=真;
    }否则{
    departmentHeaderPanel.Visible=假;
    }
    }
    }    
    
  • 总psuedo代码。甚至没有检查正确的语法

    或者,为了更灵活,你可以用更好的方法处理这个问题

  • 使用linq将表单分组到部门中。然后有嵌套的中继器,在外面有一个普通的中继器,每个部门重复。然后在该部门的表单上对内部转发器进行数据绑定。您可以在行数据绑定事件中再次执行此操作

  • 有两种相对简单的方法来实现这一点

  • 如果您确定传入的数据总是排序的,并且是线性的,那么您可以通过一些简单的调整来做到这一点。在itemtemplate中创建条件可见的元素,并控制行数据绑定事件中的可见性

    <asp:Repeater ID="rptItemList" runat="server" OnItemDataBound="rptItemListOnItemDataBound" OnItemCommand="rptItemListOnItemCommand">
    <ItemTemplate>
        <asp:Panel runat="server" id="departmentHeaderPanel" Visible="false">
            <a name="1"><img src="images/divider_accounting.gif" alt="" height="26px" width="480px"></a>
        </asp:Panel>  
    
        <div class="form col-sm-12"> 
            <a href="<%#DataBinder.Eval(Container.DataItem,"Link").ToString() %>"><%#DataBinder.Eval(Container.DataItem,"Name").ToString() %></a>  
    
            <asp:Panel ID="pnlAdmin" runat="server" Visible="false">
                <asp:HyperLink ID="lnkEdit" runat="server" ResourceKey="EditItem.Text" Visible="false" Enabled="false" />
                <asp:LinkButton ID="lnkDelete" runat="server" ResourceKey="DeleteItem.Text" Visible="false" Enabled="false" CommandName="Delete" />
            </asp:Panel>
        </div>
    </ItemTemplate>
    
    
    

    ///将最后一个部门定义为属性或字段。
    var lastnowndepartment=“”;
    void ItemDataBound(对象发送方,RepeaterItemEventArgs e){
    如果(e.Item.ItemType==ListItemType.Item){
    var departmentHeaderPanel=(面板)e.Item.FindControl(“departmentHeaderPanel”);
    var currentForm=(Form)e.Item.DataItem;
    if(当前表单.部门LastKnown部门)
    {
    lastKnownDepartment=currentForm.department;
    departmentHeaderPanel.Visible=真;
    }否则{
    departmentHeaderPanel.Visible=假;
    }
    }
    }    
    
  • 总psuedo代码。甚至没有检查正确的语法

    或者,为了更灵活,你可以用更好的方法处理这个问题

  • 使用linq将表单分组到部门中。然后有嵌套的中继器,在外面有一个普通的中继器,每个部门重复。然后在该部门的表单上对内部转发器进行数据绑定。您可以在行数据绑定事件中再次执行此操作

  • 有两种相对简单的方法来实现这一点

  • 如果您确定传入的数据总是排序的,并且是线性的,那么您可以通过一些简单的调整来做到这一点。在itemtemplate中创建条件可见的元素,并控制行数据绑定事件中的可见性

    <asp:Repeater ID="rptItemList" runat="server" OnItemDataBound="rptItemListOnItemDataBound" OnItemCommand="rptItemListOnItemCommand">
    <ItemTemplate>
        <asp:Panel runat="server" id="departmentHeaderPanel" Visible="false">
            <a name="1"><img src="images/divider_accounting.gif" alt="" height="26px" width="480px"></a>
        </asp:Panel>  
    
        <div class="form col-sm-12"> 
            <a href="<%#DataBinder.Eval(Container.DataItem,"Link").ToString() %>"><%#DataBinder.Eval(Container.DataItem,"Name").ToString() %></a>  
    
            <asp:Panel ID="pnlAdmin" runat="server" Visible="false">
                <asp:HyperLink ID="lnkEdit" runat="server" ResourceKey="EditItem.Text" Visible="false" Enabled="false" />
                <asp:LinkButton ID="lnkDelete" runat="server" ResourceKey="DeleteItem.Text" Visible="false" Enabled="false" CommandName="Delete" />
            </asp:Panel>
        </div>
    </ItemTemplate>
    
    
    

    ///将最后一个部门定义为属性或字段。
    var lastnowndepartment=“”;
    void ItemDataBound(对象发送方,RepeaterItemEventArgs e){
    如果(e.Item.ItemType==ListItemType.Item){
    var departmentHeaderPanel=(面板)e.Item.FindControl(“departmentHeaderPanel”);
    var currentForm=(Form)e.Item.DataItem;
    if(当前表单.部门LastKnown部门)
    {
    lastKnownDepartment=currentForm.department;
    departmentHeaderPanel.Visible=真;
    }否则{
    departmentHeaderPanel.Visible=假;
    }
    }
    }    
    
  • 总psuedo代码。甚至没有检查正确的语法

    或者,为了更灵活,你可以用更好的方法处理这个问题

  • 使用linq将表单分组到部门中。然后有嵌套的中继器,在外面有一个普通的中继器,每个部门重复。然后在该部门的表单上对内部转发器进行数据绑定。您可以在行数据绑定事件中再次执行此操作

  • 有两种相对简单的方法来实现这一点

  • 如果您确定传入的数据总是排序的,并且是线性的,那么您可以通过一些简单的调整来做到这一点。在itemtemplate中创建条件可见的元素,并控制行数据绑定事件中的可见性

    <asp:Repeater ID="rptItemList" runat="server" OnItemDataBound="rptItemListOnItemDataBound" OnItemCommand="rptItemListOnItemCommand">
    <ItemTemplate>
        <asp:Panel runat="server" id="departmentHeaderPanel" Visible="false">
            <a name="1"><img src="images/divider_accounting.gif" alt="" height="26px" width="480px"></a>
        </asp:Panel>  
    
        <div class="form col-sm-12"> 
            <a href="<%#DataBinder.Eval(Container.DataItem,"Link").ToString() %>"><%#DataBinder.Eval(Container.DataItem,"Name").ToString() %></a>  
    
            <asp:Panel ID="pnlAdmin" runat="server" Visible="false">
                <asp:HyperLink ID="lnkEdit" runat="server" ResourceKey="EditItem.Text" Visible="false" Enabled="false" />
                <asp:LinkButton ID="lnkDelete" runat="server" ResourceKey="DeleteItem.Text" Visible="false" Enabled="false" CommandName="Delete" />
            </asp:Panel>
        </div>
    </ItemTemplate>
    
    
    

    ///将最后一个部门定义为属性或字段。
    var lastnowndepartment=“”;
    void ItemDataBound(对象发送方,RepeaterItemEventArgs e){
    如果(e.Item.ItemType==ListItemType.Item){
    var departmentHeaderPanel=(面板)e.Item.FindControl(“departmentHeaderPanel”);
    var currentForm=(Form)e.Item.DataItem;
    if(当前表单.部门LastKnown部门)
    {
    lastKnownDepartment=currentForm.department;
    departmentHeaderPanel.Visible=真;
    }否则{
    departmentHeaderPanel.Visible=假;
    }
    }
    }    
    
  • 总psuedo代码。甚至没有检查正确的语法

    或者,为了更灵活,你可以用更好的方法处理这个问题

  • 将您的fo分组