Ajax实现的明细去除重复 datatable去除重复

ajax  Detail.aspx页面

 protected void Page_Load(object sender, EventArgs e)
    {
        Thread.Sleep(500);
        string Keyid = Request.QueryString["Id"].ToString();
        //string wsn = Request.QueryString["wsn"].ToString();
                                                
        DataTable dt = Hst.Paging.Paging.GetList(" ExecSN ='" + Keyid + "'  and (Status='已检验' or status='部分入库')", "V_ExecPro_Bom1").Tables[0];
        StringBuilder sb = new StringBuilder();
        sb.Append("<table style='width:83%' style='margin:2px;border:Double 3px #5D7B9D;'><tr><th>选择</th>");
        sb.Append("<th>产品编码</th><th>产品名称</th><th>产品规格</th><th>产品型号</th><th>产品材质</th>");
        sb.Append("<th>产品图纸号</th><th>产品单位</th><th>计划数量</th><th>合格数量</th><th>未入库数量</th><th>本次入库数量</th></tr>");
        string a = "";
        bool isFirst = false;
        if (dt.Rows.Count != 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string onleyone = dt.Rows[i]["R_BOMSN"].ToString() + dt.Rows[i]["PlanSN"].ToString();
                if (a != onleyone || isFirst = false)
                {
                    a = onleyone; isFirst = true;
                    sb.Append("<tr><td class='detail'><input type='checkbox' name='checkbox' value='" + dt.Rows[i]["ExecProID"].ToString() + "'/>");
                    sb.Append("<td class='detail'>" + dt.Rows[i]["BOMSN"].ToString() + " </td><td class='detail'>" + dt.Rows[i]["BomName"].ToString() + " </td><td class='detail'>" + dt.Rows[i]["Size"].ToString() + "</td><td class='detail'>" + dt.Rows[i]["Model"].ToString() + " </td> ");
                    sb.Append("<td class='detail'>" + dt.Rows[i]["Qulity"].ToString() + "</td><td class='detail'>" + dt.Rows[i]["ImageNo"].ToString() + "</td><td class='detail'>" + dt.Rows[i]["Unit"].ToString() + "</td><td class='detail'>" + dt.Rows[i]["PlanNumber"].ToString() + "</td><td class='detail'>" + dt.Rows[i]["OkNumber"].ToString() + "</td> ");
                    sb.Append("<td class='detail'><input id='TextNotIn_" + dt.Rows[i]["ExecProID"].ToString() + "' type='text' value='" + dt.Rows[i]["NotInNumber"].ToString() + "'  style='background-color: transparent; border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none; width: 50px;' readonly='readonly' /></td><td class='detail'><input id='TextRK_" + dt.Rows[i]["ExecProID"].ToString() + "' type='text' value='" + dt.Rows[i]["NotInNumber"].ToString() + "' style=' width:50px' /></td> </tr>");

                }
            }
            sb.Append(" </table>");
            Response.Write(sb.ToString());
        }
        else
        {
            return;
        }

主页面

 

   <script language="javascript" type="text/javascript" >
// <!CDATA[
function Show(id)
{
    if(document.getElementById("Details"+id).style.display=="none")
    {
     document.getElementById("Details"+id).style.display="block";
     document.getElementById("Content_"+id).innerHTML="<div style='font-weight:300; color:red; width:100%; text-align:center;'><img src='../../../images/ajax-loader.gif' /> 正在加载...</div>";
     sendRequest("Detail.aspx?Id="+id,"GetOrdersDetails");
     document.getElementById("ExpSpan"+id).src="../../../images/-.png";
    }
    else
    {
     document.getElementById("Details"+id).style.display="none";
     document.getElementById("ExpSpan"+id).src="../../../images/+.png";
    }

}
 function ReEnter(a)
    {
    openWindow("../OutStorage/SelectWarehouse.aspx",700,600)
      a.style.border="#cdcdcd 1px solid";
    }
// ]]>
    </script>

 <ItemTemplate>
                            <tr>
                                <%--<td class="ItemTemplate">
                                    <a href="javascript:openWindow('ProcMscinAdd.aspx?Id=<%#Eval("ExecSN") %>',900,700)">
                                        选择</a>
                                </td>--%>
                                <td class="ItemTemplate  " οnclick="Show('<%#Eval("ExecSN") %>')" style="cursor: hand">
                                    <img src="../../../images/+.png" alt="点击展开" id="ExpSpan<%#Eval("ExecSN") %>" />
                                    <%#Eval("CheckSN")%>
                                </td>
                                <td class="ItemTemplate  " οnclick="Show('<%#Eval("ExecSN") %>')" style="cursor: hand">
                                    <%#Eval("EmployeeName")%>
                                </td>
                                <td class="ItemTemplate  " οnclick="Show('<%#Eval("ExecSN") %>')" style="cursor: hand">
                                    <%#Eval("DepartMentName")%>
                                </td>
                                <td class="ItemTemplate  " οnclick="Show('<%#Eval("ExecSN") %>')" style="cursor: hand">
                                    <%#Eval("IsIn").ToString() == "0" ? "未出库" : "已出库"%>
                                </td>
                                <td class="ItemTemplate  " οnclick="Show('<%#Eval("ExecSN") %>')" style="cursor: hand">
                                    <%#((DateTime)Eval("CheckDate")).ToString("yyyy-MM-dd")%>
                                </td>
                            </tr>
                            <tr style="display: none" id="Details<%#Eval("ExecSN") %>">
                                <td colspan="6" style="text-align: left; padding-left: 25px; background-image: url(../images_index/L.gif);
                                    background-repeat: no-repeat; background-position: 6px top;"  id="Content_<%#Eval("ExecSN") %>">
                                </td>
                            </tr>
                        </ItemTemplate>

 

DataTable去除重复

 

 public static DataTable GetInfoS( string WhereStr)
        {
            DataTable dt = Hst.DBUtility.DbHelperSQL.Query("select * from V_ExecPro_Bom_y where " + WhereStr).Tables[0];
            DataTable dtNew = new DataTable();
            dtNew = dt.Clone();
                //Hst.DBUtility.DbHelperSQL.Query("select * from V_ExecPro_Bom_y where " + WhereStr).Tables[0];
            bool isFrist = true;
            string a = "";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string one = dt.Rows[i]["BOMSN"].ToString() + dt.Rows[i]["PlanSN"].ToString();
                if (a != one || isFrist == true)
                {
                    a = one; isFrist = false;
                    dtNew.Rows.Add(dt.Rows[i].ItemArray);                  
                }              

            }
            return dtNew;
        }

 注:for (int i = 10; j < dt.Rows.Count; i++) { row = dtn.NewRow(); row = dt.Rows[j]; dtn.ImportRow(row); }

DataTable dtn =dt.Copy();
复制表结构和数据
dt.Clone,光复制表结构

在C#中,使用`DataTable`对象去除基于特定列的重复数据是一个常见的需求。可以通过`DataTable`的`Compute`方法或者创建一个新的`DataTable`来实现。以下是基于特定列去除重复数据的一种方法: 1. 使用`DataTable`的`DefaultView`属性和`RowFilter`属性,结合`Unique`标志来过滤掉重复行。这种方法适用于单个列去重。 ```csharp DataTable dt = new DataTable(); // 假设dt已经填充了数据 // 获取特定列的列名 string columnName = "需要去重的列名"; // 使用RowFilter属性过滤重复DataTable uniqueTable = dt.DefaultView.ToTable(true, columnName); // uniqueTable 现在包含了去除重复数据DataTable ``` 2. 如果需要根据多个列进行去重,可以在`RowFilter`中指定多个列名,并在`Compute`方法中使用`Group By`语句。 ```csharp DataTable dt = new DataTable(); // 假设dt已经填充了数据 // 获取需要去重的列名数组 string[] columnNames = new string[] { "第一列名", "第二列名" }; // 构建Group By语句 string groupByStatement = string.Join(", ", columnNames); // 使用Compute方法进行分组去重 DataTable uniqueTable = dt.Compute("count(" + columnName + ")", "Group By " + groupByStatement); // uniqueTable 现在包含了去除重复数据DataTable ``` 需要注意的是,使用`Compute`方法时,需要确保分组列中至少有一列是可以进行计数操作的列(例如,存在非空或可计数的列),否则可能会导致结果不正确。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值