Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.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
ASP.NET中继器控件的条件语句_Asp.net_Webforms - Fatal编程技术网

ASP.NET中继器控件的条件语句

ASP.NET中继器控件的条件语句,asp.net,webforms,Asp.net,Webforms,我正在使用ASP.NET(VB)中的repeater控件,使用附带的代码填充一个包含6列的表中的一些数据 我想要一段代码,通过将if/elseif/else条件附加到中继器控制器来实现以下功能: 对于带有=“40103”的记录,则在一个单元格中显示数据,将所有6列合并为一列(理想情况下使用colspan=6) 对于具有=“40105”的记录,则数据将显示在两个单元格中,合并第二列和第三列 对于所有其他记录,以实际格式显示数据 我已经通过各种网站寻找解决方案,但徒劳无功。请帮帮我 <asp:

我正在使用ASP.NET(VB)中的repeater控件,使用附带的代码填充一个包含6列的表中的一些数据

我想要一段代码,通过将if/elseif/else条件附加到中继器控制器来实现以下功能:

  • 对于带有=“40103”的记录,则在一个单元格中显示数据,将所有6列合并为一列(理想情况下使用colspan=6)

  • 对于具有=“40105”的记录,则数据将显示在两个单元格中,合并第二列和第三列

  • 对于所有其他记录,以实际格式显示数据

  • 我已经通过各种网站寻找解决方案,但徒劳无功。请帮帮我

    <asp:Repeater ID="Repeater3" runat="server">           
        <headertemplate>
            <tr style="height:25px;vertical-align:middle">
                <th class ="dg_rpt_center" align="left" width = "10%" >
                    <asp:Label ID="Label7"  runat="server" class ="lbl105" >SOLID</asp:Label></th>
                <th class ="dg_rpt_center" align="left" width = "30%">
                    <asp:Label ID="Label10"  runat="server" class ="lbl105" >SOL Name</asp:Label></th>
                <th class ="dg_rpt_center" align="right" width = "10%">
                    <asp:Label ID="Label11"  runat="server" class ="lbl105" >Target</asp:Label></th>
                <th class ="dg_rpt_center" align="right" width = "10%">
                    <asp:Label ID="Label12"  runat="server" class ="lbl105" >Achievement</asp:Label></th>      
                <th class ="dg_rpt_center" align="right" width = "10%">
                    <asp:Label ID="Label13"  runat="server" class ="lbl105" >Margin</asp:Label></th>
                <th class ="dg_rpt_center" align="right" width = "10%" >
                    <asp:Label ID="Label14"  runat="server" class ="lbl105" >Growth</asp:Label></th>
            </tr>
        </headertemplate>
        <ItemTemplate>
            <tr>
                <td align="left" width = "10%"><asp:LinkButton ID="lblsolid"  runat="server" class ="lbl9N" Text='<%#Eval("SOLID")%>' OnClick='subDtClick' CommandArgument='<%#Eval("SLNO")%>'></asp:LinkButton></td>
                <td align="left" width = "30%"><asp:Label ID="lblsolname"  runat="server" class ="lbl9N" Text='<%#Eval("NAME")%>'></asp:Label></td>
                <td align="right" width = "10%"><asp:Label ID="lbltgt"  runat="server" class ="lbl9N" Text='<%#Eval("TGT")%>'></asp:Label></td>
                <td align="right" width = "10%"><asp:Label ID="lblach"  runat="server" class ="lbl9N" Text='<%#Eval("ACH")%>'></asp:Label></td>
                <td align="right" width = "10%"><asp:Label ID="lblmrgn"  runat="server" class ="lbl9N" Text='<%#Eval("MGR")%>'></asp:Label></td>
                <td align="right" width = "10%"><asp:Label ID="lblgr"  runat="server" class ="lbl9N" Text='<%#Eval("GRW")%>'></asp:Label></td>
            </tr>
         </ItemTemplate>
    </asp:Repeater>
    
    
    固体
    溶胶名称
    目标
    成就
    边缘
    生长
    
    要实现这一点,您可以在中继器控件的
    ItemDataBound
    事件中编写逻辑。您需要获取表格单元格和标签的引用,然后设置
    colspan
    ,合并标签值,并隐藏任何额外的单元格

    ASPX页

    <asp:Repeater ID="Repeater3" runat="server" OnItemDataBound="Repeater3_ItemDataBound">
                <HeaderTemplate>
                    <tr style="height: 25px; vertical-align: middle">
                        <th class="dg_rpt_center" align="left" width="10%">
                            <asp:Label ID="Label7" runat="server" class="lbl105">SOLID</asp:Label></th>
                        <th class="dg_rpt_center" align="left" width="30%">
                            <asp:Label ID="Label10" runat="server" class="lbl105">SOL Name</asp:Label></th>
                        <th class="dg_rpt_center" align="right" width="10%">
                            <asp:Label ID="Label11" runat="server" class="lbl105">Target</asp:Label></th>
                        <th class="dg_rpt_center" align="right" width="10%">
                            <asp:Label ID="Label12" runat="server" class="lbl105">Achievement</asp:Label></th>
                        <th class="dg_rpt_center" align="right" width="10%">
                            <asp:Label ID="Label13" runat="server" class="lbl105">Margin</asp:Label></th>
                        <th class="dg_rpt_center" align="right" width="10%">
                            <asp:Label ID="Label14" runat="server" class="lbl105">Growth</asp:Label></th>
                    </tr>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr>
                        <td id="tdSOLID" runat="server" align="left" width="10%">
                            <asp:LinkButton ID="lblsolid" runat="server" class="lbl9N" Text='<%#Eval("SOLID")%>' CommandArgument='<%#Eval("SLNO")%>'></asp:LinkButton></td>
                        <td id="tdNAME" runat="server" align="left" width="30%">
                            <asp:Label ID="lblsolname" runat="server" class="lbl9N" Text='<%#Eval("NAME")%>'></asp:Label></td>
                        <td id="tdTGT" runat="server" align="right" width="10%">
                            <asp:Label ID="lbltgt" runat="server" class="lbl9N" Text='<%#Eval("TGT")%>'></asp:Label></td>
                        <td id="tdACH" runat="server" align="right" width="10%">
                            <asp:Label ID="lblach" runat="server" class="lbl9N" Text='<%#Eval("ACH")%>'></asp:Label></td>
                        <td id="tdMGR" runat="server" align="right" width="10%">
                            <asp:Label ID="lblmrgn" runat="server" class="lbl9N" Text='<%#Eval("MGR")%>'></asp:Label></td>
                        <td id="tdGRW" runat="server" align="right" width="10%">
                            <asp:Label ID="lblgr" runat="server" class="lbl9N" Text='<%#Eval("GRW")%>'></asp:Label></td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
    

    你检查过中继器了吗?是的。但是合并表格单元格需要在设计级别完成。对吗?当涉及某些业务逻辑时(即,
    if(SOLID==40103){//display change}
    )。是的,您正在影响表示/设计层,但您可能希望代码隐藏文件中包含该逻辑(从表行添加或删除类)。我可以使用itemdatabound更改字体、启用/禁用控件并使整行不可见。但是我不知道如何合并itemdatabound事件中的表单元格。您可以访问itemdatabound事件中的行。类似这样:
    中的
    和itemboundevent
    var行=(System.Web.UI.htmlControl.HtmlTableRow)e.Item.FindControl(“行”)。您可以对表格单元格执行相同的操作,添加
    colspan
    属性,并在需要时删除它们。这有意义吗?
    public void Repeater3_ItemDataBound(Object Sender, RepeaterItemEventArgs e) {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
    
                var lblsolid = (LinkButton)e.Item.FindControl("lblsolid");
    
                if (lblsolid.CommandArgument == "40103" || lblsolid.CommandArgument == "40105") {
    
                    //Labels
                    var lblsolname = (Label) e.Item.FindControl("lblsolname");
                    var lbltgt = (Label) e.Item.FindControl("lbltgt");
                    var lblach = (Label) e.Item.FindControl("lblach");
                    var lblmrgn = (Label) e.Item.FindControl("lblmrgn");
                    var lblgr = (Label) e.Item.FindControl("lblgr");
    
                    //Table Cells
                    var tdSOLID = (HtmlTableCell)e.Item.FindControl("tdSOLID");
                    var tdNAME = (HtmlTableCell)e.Item.FindControl("tdNAME");
                    var tdTGT = (HtmlTableCell)e.Item.FindControl("tdTGT");
                    var tdACH = (HtmlTableCell)e.Item.FindControl("tdACH");
                    var tdMGR = (HtmlTableCell)e.Item.FindControl("tdMGR");
                    var tdGRW = (HtmlTableCell)e.Item.FindControl("tdGRW");
    
                    if (lblsolid.CommandArgument == "40103") {
                        //merge all label values into a single string
                        var mergedCellValues = string.Format("{0} {1} {2} {3} {4}", lblsolname.Text, lbltgt.Text, lblach.Text, lblmrgn.Text, lblgr.Text);
    
                        //set the text value of the first table cell and span it 6 columns
                        tdSOLID.InnerText = mergedCellValues;
                        tdSOLID.Attributes.Add("colspan", "6");
    
                        //remove extra cells
                        tdNAME.Visible = false;
                        tdTGT.Visible = false;
                        tdACH.Visible = false;
                        tdMGR.Visible = false;
                        tdGRW.Visible = false;
                    } else if (lblsolid.CommandArgument == "40105") {
                        //same concept as above, but with different colspan and cell hiding
                    }
    
                }
    
            }
        }