private void BindGridToppings()
{
}
这是asp页面的gridview
<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用作后端,两周前我才开始使用数据库进行编程。所以访问它对我来说仍然是新的。
我的DB.Where ......调用在BindGridToppings函数中格式不正确,因为complimer告诉我。或者亚音速查询不是可以进行交互的类,正如我的编译器在尝试foreach循环时告诉我的那样.items.add
关于如何绑定这个转发器的任何建议都很可爱。
谢谢,Macaire Bell
答案 0 :(得分:0)
我不太关注你在这里说的话......
我的DB.Where ......调用在BindGridToppings函数中格式不正确,因为complimer告诉我。或者亚音速查询不是可以进行交互的类,正如我的编译器在尝试foreach循环时告诉我的那样.items.add
我看不到BindGridToppings()
的电话?您是否正在尝试解决这些编译器错误(如果是这样,我们需要更多信息),或者在GridView中为Repeater获取正确的绑定技术?
如果您的问题是如何解决GridView中的Repeater绑定问题,请尝试此操作。
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
事件以绑定转发器。
答案 1 :(得分: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>
在前面
感谢您的帮助,虽然它让我得到了答案!