Reputation: 2551
I am trying to get the field values of selected rows from devexpress AspxGridView.
I set to select only one row and not multiple row in AspxGridView. and then I want to get the field values on server side. for testing I am trying print on
button.text
Here is my code of Aspx
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource3" Width="100%" SettingsBehavior-AllowSelectByRowClick="True" OnSelectionChanged="btnSearch_Click">
<Settings HorizontalScrollBarMode="Visible" ShowFilterRow="True" ShowGroupedColumns="True" ShowTitlePanel="True" ShowGroupPanel="True" />
<SettingsBehavior AllowSelectSingleRowOnly="True" /> --it will select only one row
<SettingsSearchPanel Visible="True" />
<Columns>
<dx:GridViewDataTextColumn FieldName="Status" ReadOnly="True" VisibleIndex="0">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="WorksheetID" VisibleIndex="1">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="POTitle" VisibleIndex="2" Width="200px" ExportWidth="100" MinWidth="100">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="FromStoreName" VisibleIndex="3">
</dx:GridViewDataTextColumn>
<dx:GridViewDataDateColumn FieldName="FromDatePlaced" VisibleIndex="10">
</dx:GridViewDataDateColumn>
<dx:GridViewDataTextColumn FieldName="ToPlacementStatus" ReadOnly="True" VisibleIndex="11">
</dx:GridViewDataTextColumn>
...
...
</Columns>
</dx:ASPxGridView>
<asp:Button ID="btnSearch" CssClass="btn btn-info" runat="server" Text="Search" OnClick="btnSearch_Click" />
Screen shot of selecting one row
Server side code
public string[] Status { get; set; }
protected void btnSearch_Click(object sender, EventArgs e)
{
List<string[]> listField = new List<string[]>();
listField =(List<string[]>)ASPxGridView1.GetSelectedFieldValues(Status); \\this line showing error
\\btnSearch.Text = (string)Status.GetValue(0);
}
Error msg:
Cannot convert type System.Collection.Generic.List to System.Collection.Generic.List
Upvotes: 0
Views: 377
Reputation: 460138
You have to cast every object to a string[]
:
List<string[]> listField = ASPxGridView1.GetSelectedFieldValues(Status)
.Select(obj => (string[]) obj)
.ToList();
or with List(T).ConvertAll
List<string[]> listField = ASPxGridView1.GetSelectedFieldValues(Status).ConvertAll(obj => (string[]) obj);
Upvotes: 2