0

I have enquiry on how to parse data of sub DataGridView to the main DataGridView. For example:

I have a column named "abnormal" on the main DataGridView and I need the data for avail column from the sub DataGridView to display on the main DataGridView "abnormal" column. I have tried the CustomCallBack but it doesn't work. The error that appeared:

"DataBinding: 'DevExpress.Web.Data.WebDataRow' does not contain a property with the name 'isAvail'`

My code : The main DataGridView id is disgrid and the sub DataGridView is detgrid

The code for main DataGridView abnormal column (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>

The code for DetGridx (asp.net)

<dx:ASPxGridView ID="DetGridx" runat="server" ClientIDMode="Static" OnCustomCallback="DetGridx_CustomCallback" OnHtmlDataCellPrepared="DetGridx_HtmlDataCellPrepared" OnDataBinding="DetGridx_DataBinding"  ClientInstanceName ="DetGridx"  KeyFieldName="ID"

The code for main 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()

The code for 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

Can anyone guide me on this? Or providing a similar example for me to refer is good enough.

Sample and expected output:

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 

Thanks in advance.

Attempt :

add ds.Tables("dat").PrimaryKey = New DataColumn() {ds.Tables("dat").Columns("isAvail")} to maingrid function

error : these columns dont currently have unique values.

Kit
  • 81
  • 9
  • Check if `adapter2` contains query results. It's possible that `GridView` doesn't have any populated datasource at the moment of binding. – Tetsuya Yamamoto Sep 14 '18 at 06:31
  • there is problem on the distinct(isAvail), but once i removed it, the data for DetGridx back to normal. and for the main gridview the error appeared is still the same. – Kit Sep 14 '18 at 06:44
  • You're not including any code for "main `GridView`", can you provide the markup and code behind for it? For the `DISTINCT` query you may look here: https://stackoverflow.com/questions/11937206/sql-query-multiple-columns-using-distinct-on-one-column-only. – Tetsuya Yamamoto Sep 14 '18 at 07:05
  • i have updated the post, the distinct is used because of the duplicate value of isAvail, noted for the link. – Kit Sep 14 '18 at 07:22

1 Answers1

0

Probably you need to slightly change Eval("isAvail") to Eval("[isAvail]") like this:

<DataItemTemplate>
    <dx:ASPxHyperLink ID="ASPxHyperLink1" runat="server" Text='<%# Eval("[isAvail]") %>' ... >
    </dx:ASPxHyperLink>
</DataItemTemplate>

Or by checking Container.DataItemPosition before using DataBinder.Eval():

<DataItemTemplate>
    <dx:ASPxHyperLink ID="ASPxHyperLink1" runat="server" Text='<%# If(Container.DataItemPosition > 0, DataBinder.Eval(Container.Items[Container.DataItemPosition], "[isAvail]"), "") %>' ... >
    </dx:ASPxHyperLink>
</DataItemTemplate>

The exception in WebDataRow occurs because Eval() (and Bind() expressions) tries to rebind the grid at runtime and DisGridx doesn't assigned with data source yet (i.e. the ASPxGridView column hierarchy built earlier than assigning DataSource property, see the explanation here).

References:

'DevExpress.Web.Data.WebDataRow' does not contain a property with the name

'DevExpress.Web.Data.WebDataRow' does not contain a property with the name 'X'

Tetsuya Yamamoto
  • 24,297
  • 8
  • 39
  • 61
  • hi, sorry for the late reply, i have tried the method you provided and this time it gave me error "A field or property with name 'isAvail' was not found in the selected data source. Possible causes of this error may be the following: an incorrect or case-insensitive spelling of the grid column name; assigning a wrong or not properly initialized data source to the grid. " I have tried to copy the code from detgrid to DisGridx but the same error appeared, sorry for the inconvenience caused. – Kit Sep 18 '18 at 01:51
  • `ds.Tables("dat").Rows(0).Item("isAvail")` only returns single item, and you still not binding `isAvail` to main grid. Because `DataSource` accepts `DataTable`, try creating new `DataColumn` with name `isAvail` to pass into main grid's `DataSource` property (reminder: edit your question to include additional codes instead pasting codes in comment). – Tetsuya Yamamoto Sep 18 '18 at 02:08
  • you mean add the new column to the main grid function but the error appeared these columns dont currently have unique values. i have updated the post. – Kit Sep 18 '18 at 03:19
  • is there anyway to bind two datasource into one without merging it? what i searched online required to merge. I created new datacolumn and it showed error because of the duplicate value as shown in the post sample and expected output. – Kit Sep 18 '18 at 06:02
  • You can't bind 2 totally different data sources into `DataSource` property without merging them, because the latter will override the former. Why you're setting primary key for `isAvail` like this while it obviously has dupe values (also with true/false condition): `ds.Tables("dat").PrimaryKey = New DataColumn() {ds.Tables("dat").Columns("isAvail")}`? – Tetsuya Yamamoto Sep 18 '18 at 06:08
  • sorry for doing this stupid mistake but i have tried so many times on this and error keep appearing, really frustrating and totally lost. – Kit Sep 18 '18 at 06:14
  • if this way doesnt work, is it possible to work on DetGridx's customcallback to display isAvail data to DisGridx? – Kit Sep 18 '18 at 07:28