gpt4 book ai didi

c# - Asp.Net 将 SQL 数据绑定(bind)到转发器?

转载 作者:太空宇宙 更新时间:2023-11-03 22:27:37 26 4
gpt4 key购买 nike

我正在尝试将数据从 SQL 绑定(bind)到转发器控件。我已经尝试了我通常为 Gridview 所做的事情,但它不起作用。我想看一个示例,无论是使用 SQLAdapter 还是使用命令中的 ExecuteReader。谢谢!

string sql = "SELECT [WallPost], [DatePosted] FROM [WallTable] WHERE [UserId] = '"
+ Request["friend"] + "'";

string strCon =
System.Web.Configuration.WebConfigurationManager.ConnectionStrings["SocialSiteConnectionString"].ConnectionString;

SqlConnection conn = new SqlConnection(strCon);

SqlDataAdapter daUserProfile = new SqlDataAdapter(sql, conn);

dsSocialSite.UserProfileDataTable tbUserProfile =
new dsSocialSite.UserProfileDataTable();

daUserProfile.Fill(tbUserProfile);

rpWall2.DataSource = tbUserProfile; //rpWall2 = repeater control

rpWall2.DataBind();

最佳答案

举个我前几天遇到的例子

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" 
AutoEventWireup="true"CodeFile="Default.aspx.cs" Inherits="Default2"
Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<div id="Questions" align="center" style="background-color: #C0C0C0">
<asp:Repeater ID="QuestionsRepeater" runat="server"
DataSourceID="SqlDataSourceQuestions">
<ItemTemplate>
<div align="left" style="text-indent: 15px">
<asp:Label ID="Label1"
runat="server" Text= '<%# Eval("QCategory") %>'
Font-Bold="True" Font-Size="Medium"></asp:Label>
</div>

<br />
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
DataSourceID="SqlDataSourceRatings" DataTextField="RatingsCategory"
DataValueField="RatingsCategory" RepeatDirection="Horizontal" >
</asp:RadioButtonList>

</ItemTemplate>
</asp:Repeater>

<asp:SqlDataSource ID="SqlDataSourceQuestions" runat="server"
ConnectionString="<%$ ConnectionStrings:sandboxConnectionString %>"
SelectCommand="SELECT [QCategory] FROM [QuestionsCategory]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSourceRatings" runat="server"
ConnectionString="<%$ ConnectionStrings:sandboxConnectionString %>"
SelectCommand="SELECT [RatingsCategory], [RatingsId] FROM [Ratings]">

关于c# - Asp.Net 将 SQL 数据绑定(bind)到转发器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/727766/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com