我询问如何将子 DataGridView的数据解析到主 DataGridView。例如:
我在主 DataGridView 上有一个名为“异常”的列,我需要来自子 DataGridView 的可用列的数据显示在主 DataGridView“异常”列上。我已经尝试过 CustomCallBack 但它不起作用。出现的错误:
"DataBinding: 'DevExpress.Web.Data.WebDataRow' does not contain a property with the name 'isAvail'`
我的代码:主 DataGridView id 是 disgrid,子 DataGridView 是 detgrid
主DataGridView异常列的代码(asp.net)
<dx:ASPxGridView ID="DisGridx" runat="server" OnCustomUnboundColumnData="griddata" OnHtmlDataCellPrepared="gridcell" ClientIDMode ="Static" ClientInstanceName="DisGridx" Width="100%" KeyFieldName="ID" " >
<dx:GridViewDataTextColumn FieldName="abnormal" Caption="Abnormal" >
<DataItemTemplate>
<dx:ASPxHyperLink ID="ASPxHyperLink" runat="server" Text='<%# Eval("[isAvail]") %> ' ClientSideEvents-Click='<%# "function(s,e) { DetGridx.PerformCallback(""" & Eval("ID").ToString & """); contentpop2();}" %>' >
</dx:ASPxHyperLink>
</DataItemTemplate>
</dx:GridViewDataTextColumn>
DetGridx (asp.net) 的代码
<dx:ASPxGridView ID="DetGridx" runat="server" ClientIDMode="Static" OnCustomCallback="DetGridx_CustomCallback" OnHtmlDataCellPrepared="DetGridx_HtmlDataCellPrepared" OnDataBinding="DetGridx_DataBinding" ClientInstanceName ="DetGridx" KeyFieldName="ID"
主 DataGridView (vb.net) 的代码
.....................................
Dim csvFileFolder As String = "C:\New folder\"
Dim csvFile As String = "QtimeAutomotiveByLot_New.csv"
Dim adapter2 As New OleDbDataAdapter
' specify directory path containing CSV file as data source
Dim strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + csvFileFolder + ";Extended Properties='Text;HDR=YES;FMT=Delimited';"
Dim connx As New OleDbConnection(strCon)
connx.Open()
' To display file from csv
Dim sql As New OleDbCommand("Select distinct(ID),COUNT(isAvail) as isAvail from [" + csvFile + "] where isAvail = 0 group by ID, isAvail ", connx)
adapter2.SelectCommand = sql
adapter2.Fill(ds,"csv")
connx.Close()
ds.Tables("lotlist").PrimaryKey = New DataColumn() {ds.Tables("lotlist").Columns("ID")}
ds.Tables("comd").PrimaryKey = New DataColumn() {ds.Tables("comd").Columns("ID")}
ds.Tables("monitor").PrimaryKey = New DataColumn() {ds.Tables("monitor").Columns("ID")}
ds.Tables("csv").PrimaryKey = New DataColumn() {ds.Tables("csv").Columns("ID")}
dt.Merge(ds.Tables("lotlist"))
dt.Merge(ds.Tables("comd"))
dt.Merge(ds.Tables("monitor"))
dt.Merge(ds.Tables("csv"))
Dim dv1 As DataView = dt.DefaultView
dv1.RowFilter = "[Cat] <> '' "
DisGridx.DataSource = dv1
DisGridx.DataBind()
DetGridx customcallback vb.net 的代码
Protected Sub DetGridx_CustomCallback(sender As Object, e As ASPxGridViewCustomCallbackEventArgs)
Dim sql As New OleDbCommand("Select * from [" + csvFile + "] where ID = 'L-" + e.Parameters + "' AND STEPHANDLE = (SELECT TOP 1 STEPHANDLE from [" + csvFile + "] WHERE ID = '" + e.Parameters + "')", connx)
adapter2.SelectCommand = sql
adapter2.Fill(dt1)
connx.Close()
DetGridx.DataSource = dt1
DetGridx.DataBind()
End Sub
有人可以指导我吗?或者提供一个类似的例子供我参考就足够了。
样本和预期输出:
Main Gridview Sub Grid View
Abnormal ID ID Note isAvail
0/3 kiv-02 kiv-02 1-2 0
kiv-02 1-3 0
kiv-02 1-4 0
提前致谢。
试图 :
添加 ds.Tables("dat").PrimaryKey = New DataColumn() {ds.Tables("dat").Columns("isAvail")}
到主网格功能
错误:这些列当前没有唯一值。