2012-01-20 24 views
1

こんにちは仲間のプログラマー、ここにいくつかの問題があります。私はグリッドビュー内にユーザーコントロールを追加しています。 今私の質問はどのようにそれがデータコントロールをバインドできるように、CourseCatIDが必要なグリッドビューであるため、バインドすることができます。とにかく、ネストされたgriviewの原因を使用することはできません。別の目的のためにネストされたusercontrolのレンダリングが必要です。チュートリアル/ヘルプは喜んで感謝します。 asp.netユーザーコントロールはgridview内でバインドします

<asp:GridView ID="grdCategory" runat="server" AutoGenerateColumns="False" Width="1100px" 
       DataKeyNames="CourseCatID" Font-Names="verdana,arial,helvetica,sans-serif" Font-Size="8pt" 
       CellPadding="4" ForeColor="#333333" GridLines="None"> 
       <Columns> 
        <asp:ButtonField Text="SingleClick" CommandName="SingleClick" Visible="False" /> 
        <asp:BoundField HeaderText="CourseCatID" Visible = "false" DataField="CourseCatID" /> 
        <asp:TemplateField HeaderText="Course Category"> 
         <ItemTemplate> 
          <asp:Label ID="lblCourseCatID" runat="server" Visible="false" Text='<%# Eval("CourseCatID")%>'></asp:Label> 
           <a href="javascript:toggleDiv('mydiv<%# Eval("CourseCatID")%>')"> 
           <asp:TextBox ID="txtCourseCatName" runat="server" Text='<%# Eval("CourseCatName") %>' Font-Size="XX-Small" 
          Font-Names="Verdana" Width="300px" Visible="false"></asp:TextBox> 
           <asp:Image ID="img" onclick="javascript:Toggle(this);" runat="server" ImageUrl="~/Images/minus.gif" 
            ToolTip="Collapse" Width="7px" Height="7px" ImageAlign="AbsMiddle" /></a> 
          <asp:Label ID="lbllastname" Height="15px" runat="server" Text='<%# Eval("CourseCatName")%>'> </asp:Label> 
          <div id="mydiv<%# Eval("CourseCatID")%>"> 


           <br /> 
           &#160&#160&#160&#160&#160&#160<%--OnClick="ImageAdd_click" --%> 
           <asp:ImageButton ID="ImageAdd" Height="17px" ImageUrl="Images/addCourse.png" runat="server" 
            CommandName="cmdAdd" CommandArgument='<%# Eval("CourseCatID") %>' /> 
            <br /> 
            <br /> 

            &#160&#160&#160&#160&#160&#160 
           <asp:Panel ID="pnlCourse" runat="server"></asp:Panel> 
           <b><cuc1:CourseUserControl ID="CourseUserControl1" runat="server" /></b> 
           <br /> 
           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
           <br /> 
           <br /> 
            <br /> 

           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
          </div> 
         </ItemTemplate> 
        </asp:TemplateField> 

は、オプションのカップルを持っているあなたの時間

答えて

3

いただきありがとうございます。

<cuc1:CourseUserControl ID="CourseUserControl1" runat="server" CourseCategoryID='<%# (int)Eval("CourseCatID") %>' /> 

その後、すぐにそのプロパティが割り当てられているとして、ユーザーコントロールにデータバインド:

最も簡単な一つは、あなたがこれを行うようになるユーザーコントロール上のパブリックプロパティを公開することです。カテゴリはInt32であると仮定しています。例えば、(CourseCategoryIDがないViewStateに、民間分野での値を格納することに注意してください):

if (e.Row.RowType == DataControlType.DataRow) 
{ 
    CourseUserControl courseDetails; 
    courseDetails = (CourseUserControl)e.Row.FindItem("CourseUserControl1"); 

    // Assuming category ID is Int32 
    courseDetails.CourseCategoryID = (int)grdCategory.DataKeys[e.Row.RowIndex].Value; 
    courseDetails.DataBind(); 
} 

private int _courseCategoryID; 
public int CourseCategoryID 
{ 
    get { return _courseCategoryID; } 
    set 
    { 
     _courseCategoryID = value; 

     // TODO: code that initializes the GridView in user control. 

     this.DataBind(); 
    } 
} 

あなたの他のオプションは、同じプロパティを公開し、RowDataBoundイベントを処理し、これを行うことです

現在の行のユーザーコントロールに新しいカテゴリを割り当てた直後ではなく、手動でデータバインドを行っていることに注意してください。詳細については

、以下を参照してくださいあなたの迅速な応答を GridView.RowDataBound Event (ASP.NET 3.5) または GridView.RowDataBound Event (ASP.NET 4.0)

+0

おかげでたくさんの先生が、私はそれを手動で作成を経由して、それを自分で解決します。 Dim CourseUCを使用してCourseUserControl = LoadControl( "〜/ CourseUserControl.ascx")しかし、とにかく – Androyds

関連する問題