简体   繁体   English

如何转换清单 <object> 进入清单 <String[]> 就我而言?

[英]How to convert List<object> into List<String[]> in my case?

I am trying to get the field values of selected rows from devexpress AspxGridView . 我正在尝试从devexpress AspxGridView获取选定行的字段值。

I set to select only one row and not multiple row in AspxGridView. 我设置为在AspxGridView中仅选择一行,而不选择多行。 and then I want to get the field values on server side. 然后我想在服务器端获取字段值。 for testing I am trying print on button.text 为了测试我正在尝试在button.text打印

Here is my code of Aspx 这是我的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 无法将类型System.Collection.Generic.List转换为System.Collection.Generic.List

You have to cast every object to a string[] : 您必须将每个对象都转换为string[]

List<string[]> listField = ASPxGridView1.GetSelectedFieldValues(Status)
    .Select(obj => (string[]) obj)
    .ToList();

or with List(T).ConvertAll 或与List(T).ConvertAll

List<string[]> listField = ASPxGridView1.GetSelectedFieldValues(Status).ConvertAll(obj => (string[]) obj);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM