日期:2014-05-18 浏览次数:20401 次
string[,] siteurl = { {"google","guge","America"}, {"baidu","baidu","China"}, {"yahoo","yahu", "America"} };
DataTable GetTable(string [,] siteurl) { DataTable dt = new DataTable(); dt.Columns.Add("WebSite", typeof(HyperLinkField)); dt.Columns.Add("Description", typeof(string)); dt.Columns.Add("Country", typeof(string)); HyperLinkField hlf = new HyperLinkField(); for (int i = 0; i < siteurl .GetLength(0) ; i++) { int j = 0; DataRow row = dt.NewRow(); hlf.DataNavigateUrlFormatString = "www." + siteurl[i, j++] + ".com"; row["WebSite"] = hlf; row["Description"] = siteurl[i, j++]; row["Country"] = siteurl[i, j]; dt.Rows.Add(row); } return dt; }
protected void GridView1_DataBound(object sender, EventArgs e) { foreach (GridViewRow gr in GridView1.Rows) { HyperLink hlshowread = (HyperLink)gr.FindControl("HyperLink2"); hlshowread .NavigateUrl = "http://www.g.cn/"; } }
------解决方案--------------------
用一个超级‘笨’的方法。
定义一个SiteUrl的类,三个字段,三个属性。
public class SiteUrl { private string webSite; public string WebSite { get { return webSite; } set { webSite = value; } } private string description; public string Description { get { return description; } set { description = value; } } private string country; public string Country { get { return country; } set { country = value; } } }
------解决方案--------------------
这个是直接连接打开另一个页面。楼主改一下就行的。
<asp:TemplateField FooterText="卡有效期" HeaderText="卡有效期" SortExpression="cardvaliddate"> <ItemTemplate> <asp:linkbutton ID="Label1" runat="server" Text='<%# Bind("cardvaliddate") %>' ForeColor="#00C0C0" OnClientClick=<%# "window.