1

この Stack Overflow postRowClickableGridViewで提供されているクラスを使用して、カスタム コントロールを実装しようとしています。カスタム サーバー コントロールの作成を試みたのはこれが初めてで、この MSDN ウォークスルーに示されている手順に従いました。

名前空間が の Web アプリケーション プロジェクトのディレクトリにクラスRowClickableGridViewがあり、コンパイルされます。App\_CodeMyWebApplication.App\_Code

私の問題は.aspx、コントロールを使用しようとしているページがタグ プレフィックスを認識しないことです。cc1:GridViewRowClickableこのページには、タグ間のサポートされていない要素に関する多数の警告もあります。MSDN ウォークスルーによると、すべてが整っていると思いました。

コードスニペット

<%@ Page Title="MyPage" Language="C#" MasterPageFile="~/MyMaster.master" AutoEventWireup="true" Inherits="MyPage" Codebehind="MyPage.aspx.cs" %>
<%@ Register TagPrefix="cc1" TagName="RowClickableGridView" Namespace="MyWebApplication.App_Code" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>" SelectCommand="MySpName" SelectCommandType="StoredProcedure">
    </asp:SqlDataSource>
    <cc1:RowClickableGridView ID="GVW_test" runat="server" DataSourceID="SqlDataSource1">
        <HeaderStyle CssClass="ListTop" />
        <RowStyle CssClass="RowHighlight" />
        <Columns>
            <asp:BoundField HeaderText="ID" DataField="Atr_ID" SortExpression="Atr_ID" />
            <asp:BoundField HeaderText="Name" DataField="Atr_Name" SortExpression="Atr_Name" />
        </Columns>
        <EmptyDataTemplate>
            No Data
        </EmptyDataTemplate>
   </cc1:RowClickableGridView>
</asp:Content>

私が間違っていることや、次に何を試すべきかについての提案はありますか?

4

2 に答える 2

1

ようやく動作するようになりました。しかし、私は別のアプローチを取りました。

  1. 新しいASP.NETサーバー制御プロジェクトを作成します
  2. クラスをデフォルトのcsファイルにコピーし、名前空間の名前を変更します。
  3. 名前空間宣言の上の行にデフォルトのTagPrefixを追加します。
    [assembly: TagPrefix("mynamespace", "mycustomtag")]
  4. コピーされたクラスの上の行にToolBoxDataを追加します。
    [ToolboxData("<{0}:GridViewRowClickable runat=server></{0}:GridViewRowClickable>")]
  5. プロジェクトをdllにビルドする
  6. dllをWebアプリケーションのbinディレクトリにコピーします
  7. Webアプリケーションプロジェクトの参照dll
  8. dllから新しいツールボックスアイテムを作成することを追加して、ツールボックスにコントロールを追加します
  9. コントロールをツールボックスからaspxページにドラッグアンドドロップします

これにより、aspxページの上部に適切なRegisterディレクティブが追加され、受け取ったすべての警告が修正されました。この場合もオートコンプリートが機能します。

以下はコードです。

<%@ Page Title="" Language="C#" MasterPageFile="~/MyMaster.master" AutoEventWireup="true" Inherits="MyPage" Codebehind="MyPage.aspx.cs" %>
<%@ Register Assembly="GridViewRowClickable" Namespace="CustomServerControls" TagPrefix="MyTag" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:SqlDataSource ID="Sql_MyTable" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
        SelectCommand="spTbl_Select" SelectCommandType="StoredProcedure">
    </asp:SqlDataSource>
    <egcc:GridViewRowClickable ID="GridViewRowClickable_test" runat="server" 
        DataSourceID="Sql_MyTable" DataKeyNames="tbl_id"
        AllowSorting="True" AutoGenerateColumns="False" GridLines="None" PageSize="25" Width="100%"
        EnableRowClickSelection="true" RowClickCommand="Select" OnSelectedIndexChanged="GridViewRowClickable_test_OnSelectedIndexChanged">
        <Columns>
            <asp:BoundField HeaderText="ID" DataField="tbl_id" SortExpression="tbl_id" />
            <asp:BoundField HeaderText="Name" DataField="tbl_name" SortExpression="tbl_name" />
        </Columns>
        <EmptyDataTemplate>
            No Data.
        </EmptyDataTemplate>
    </egcc:GridViewRowClickable>
</asp:Content>
于 2009-12-04T17:58:51.103 に答える