2

私が作業しているユーザーコントロールにかなり奇妙な問題があります。DotNetNuke モジュールで使用するいくつかのユーザー コントロールをコーディングしています。

基本的に、いくつかのコントロールを保持するページに UserControl があり、GridView が配置されている UserControl にロードしているプレースホルダーがあります。

基本的にここに私のページ構造があります

<asp:Panel runat="server" ID="pnlServiceType" Visible="false">
   <uc:ServiceType runat="server" ID="ServiceType" />
</asp:Panel>

そのユーザー コントロール内には、いくつかのフォーム要素と次の要素があります。

<asp:PlaceHolder runat="server" ID="phServices" />

そのプレースホルダーには、次のようにユーザー コントロールが追加されます。

<p class="header"><asp:Label runat="server" ID="lblServiceHeader" Font-Bold="true" /></p>

<asp:GridView runat="server" ID="gvServices" AlternatingRowStyle-BackColor="#eaeaea"  BorderStyle="None" GridLines="None"
AutoGenerateColumns="false" CellPadding="6" Width="100%" EnableViewState="false" OnRowEditing="gvServices_RowEditing">

ユーザーが DropDownList で何かを選択すると、プレースホルダーからコントロールをクリアし、選択したタイプに関係なく、一連のレコードに対して UserControl を 1 つだけ追加し直します。

        _serviceID = e.Value;

        //Clear the controls out of the placeholder
        phServices.Controls.Clear();

        //Reset the count of grids for the OnInit() method
        Session["GridCount"] = 0;

        if (e.Value != "NULL")
        {
            PopulateServicesGrid(_service.GetServicesByFormType(Convert.ToInt32(e.Value)));
        }
        else
        {
            PopulateServicesGrid(_service.GetServicesByClient(Convert.ToInt32(_client)));
        }

そして、PopulateServicesGrid メソッド:

    private void PopulateServicesGrid(List<NOAService> services)
    {
        //Creates a LINQ grouping based on the Billing Codes
        //Allows a super easy creation of grids based on the grouped billing codes
        var query = services.Select(service => service.BillingCode).Distinct();
        foreach (string code in query)
        {
            var servicesByCode = services.Where(service => service.BillingCode == code).ToList();
            ServicesGrid servicesGrid = LoadControl("~/DesktopModules/LEL Modules/NOA/ServicesGrid.ascx") as ServicesGrid;
            Label lblServiceHeader = servicesGrid.FindControl("lblServiceHeader") as Label;
            GridView gvServices = servicesGrid.FindControl("gvServices") as GridView;

            phServices.Controls.Add(servicesGrid);
            servicesGrid.ID = code;
            lblServiceHeader.Text = servicesByCode[0].FormTypeName;
            gvServices.DataSource = servicesByCode;
            gvServices.DataBind();

            Session["GridCount"] = phServices.Controls.Count;

        }
    }

そして、ServiceType UserControl の PageInit で、グリッドがポストバック全体に表示され、プレースホルダーから失われないように、ServiceGrid ユーザー コントロールを読み込んでいます。

    void NOAServiceType_Init(object sender, EventArgs e)
    {
        for (int i = 0; i < Convert.ToInt32(Session["GridCount"]); i++)
        {
            ServicesGrid servicesGrid = LoadControl("~/DesktopModules/LEL Modules/NOA/ServicesGrid.ascx") as ServicesGrid;
            phServices.Controls.Add(servicesGrid);

        }
    }

グリッドが正常に読み込まれ、すべてが正常に機能しているように見えます。しかし、何らかの理由で、私の GridView には CommandField があります。

    <asp:CommandField ShowEditButton="true" ItemStyle-HorizontalAlign="Right" EditText="Edit" UpdateText="Update" 
        EditImageUrl="~/images/LELModules/appbar.edit.rest.png" CancelImageUrl="~/images/LELModules/appbar.close.rest.png" UpdateImageUrl="~/images/LELModules/appbar.check.rest.png"
        ButtonType="Image" CausesValidation="false" />

グリッド行の [編集] コマンドをクリックしても、何も起こりません。私のグリッドは行を失いません。コントロールはまだそこにあり、すべて問題ないようです。もう一度クリックするまで、RowEditingイベントは発生しません。

なぜこれが起こっているのでしょうか?

UPDATE : SelectedIndexChanged ハンドラーがDataSource、PlaceHolder に再読み込みされたときに、UserControl に含まれるグリッド上で効果的にリセットされていることがわかりました。ただし、CommandField (編集) をクリックInitすると、プレースホルダーを保持する UserControl が起動します。

ServiceType UserControl < `Init` fires here
   -Form elements
   -Placeholder which holds
      --UserControl with GridView

このInitメソッドは UserControl の新しいインスタンスをロードして PlaceHolder に追加しますが、DataSource はnull. EnableViewState=trueデータはまだバインドされているように見えますが、を処理するPreRenderDataSourcegvServices | null

PlaceHolder に何度も動的に追加されている GridView で、このような行を編集することさえ可能ですか?

修正済みこの記事 http://www.west-wind.com/weblog/posts/2006/Feb/24/Overriding-ClientID-and-UniqueID-on-ASPNET-controlsを参照した後、問題が何であるかを知りました

IDが変更されたらどうなるのだろうと考えさせられました。コントロールはネストされています。そこで、GridView の ID、ClientID、および UniqueID を確認するためだけに時計を置いてみました。コントロールがInitハンドラーに読み込まれると、追加時にスーパー ジェネリック ID が割り当てられます。

private void PopulateServicesGrid(List<NOAService> services)
{
    //Creates a LINQ grouping based on the Billing Codes
    //Allows a super easy creation of grids based on the grouped billing codes
    var query = services.Select(service => service.BillingCode).Distinct();
    foreach (string code in query)
    {
        var servicesByCode = services.Where(service => service.BillingCode == code).ToList();
        ServicesGrid servicesGrid = LoadControl("~/DesktopModules/LEL Modules/NOA/ServicesGrid.ascx") as ServicesGrid;
        Label lblServiceHeader = servicesGrid.FindControl("lblServiceHeader") as Label;
        GridView gvServices = servicesGrid.FindControl("gvServices") as GridView;

        phServices.Controls.Add(servicesGrid);
        **servicesGrid.ID = code;**
        lblServiceHeader.Text = servicesByCode[0].FormTypeName;
        gvServices.DataSource = servicesByCode;
        gvServices.DataBind();

        Session["GridCount"] = phServices.Controls.Count;

    }
}

IDを別のものとして設定していました。そのため、グリッドで Edit RowCommand を押すと、コントロールが再度読み込まれInit、ID がカスタム セット コード (T2020、データベースから取得) から汎用 ID に戻されましたが、認識されませんでした。イベントを発生させる方法。

この問題の修正に少なくとも 12 時間を費やしたので、これが誰かの役に立てば幸いです。

4

0 に答える 0