Repeater里的ASP.NET DataGrid,如何改写为长尾?

2026-03-30 12:091阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计514个文字,预计阅读时间需要3分钟。

Repeater里的ASP.NET DataGrid,如何改写为长尾?

我有两个表:CommunityID_PersonID 和 People 表,其中包含:FirstName LastName。我想为每个社区显示不同的 DataGrid,每个数据网格只包含属于该社区的员工。我想这样实现而不使用一个单表。

我有一个有两列的表:

CommunityID PersonID

还有一个“People”表,其中包括:

FirstName LastName

我想为每个社区显示不同的DataGrid,每个数据网格只包含属于该社区的人员.我想这样做而不使用4个单独的SqlDataSources.

一个转发器看起来是一个好方法,在ItemTemplate中有一个DataGrid,但我似乎无法做出正确或反复的方法来使用每个重复的不同值.

如果有人对更好的方法有任何建议,我会非常感激,因为这是我第一次进入ASP.NET世界

谢谢,

麦克风

我个人不会使用DataGrid控件,因为它会限制您对输出的控制,并且它们已被更新的 GridView&更换. ListView控件(虽然DataGrid是 not obsolete所以如果你愿意,可以随意使用它).您可能需要考虑使用替代方案,但不要求您这样做.

要做你想要的,你会得到如下标记:

<asp:Repeater runat="server" ID="myRepeater" onitemdatabound="Repeater_ItemDataBound"> <ItemTemplate> <asp:DataGrid runat="server" ID="myDataGrid"> </asp:DataGrid> </ItemTemplate> </asp:Repeater>

然后,您将使用以下代码隐藏连接标记:

protected void Page_Load(object sender, EventArgs e) { myRepeater.DataSource = new Object[0]; myRepeater.DataBind(); } protected void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs e) { DataGrid dg = (DataGrid)e.Item.FindControl("myDataGrid"); object o = e.Item.DataItem;// Cast the DataItem as whatever // your Repeater's DataSource is // ... // Do whatever you need to get the // data source for your DataGrid here // ... dg.DataSource = DataGridSourceObjectHere; dg.DataBind(); }

关键是Repeater的ItemDataBound事件,这是每次创建转发器行时调用的方法.这是数据绑定DataGrid源的地方.您可以使用RepeaterItemEventArgs参数在此方法中放置所需的任何逻辑,以访问绑定到Repeater的数据项.

Repeater里的ASP.NET DataGrid,如何改写为长尾?

本文共计514个文字,预计阅读时间需要3分钟。

Repeater里的ASP.NET DataGrid,如何改写为长尾?

我有两个表:CommunityID_PersonID 和 People 表,其中包含:FirstName LastName。我想为每个社区显示不同的 DataGrid,每个数据网格只包含属于该社区的员工。我想这样实现而不使用一个单表。

我有一个有两列的表:

CommunityID PersonID

还有一个“People”表,其中包括:

FirstName LastName

我想为每个社区显示不同的DataGrid,每个数据网格只包含属于该社区的人员.我想这样做而不使用4个单独的SqlDataSources.

一个转发器看起来是一个好方法,在ItemTemplate中有一个DataGrid,但我似乎无法做出正确或反复的方法来使用每个重复的不同值.

如果有人对更好的方法有任何建议,我会非常感激,因为这是我第一次进入ASP.NET世界

谢谢,

麦克风

我个人不会使用DataGrid控件,因为它会限制您对输出的控制,并且它们已被更新的 GridView&更换. ListView控件(虽然DataGrid是 not obsolete所以如果你愿意,可以随意使用它).您可能需要考虑使用替代方案,但不要求您这样做.

要做你想要的,你会得到如下标记:

<asp:Repeater runat="server" ID="myRepeater" onitemdatabound="Repeater_ItemDataBound"> <ItemTemplate> <asp:DataGrid runat="server" ID="myDataGrid"> </asp:DataGrid> </ItemTemplate> </asp:Repeater>

然后,您将使用以下代码隐藏连接标记:

protected void Page_Load(object sender, EventArgs e) { myRepeater.DataSource = new Object[0]; myRepeater.DataBind(); } protected void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs e) { DataGrid dg = (DataGrid)e.Item.FindControl("myDataGrid"); object o = e.Item.DataItem;// Cast the DataItem as whatever // your Repeater's DataSource is // ... // Do whatever you need to get the // data source for your DataGrid here // ... dg.DataSource = DataGridSourceObjectHere; dg.DataBind(); }

关键是Repeater的ItemDataBound事件,这是每次创建转发器行时调用的方法.这是数据绑定DataGrid源的地方.您可以使用RepeaterItemEventArgs参数在此方法中放置所需的任何逻辑,以访问绑定到Repeater的数据项.

Repeater里的ASP.NET DataGrid,如何改写为长尾?