1

テーブルを表示する LinqDataSource と GridView があります。タイプxmlの列は表示されません。私が考慮していない別のアプローチがあるかもしれませんが、Sql Serverクエリ出力で行うように、クリック可能なxmlを表示するためのリンクを表示してもらいたいと思います(xmlデータのスタイル表示など. )。やり方を知りたい2つのこと

  • まず、xml を文字列に変換して取得し、テーブルに表示します。たぶん最初の30文字。
  • 最後に、XML 全体を表示するためのクリック可能なリンク、サブテーブル、またはスタイル設定された文字列など、便利なものに xml をスタイルします。

したがって、次は機能し、編集リンクと削除リンクを含む素敵なテーブルを表示します。しかし、Xml フィールドがありません。Xml フィールドのサポートを追加するにはどうすればよいですか?

<form id="form1" runat="server">
<div>
    <asp:LinqDataSource ID="OrdersDataSource"
        OnContextCreating="LinqDataSource_ContextCreating"
        runat="server" ContextTypeName="MyDbDataContext"
        EnableUpdate="True" TableName="orders"
        EnableDelete="true"
        OrderBy="Status, UserId">
    </asp:LinqDataSource>
    <asp:GridView ID="OrdersGridView" DataSourceID="OrdersDataSource"
        CssClass="gridview" PageSize="30" AutoGenerateDeleteButton="true"
        AutoGenerateEditButton="true" AllowPaging="True" AllowSorting="True"
        AlternatingRowStyle-BackColor="Beige" DataKeyNames="OrderId"
        runat="server" Width="705px">
        <Columns>
        </Columns>
    </asp:GridView>
</div>
</form>

現在、Page_Load は空です。

4

1 に答える 1

0

The best approach would be to use GridView's RowDataBound event. This would look something like this:

protected void OrdersGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        var dataItem = e.Row.DataItem;
        ...
    }
}

I'm not sure what the type of dataItem is, but probably you can cast it to your order type (easiest to see in the debugger, just set a breakpoint in the RowDataBound event handler). You should be able to get your xml data from this object. When you have the xml data, you can convert it to a string and get the first 30 characters, for example.

The last thing to do is set this text in the correct cell. See the example on MSDN for this.

于 2010-07-29T09:21:00.250 に答える