C# 从asp.net c中的数据库列获取超链接列表

C# 从asp.net c中的数据库列获取超链接列表,c#,asp.net,database,hyperlink,label,C#,Asp.net,Database,Hyperlink,Label,我有一个项目网站报价网站 我有一个页面,所有的报价都显示在这里。下面是截图。 我使用存储过程来显示这个结果 现在我的主要问题是: 如您所见,有一个用于标记的字段 标签:生活、有趣、领导力、灵感、友谊 但该值来自数据库列类别。我用一个标签来显示所有类别 但我想将它划分为单独的类别,并将用户重定向到他单击的特定类别上 有没有办法把这个标签分成多个超链接 我的存储过程以防任何人需要 ALTER Proc text_quotes ( @cat varchar(50) ) as b

我有一个项目网站报价网站 我有一个页面,所有的报价都显示在这里。下面是截图。 我使用存储过程来显示这个结果

现在我的主要问题是:

如您所见,有一个用于标记的字段 标签:生活、有趣、领导力、灵感、友谊

但该值来自数据库列类别。我用一个标签来显示所有类别

但我想将它划分为单独的类别,并将用户重定向到他单击的特定类别上

有没有办法把这个标签分成多个超链接

我的存储过程以防任何人需要

ALTER Proc text_quotes
    (
    @cat varchar(50)
    )
as
begin
    select p.id,p.title,p.description,p.category,p.metadescp,p.metatitle,p.tags,f.img
    from tbl_upload_image p
    inner join tbl_author f
    on p.description = f.name
    where p.category like '%' + @cat + '%'
    order by p.upload_date desc
end
来自数据库的示例条目:

身份证号码:12

报价:dghjn

类别:生活、有趣、领导力、励志、友谊

作者:吉姆·凯瑞

更新:

我使用了以下代码:

foreach (DataListItem item in DataList4.Items)
        {
            Repeater RepeaterQ = ((Repeater)(item.FindControl("Repeater1")));
            string categories = ((Label)(item.FindControl("categoryLabel"))).ToString();

            // Label lblCategory = ((Label)(DataList4.FindControl("categoryLabel")));
            string[] arr1 = categories.Split(',');

            RepeaterQ.DataSource = arr1;

            RepeaterQ.DataBind();
        }

但我在repeater中得到System.Web.UI.WebControls.Label作为文本。有什么帮助吗?

如果您的类别数据包含在类似类别的变量中,那么我假设您将其分配到标签lblCategory作为示例

lblCategory.Text = categories;
如果你是这样做的,那么你可以试试这个

lblCategory.Text = String.Join("", 
     categories.Split(new char[]{','}, StringSplitOptions.RemoveEmptyEntries) //Split Category csv to array of categories
    .Select(x=>String.Format("<a href='page.aspx?cat={0}'>{0}</a>"), x)) // return all categories with formatted anchor tag
    .ToArray() // Convert To Array
); //Join with empty string and assign to label text property

在我从数据库中选择这些类别后,我必须对其进行划分,因为我只使用单列类别来存储所有选定的类别。如果要在asp.net cYes中使用它,它将在asp.net 3.5中工作,则需要添加Syatem.Linq的引用。然后选择x=>String.Format,x是Linq扩展方法,这里x表示每个类别为String。请查看我在que中发布的更新。如果你能帮忙的话。Thanksi使用了repeater来绑定您所说的类别
foreach (DataListItem item in DataList4.Items)
{
    Repeater RepeaterQ = ((Repeater)(item.FindControl("Repeater1")));
    //string categories = ((Label)(item.FindControl("categoryLabel"))).ToString();
    string categories = ((Label)(item.FindControl("categoryLabel"))).Text;
    string[] arr1 = categories.Split(',');
    RepeaterQ.DataSource = arr1;
    RepeaterQ.DataBind();
}