0
private void BindGridToppings()
    {

    }

これがaspページからのグリッドビューです

<asp:GridView ID="gridv" runat="server" AutoGenerateColumns="false" EnableModelValidation="true" OnRowDataBound="Pizzas_RowBound">
    <Columns>
        <asp:TemplateField HeaderText="Edit">
            <ItemTemplate>
                <asp:ImageButton ImageUrl="~/images/edit.png" ID="btnEditPizza" runat="server" RowIndex='<%# Container.DisplayIndex %>' onClick="Pizzas_RowEditing" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Delete">
            <ItemTemplate>
                <asp:ImageButton ImageUrl="~/images/del.png" ID="btnDeletePizza" runat="server" RowIndex='<%# Container.DisplayIndex %>' OnClick="Pizzas_RowDeleting" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField  DataField="Name" HeaderText="Name" SortExpression="Name" />
        <asp:TemplateField HeaderText="Pizza ID" >
            <ItemTemplate>
                <asp:Label ID="lblID" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "ID").ToString() %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Crust">
            <ItemTemplate>
                <asp:Label ID="lblCrust" runat="server" Text='<%#GetNameByLookUpID(DataBinder.Eval(Container.DataItem, "Crust").ToString()) %>'>            </asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Cheese">
            <ItemTemplate>
                <asp:Label ID="lblCheese" runat="server" Text='<%#GetNameByLookUpID(DataBinder.Eval(Container.DataItem ,"Cheese").ToString()) %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
        <asp:BoundField DataField="Cost" HeaderText="Cost" SortExpression="Cost" DataFormatString="{0:C}" />
        <asp:TemplateField HeaderText="Toppings">
            <ItemTemplate>
                <asp:Repeater ID="rptList" Runat="server">                            
                </asp:Repeater>
            </ItemTemplate>                
        </asp:TemplateField>
    </Columns>                
</asp:GridView>

SQLとSubSonicがバックエンドとして使用されています。私は、2週間前にデータベースを使用してプログラミングを開始しました。ですから、それにアクセスすることは私にとってまだ新しいことです。

コンパイラーが私に言ったように、私のDB.Where......呼び出しがBindGridToppings関数で正しくフォーマットされていませんでした。または、foreachループと.items.addを試したときにコンパイラが教えてくれたように、亜音速クエリは相互作用できるクラスではありません

このリピーターをバインドする方法についてのアドバイスは素敵でしょう。

ありがとう、Macaire Bell

4

2 に答える 2

0

解決策を見つけました。

    protected void Pizzas_RowBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int pizzaID = Convert.ToInt32(((Label)e.Row.FindControl("lblID")).Text);
            BulletedList bltTopping = ((BulletedList)e.Row.FindControl("bltTopping"));
            ToppingsCollection toppings = ToppingsMembers.RetriveByPizzaID(pizzaID);
            bltTopping.Items.Clear();
            foreach (Toppings topping in toppings)
            {
            bltTopping.Items.Add(new ListItem(GetNameByLookUpID(topping.ToppingID.ToString())));
        }
    }
}

            <asp:TemplateField HeaderText="Toppings">
                <ItemTemplate>                
                    <asp:BulletedList ID="bltTopping" Runat="server">                            
                    </asp:BulletedList>
                </ItemTemplate>                
            </asp:TemplateField>

前に

それが私の答えに私を導いたけれどもあなたが助けてくれてありがとう!

于 2012-05-24T13:05:58.533 に答える
0

私はあなたがここで言っていることに完全には従いません...

コンパイラーが私に言ったように、私のDB.Where......呼び出しがBindGridToppings関数で正しくフォーマットされていませんでした。または、foreachループと.items.addを試したときにコンパイラが教えてくれたように、亜音速クエリは相互作用できるクラスではありません

呼び出しが表示されませBindGridToppings()んか?これらのコンパイラエラーを解決しようとしていますか(そうであれば、もう少し情報が必要です)、またはGridView内のリピーターの適切なバインド手法を取得しようとしていますか?

問題がGridView内のリピーターのバインドを解決する方法である場合は、これを試してください。

このようなASPX:

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" onrowdatabound="GridView1_RowDataBound">
        <Columns>
            <asp:BoundField HeaderText="Foo1" DataField="Foo1" />
            <asp:TemplateField HeaderText="FooFive">
                <ItemTemplate>
                    <asp:Repeater ID="Repeater1" runat="server">
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Eval("FooFive") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:Repeater>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

コードビハインドこのように:

    protected void Page_Load(object sender, EventArgs e)
    {
        List<object> foo1Objects = new List<object>();
        foo1Objects.Add(new { Foo1 = "Hello" });
        foo1Objects.Add(new { Foo1 = "World" });

        GridView1.DataSource = foo1Objects;
        GridView1.DataBind();
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        Repeater rep1 = e.Row.FindControl("Repeater1") as Repeater;
        if (rep1 != null)
        {
            List<object> fooFiveObjects = new List<object>();
            fooFiveObjects.Add(new { FooFive = "Apple" });
            fooFiveObjects.Add(new { FooFive = "Orange" });
            fooFiveObjects.Add(new { FooFive = "Banana" });

            rep1.DataSource = fooFiveObjects;
            rep1.DataBind();
        }
    }

データ取得とGridView1のデータバインディングの動作は少し異なると思いますが、重要なのはGridView1_RowDataBoundリピーターをバインドするイベントを処理することです。

于 2012-05-22T21:22:40.917 に答える