Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
245
WebDataGrid and first row selection (ServerSide)
posted

Hello, I have a problem with webdatagrid and the server side selection of the first row.

The Grid is used only for details selection and after loaded and show datain each rows, I need to select the first row and load the relative details in a separate Ajax Panel.

During the normal use, selecting a different row, the Ajax Panel content is correctly updated.

My problem happen if I select the first row (server side) in the following way:

SelectedRowCollection selectedRows = Grid.Behaviors.Selection.SelectedRows;

selectedRows.Add (Grid.Rows [0]);

selecting other rows everything seems work good (Rows > zero), but if I go back to the first Row (Row [0]), it seems that I am losing alignment, and Ajax Panel show old data.

If I choose other rows again, everything seems good.

If, on the other hand, I don't select the first Row (by server side code) and click each rows, the selection Grid works correctly, updating the Ajax Panel, even when I select Row [0].

This is my Grid:

<ig:WebDataGrid ID="Grid" runat="server" AutoGenerateColumns="False"
                        EnableDataViewState="True" EnableRelativeLayout="True" BorderWidth="1px"
                        Height="130px" Width="720px" DataKeyFields="Indice"
                        BorderStyle="Solid" BackColor="White" EnableAjax="False"
                        EnableAjaxViewState="False" onrowselectionchanged="Grid_ActiveRowChange">
                            <Columns>
                                <ig:BoundDataField DataFieldName="KDE02" DataType="System.Int32" Hidden="True" Key="KDE02" Width="10px">
                                    <Header Text="KDE02" />
                                </ig:BoundDataField>
                                <ig:BoundDataField DataFieldName="A01" DataType="System.String" HtmlEncode="False" Key="A01" Width="100px">
                                    <Header Text="A01" />
                                </ig:BoundDataField>
                                <ig:BoundDataField DataFieldName="A03" DataType="System.Int32" HtmlEncode="False" Key="A03" Width="40px">
                                    <Header Text="A03" />
                                </ig:BoundDataField>
                                <ig:BoundDataField DataFieldName="WXDD" DataType="System.String" HtmlEncode="False" Key="WXDD" Width="140px">
                                    <Header Text="WXDD" />
                                </ig:BoundDataField>
                                <ig:BoundDataField DataFieldName="A50Z" DataType="System.Decimal" Key="A50Z" Width="160px">
                                    <Header Text="A50Z" />
                                </ig:BoundDataField>
                                <ig:BoundDataField DataFieldName="X80A" DataType="System.String" Key="X80A" Width="80px">
                                    <Header Text="X80A" />
                                </ig:BoundDataField>
                                <ig:BoundDataField DataFieldName="X80E" DataType="System.String" Key="X80E" HtmlEncode="False" Width="50px" CssClass="igg_CheckBoxAlignCentrer">
                                    <Header Text="X80E" />
                                </ig:BoundDataField>
                                <ig:BoundDataField DataFieldName="Indice" DataType="System.String" Hidden="true" Key="Indice" Width="10px">
                                    <Header Text="Indice" />
                                </ig:BoundDataField>
                            </Columns>
                            <Behaviors>
                                <ig:EditingCore AutoCRUD="False" BatchUpdating="True">
                                </ig:EditingCore>
                                     <ig:Activation></ig:Activation>
                                <ig:Selection CellClickAction="Row" RowSelectType="Single">
                                    <AutoPostBackFlags RowSelectionChanged="True" />
                                </ig:Selection>
                                <ig:RowSelectors>
                                </ig:RowSelectors>
                            </Behaviors>
                        </ig:WebDataGrid>

For me it is essential to load the details of the first GridRow and populate the relative Ajax Panel.

I can also loading data by forcing the index "0" from code, but I need that the Grid show the first row selected, but does not misalign the selections of other rows

PS:   Infragistics4 20.2, Version=20.2.20202.1

some advice?

Thank you

Parents
  • 1560
    Verified Answer
    Offline posted
    Hello,

    Thank you for the provided code snippet.

    I have been looking into the described behavior and prepared a small sample with two UpdatePanels trying to reproduce it.
    In the first UpdatePanel I added a WebDataGrid and a button that would select the first row on the server-side. In the second panel, I added a TextBox that would display the DataKey value of the selected row.

    I was able to reproduce the described behavior, however, after an investigation, I could say that the OnRowSelectionChanged event will not fire as the SelectedRows collection is being changed programmatically. The event is fired only through a UI interaction. Having this in mind the code responsible for updating the required controls in the second panel should be called at the time you change the SelectedRows property.

    For the purposes of the example, I defined a method that would update the TextBox Text property with a given as argument string. This method should be called in the OnRowSelectionChanged event handler and each time after the SelectedRows collection is modified:
           protected void WebDataGrid1_RowSelectionChanged(object sender, Infragistics.Web.UI.GridControls.SelectedRowEventArgs e)
            {
                this.updateDetailsPanel(e.CurrentSelectedRows[0].DataKey[0].ToString());
            }
            protected void Button1_Click(object sender, EventArgs e)
            {
                SelectedRowCollection selectedRows = this.WebDataGrid1.Behaviors.Selection.SelectedRows;
                selectedRows.Add(this.WebDataGrid1.Rows[0]);           
                this.updateDetailsPanel(this.WebDataGrid1.Rows[0].DataKey[0].ToString());
            }
            private void updateDetailsPanel(string data)
            {
                this.TextBox1.Text = data;
            }

    I have attached a sample application, that uses this approach. Please test it on your side and let me know if I may be of any further assistance.

    Sincerely,
    Teodosia Hristodorova
    Associate Software Developer
Reply Children