C1 Gridview Update problem?

Posted by: thermoplan_mn on 10 September 2017, 11:46 am EST

  • Posted 10 September 2017, 11:46 am EST

    Hello,

    I have an C1Gridview, which I want to update from server side, but I don´t know how. So may be someone knows.

    To be more detailed:

    In the program I have a MS Chart control, which displays a Graph. The Graph does have a MouseMove Event, which tells what values are at the specifed point. So all I want is to have the Grid display the values, which I get from the MouseMove. But my GridView doesn´t update until I reload the page.

    The Grid has it´s own Updatepanel, which updates every time the mouse moves. So here is my code for initializing the GridView:

    Grid_Data = New DataTable

    Grid_Data.Clear()
    Grid_Data.Columns.Clear()
    Grid_Data.Rows.Clear()
    Grid_Data.Columns.Add("Akt")
    Grid_Data.Columns.Add("Wert")
    Grid_Data.Columns.Add("Name")

    i = 0
    For Each KonfigWert In Konfig
    Dim Einzeldaten As DataRow

    Einzeldaten = Grid_Data.NewRow()
    Einzeldaten(0) = KonfigWert.aktiv.ToString
    If MouseMove_Data Is Nothing Or MouseMove_Data.Count <= 0 Then
    Einzeldaten(1) = ""
    Else
    Einzeldaten(1) = MouseMove_Data(i).Wert
    End If

    Einzeldaten(2) = MW_Kfg(KonfigWert.Zeiger).Name
    Grid_Data.Rows.Add(Einzeldaten)
    i = i + 1
    Next

    Grid.Visible = True
    Grid_Data.AcceptChanges()
    Grid.DataSource = Grid_Data
    Grid.DataBind()


    May be some can tell me, how to update the Gridview or just on row.

    Thanks in advance.

    Ps.: Sorry for my bad english :)
  • Replied 10 September 2017, 11:46 am EST

    Could you please post your sample so that I can take a look?

    Thanks
  • Replied 10 September 2017, 11:46 am EST

    Hi,

    I believe you're referring to the MouseMove client side event. To update C1GridView from server side, there has to be a postback or an ajax callback. I think you could do a postback from the MouseMove event and pass along the values. Then retrieve these values and update C1GridView.

    Let me know if it helps.

    Regards
  • Replied 10 September 2017, 11:46 am EST

    Hi,

    Thanks for the reply.

    The problem is, I don´t know how to do a postback of the C1GridView from serverside. The MouseMove Event works perfect, but the Grid isn´t updating.
  • Replied 10 September 2017, 11:46 am EST

    Sure.

    First MouseMove Event on client side:
    <script language="Javascript">
    $('#Chart').mousemove(function (e) {
    var x = e.pageX - this.offsetLeft;
    var y = e.pageY - this.offsetTop;

    $('#<%= Txt_MouseMove.ClientId %>').val(x + ':' + y);
    __doPostBack('<%= Txt_MouseMove.ClientID %>', '');
    });
    </script>


    Next TextChanged Event:
        Protected Sub Txt_MouseMove_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles Txt_MouseMove.TextChanged
    Dim Test(2) As String

    Test = Txt_MouseMove.Text.Split(":")
    Grafik.MouseMove(Test(0), Test(1))
    'Txt_Test.Text = Grafik.GetValues(Test(0), Test(1), 0)

    UpdatePanel_Grid.Update()

    End Sub


    MouseMove Code:
         Dim MoveData(2) As String
    Dim TmpData As Kla_HelpGraph.GrafikDaten
    Dim i As Integer


    MouseMove_Data.Clear()

    For i = 0 To Konfig.Count - 1
    MoveData = GetValues(x, y, i).Split(";")
    If MoveData(0) = "" Then
    TmpData.Datum = Konfig(0).StartDatum
    TmpData.Wert = 0
    Else
    TmpData.Datum = MoveData(0)
    TmpData.Wert = MoveData(1)
    End If

    MouseMove_Data.Add(TmpData)
    Next i

    Update_Grid()


    Grid init (only first time page loads):
      Dim i As Integer
    Grid_Data = New DataTable

    Grid_Data.Clear()
    Grid_Data.Columns.Clear()
    Grid_Data.Rows.Clear()
    Grid_Data.Columns.Add("Akt")
    Grid_Data.Columns.Add("Wert")
    Grid_Data.Columns.Add("Name")
    i = 0
    For Each KonfigWert In Konfig
    Dim Einzeldaten As DataRow

    Einzeldaten = Grid_Data.NewRow()
    Einzeldaten(0) = KonfigWert.aktiv.ToString
    If MouseMove_Data Is Nothing Or MouseMove_Data.Count <= 0 Then
    Einzeldaten(1) = ""
    Else
    Einzeldaten(1) = MouseMove_Data(i).Wert
    End If

    Einzeldaten(2) = MW_Kfg(KonfigWert.Zeiger).Name
    Grid_Data.Rows.Add(Einzeldaten)
    i = i + 1
    Next

    Grid.Visible = True
    Grid_Data.AcceptChanges()
    Grid.DataSource = Grid_Data
    Grid.DataBind()


    And for Grid Update, I don´t know how to do. Since yesterday I try to use Templates for Grid initializing. Now I think my Grid updates every time I use Updatepanel.Update(), but alle Data in the Grid is deleted. I also don´t know if templates will help me.

    So here is so renewed code for Grid initializing:

    Dim xx As C1TemplateField
    Dim f As New C1GridViewUpdateBinding
    Dim i As Integer

    Grid.Columns.Clear()
    Grid.AutogenerateColumns = False
    xx = New C1TemplateField
    xx.HeaderText = "H"
    xx.HeaderTemplate = New Template("Akt", DataControlRowType.Header)
    xx.ItemTemplate = New Template("Akt", DataControlRowType.DataRow)
    'f.UpdateField = "Akt"
    'xx.UpdateBindings.Add(f)
    Grid.Columns.Add(xx)

    xx = New C1TemplateField
    xx.HeaderTemplate = New Template("Wert", DataControlRowType.Header)
    xx.ItemTemplate = New Template("Wert", DataControlRowType.DataRow)
    'f.UpdateField = "Wert"
    'xx.UpdateBindings.Add(f)
    Grid.Columns.Add(xx)

    xx = New C1TemplateField
    xx.HeaderTemplate = New Template("Name", DataControlRowType.Header)
    xx.ItemTemplate = New Template("Name", DataControlRowType.DataRow)
    'f.UpdateField = "Name"
    'xx.UpdateBindings.Add(f)
    Grid.Columns.Add(xx)

    'gd.Clear()
    Grid_Data.Clear()
    Grid_Data.Columns.Clear()
    Grid_Data.Rows.Clear()
    Grid_Data.Columns.Add("Akt")
    Grid_Data.Columns.Add("Wert")
    Grid_Data.Columns.Add("Name")
    i = 0
    For Each KonfigWert In Konfig
    Dim Einzeldaten As DataRow

    Einzeldaten = Grid_Data.NewRow()
    Einzeldaten(0) = KonfigWert.aktiv.ToString
    If MouseMove_Data Is Nothing Or MouseMove_Data.Count <= 0 Then
    Einzeldaten(1) = ""
    Else
    Einzeldaten(1) = MouseMove_Data(i).Wert
    End If

    Einzeldaten(2) = MW_Kfg(KonfigWert.Zeiger).Name
    Grid_Data.Rows.Add(Einzeldaten)
    i = i + 1
    Next

    Grid.Visible = True
    Grid_Data.AcceptChanges()
    Grid.DataSource = Grid_Data
    Grid.DataBind()
    End Sub


    Public Class Template
    Implements ITemplate

    Private _ColName As String
    Private _rowType As DataControlRowType
    Private _Count As Integer

    Public Sub New(ByVal ColName As String, ByVal RowType As DataControlRowType)
    _ColName = ColName
    _rowType = RowType
    End Sub

    Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
    Select Case _rowType
    Case DataControlRowType.Header
    Dim lc As New Literal()
    lc.Text = "<b>" + _ColName + "</b>"
    container.Controls.Clear()
    container.Controls.Add(lc)
    Exit Select
    Case DataControlRowType.DataRow
    Dim lbl As New Label
    AddHandler lbl.DataBinding, New EventHandler(AddressOf Me.lbl_DataBind)
    container.Controls.Add(lbl)
    Exit Select
    Case DataControlRowType.Footer
    Dim flc As New Literal()
    flc.Text = "<b>Total No of Articles:" + _Count + "</b>"
    container.Controls.Add(flc)
    Exit Select
    Case Else
    Exit Select
    End Select
    End Sub


    Private Sub lbl_DataBind(ByVal sender As [Object], ByVal e As EventArgs)
    Dim lbl As Label = DirectCast(sender, Label)
    Dim row As C1GridViewRow = DirectCast(lbl.NamingContainer, C1GridViewRow)
    lbl.Text = DataBinder.Eval(row.DataItem, _ColName).ToString()
    End Sub
    End Class


    If you need more, please tell me. And really thank you for your support.


    EDIT:

    After todays research I found out that my problem is, that the object of my GridView is not saved to the GridView Control on my page. Because of this, the GridView always losses all Data, when I do update my Updatepanel.

    But I also don´t know how to make the GridView on the page the child of the GridView in may Grid class.....
  • Replied 10 September 2017, 11:46 am EST

    > Now I think my Grid updates every time I use Updatepanel.Update(), but alle Data in the Grid is deleted.

    The Grid will be refreshed when you call UpdatePanel.Update(), since the grid is inside UpdatePanel.

    > But I also don´t know how to make the GridView on the page the child of the GridView in may Grid class...

    What do you mean when you say "make the GridView on the page the child of the GridView in may Grid class" ? Have you created your own class which derives from C1GridView?

    Thanks
  • Replied 10 September 2017, 11:46 am EST

    [xml][/xml]
  • Marked as Answer

    Replied 10 September 2017, 11:46 am EST

    Hello grn.developer@gmail.com,

    We did not receive your last reply. Could you please let us know whether you need further assistance in the issue.

    Thanks,
    Richa
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels