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
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; }
Thanks for the reply.
I apologize if I could only analyze your application now, but I have thousands of other codes to modify ...
The solution would be a little too invasive in my very complex Forms (with many postbacks before showing the grid).
Given that the "SelectedRows" code is fired only from the user interface, would it be possible to get around this by running a javascript that selects row [0] only when a selected row doesn't already exist? (on aspx or serverside added)
It doesn't matter if it performs an additional postback.
Unfortunately I'm not very familiar with javascript and I don't know if this is possible.
Thanks for any advice...
Hi Theodosia, I correct myself:
Testing the solution you proposed I saw that simply inserting the Grid inside an UpdatePanel, with the same code I used before (ref. my first message) it seems that the "grid index loss" in server side code does not happen.
Is this behavior possible for you?
I try to do more in-depth tests.