如何限制一列不应该与转发器中的其他行重复 [英] how to restrict one column should not repeat with other row in repeater

查看:55
本文介绍了如何限制一列不应该与转发器中的其他行重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何限制一列不应该与转发器中的其他行重复



 | --------- | --------- | ---------- | ---------- | 
|数据|数据|数据|数据|
| | | ---------- | |
| | |数据| |
| | | ---------- | |
| | |数据| |
| --------- | --------- | ---------- | ---------- |
|数据|数据|数据|数据|
| | | ---------- | |
| | |数据| |
| | | ---------- | |
| | |数据| |
| --------- | --------- | ---------- | ---------- |
|数据|数据|数据|数据|
| | | ---------- | |
| | |数据| |
| | | ---------- | |
| | |数据| |
| | | ---------- | |
| | |数据| |
| | | ---------- | |
| | |数据| |
| --------- | --------- | ---------- | ---------- |



 <   ItemTemplate  >  
< td align = center >
< < span class =code-leadattribute> asp:Label ID = lblGrade runat = server 文本 =' <% #Eval( 成绩) %>' > < / asp:标签 >
< / td >
< td align = center >
<% #Eval( Grade_point)%>
< / td >
< td align = center >
<% #Eval( CREDITS_POINT)%>
< / td >
< td align = center >
< asp:Label ID = lblRptrCredit runat = server Text =' <% #Eval( < span class =code-string> CG)%>' > < / asp:标签 >
< / td >

< td rowspan = 7 >
NA
< / td >
< < span class =code-leadattribute> / tr < span class =code-keyword>>
< / ItemTemplate >

解决方案

我建​​议您在gridview中执行此操作如下:



< asp:GridView ID =   GridView6 runat =   server AutoGenerateColumns = < span class =code-string>  false 
OnPreRender = GridView6_PreRender >

< Columns>
< asp:BoundField DataField = one HeaderText = SortExpression = 代码 />
< asp:BoundField DataField = 两个 HeaderText = SortExpression = 名称 />
< asp:BoundField DataField = three HeaderText = SortExpression = date1
/>
< asp:BoundField DataField = four HeaderText = SortExpression = 离开 />
< asp:BoundField DataField = five HeaderText = SortExpression = ltype />
< / >
< / asp:GridView >





在预渲染事件中调用MergeRows函数:



  protected   void  GridView6_PreRender(对象发​​件人,EventArgs e)
{
MergeRows(GridView6);
}





以下是功能:



  public   static   void  MergeRows(GridView gridView)
{
for int rowIndex = gridView.Rows.Count - 2 ; rowIndex > = 0 ; rowIndex--)
{
GridViewRow row = gridView.Rows [rowIndex];
GridViewRow previousRow = gridView.Rows [rowIndex + 1 ];

for int i = 0 ; i < row.Cells.Count - 2 ; i ++)
{
if (row.Cells [i] .Text == previousRow.Cells [i] .Text)
{
row.Cells [i] .RowSpan = previousRow.Cells [i] .RowSpan < 2 2
previousRow.Cells [i] .RowSpan + 1 ;
previousRow.Cells [i] .Visible = false ;
}
}
}
}





希望这会有所帮助。!


how to restrict one column should not repeat with other row in repeater

|---------|---------|----------|----------|
| data    | data    |data      | data     |
|         |         |----------|          |
|         |         |data      |          |
|         |         |----------|          |
|         |         |data      |          |
|---------|---------|----------|----------|
| data    | data    |data      | data     |
|         |         |----------|          |
|         |         |data      |          |
|         |         |----------|          |
|         |         |data      |          |
|---------|---------|----------|----------|
| data    | data    |data      | data     |
|         |         |----------|          |
|         |         |data      |          |
|         |         |----------|          |
|         |         |data      |          |
|         |         |----------|          |
|         |         |data      |          |
|         |         |----------|          |
|         |         |data      |          |
|---------|---------|----------|----------|


 <ItemTemplate>
    <td align="center">
                                                                                    <asp:Label ID="lblGrade" runat="server" Text='<%#Eval("Grades")%>'></asp:Label>
                                                                                </td>
 <td align="center">
<%#Eval("Grade_point")%>
                                                                                </td>
 <td align="center">
                                                                                    <%#Eval("CREDITS_POINT")%>
</td>
<td align="center">
                                                                                    <asp:Label ID="lblRptrCredit" runat="server" Text='<%#Eval("CG")%>'></asp:Label>
 </td>

<td rowspan="7" >
 NA
</td>
</tr>
 </ItemTemplate>

解决方案

I suggest you to perform this in gridview as follows:

<asp:GridView ID="GridView6" runat="server" AutoGenerateColumns="false"
                            OnPreRender="GridView6_PreRender" >
                            
                            <Columns>
                                <asp:BoundField DataField="one" HeaderText="" SortExpression="code" />
                                <asp:BoundField DataField="two" HeaderText="" SortExpression="name" />
                                <asp:BoundField DataField="three" HeaderText="" SortExpression="date1"
                                     />
                                <asp:BoundField DataField="four" HeaderText="" SortExpression="leave" />
                                <asp:BoundField DataField="five" HeaderText="" SortExpression="ltype" />
                            </Columns>
                        </asp:GridView> 



On prerender event call the MergeRows function:

protected void GridView6_PreRender(object sender, EventArgs e)
        {
            MergeRows(GridView6);
        }



And below is the function:

public static void MergeRows(GridView gridView)
        {
            for (int rowIndex = gridView.Rows.Count - 2; rowIndex >= 0; rowIndex--)
            {
                GridViewRow row = gridView.Rows[rowIndex];
                GridViewRow previousRow = gridView.Rows[rowIndex + 1];

                for (int i = 0; i < row.Cells.Count - 2; i++)
                {
                    if (row.Cells[i].Text == previousRow.Cells[i].Text)
                    {
                        row.Cells[i].RowSpan = previousRow.Cells[i].RowSpan < 2 ? 2 :
                                               previousRow.Cells[i].RowSpan + 1;
                        previousRow.Cells[i].Visible = false;
                    }
                }
            }
        }



Hope this helps.!


这篇关于如何限制一列不应该与转发器中的其他行重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆