添加超链接到一个GridView [英] add hyperlink to a gridview
问题描述
我使用C#和asp.net创建一个网页
我有一个简单的SQLite数据库。
我有我在哪里显示只是简单的2图书分类一个gridview。
这两个类别
小说
技术
I am creating a webpage using C# and asp.net I have a simple sqlite database. I have a gridview where i am displaying just simple 2 Book categories. The two categories are Fiction technical
我想分配一个链接到这些类别,以便用户可以被定向到一个新的一页。
I would like to assign a link to those categories so the user can be directed to a new page.
下面是显示在GridView中的数据的快照..
在这里我想添加一个链接到小说和技术重定向到一个新的一页。
这是我的数据集和GridView。
Here is a snapshot of the data being displayed in the gridview.. where i want to add a link to Fiction and technical to redirect to a new page. This is my dataset and gridview.
DataSet dsgrid;
dsgrid = (DataSet)Cache["GridViewDataSet"];
if (dsgrid == null)
{
dsgrid = GetDataSet(); //call function
Cache["GridViewDataSet"] = dsgrid;
}
else
{
}
//bind our cache data to a datasource
GridView1.DataSource = dsgrid.Tables[0];
GridView1.DataBind();
}
catch (Exception ex)
{
this.lblError.Text = ex.Message;
}
}
private DataSet GetDataSet()
{
String connectionString = "Data Source=" + Server.MapPath(@"~\App_Data\bookDB.db");
String selectCommand = "Select * from Category";
SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter(selectCommand, connectionString);
DataSet ds = new DataSet();
dataAdapter.Fill(ds);
//GridView1.DataSource = ds;
// GridView1.DataBind();
return ds;
}
感谢您
推荐答案
这是标记code,你必须将超链接添加到GridView控件的IntemTempalte集合内,添加绑定前pression到所包含的控件的Text属性。
this is the markup code, you have to add a hyperlink to the gridview control inside the IntemTempalte collection and add a binding expression to the text property of the contained controls
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="128px">
<Columns>
<asp:TemplateField HeaderText="Code">
<ItemTemplate>
<asp:Label ID="lblCodigo" runat="server" Text='<%#Eval("columnNae")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:HyperLink ID="link" runat="server" Text='<%#Eval("columnNae") %>' NavigateUrl="http://nudierweb.somee.com"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
这篇关于添加超链接到一个GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!