如何在ASP.NET中单击tr标签时重定向到另一个页面 [英] How to redirect on another page on clicking tr tag in ASP.NET
本文介绍了如何在ASP.NET中单击tr标签时重定向到另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在clients.aspx页面的html表中从sqldatabase获取了多条记录。现在我想在用户点击任意一行时重定向userprofile.aspx页面我应该做什么代码
我认为onclick中单引号和双引号有误我用过的事件。
我使用的是这个代码
提前致谢
我尝试过:
public partial class 客户端:System.Web.UI.Page
{
受保护 void Page_Load( object sender,EventArgs e)
{
if (!this.IsPostBack)
{
// 从数据库填充DataTable。
DataTable dt = this 跨度> .GetData();
// 构建HTML字符串。
StringBuilder html = new StringBuilder();
// 表格开始。
html.Append(< span class =code-string> < table);
foreach (DataRow row in dt.Rows)
{
html.Append( < tr style ='cursor:pointer'; onclick = 'window.location的=的' http://本地主机:52582 /音轨/ UserProfile.aspx'>中跨度>);
foreach (DataColumn column in dt.Columns)
{
html.Append( < td>);
html.Append(row [column.ColumnName]);
html.Append( < / td>);
}
html.Append( < / tr>);
}
// 表格结束。
html.Append( < / table>);
// 将HTML字符串附加到占位符。
PlaceHolder1 .Controls.Add( new Literal {Text = html.ToString()});
}
}
private DataTable GetData()
{
string constr = ConfigurationManager.ConnectionStrings [ constr]。的ConnectionString;
使用(SqlConnection con = new SqlConnection(constr))
{
使用(SqlCommand cmd = new SqlCommand( SELECT top 10 cln_cd,cln_add FROM client))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
使用(DataTable dt = new DataTable())
{
sda.Fill(dt);
return dt;
}
}
}
}
}
}
解决方案
Quote:我认为在我使用的onclick事件中单引号和双引号有误。
您认为正确! :)
尝试:
html.Append( < tr style = \cursor:pointer; \onclick = \window.location.href ='http:// localhost:52582 /轨道/ UserProfile.aspx'; \ > 中跨度>);
I have multiple records which I fetched from sqldatabase in html table on clients.aspx page. Now I want to redirect on userprofile.aspx page when user click on any row What code should I do
I think there is mistake in single quote and double quote in onclick event which I used.
I am using this code
Thanks in advance
What I have tried:
public partial class Clients : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
//Populating a DataTable from database.
DataTable dt = this.GetData();
//Building an HTML string.
StringBuilder html = new StringBuilder();
//Table start.
html.Append("<table");
foreach (DataRow row in dt.Rows)
{
html.Append("<tr style='cursor:pointer'; onclick='window.location='http://localhost:52582/track/UserProfile.aspx'>");
foreach (DataColumn column in dt.Columns)
{
html.Append("<td>");
html.Append(row[column.ColumnName]);
html.Append("</td>");
}
html.Append("</tr>");
}
//Table end.
html.Append("</table>");
//Append the HTML string to Placeholder.
PlaceHolder1.Controls.Add(new Literal { Text = html.ToString() });
}
}
private DataTable GetData()
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT top 10 cln_cd,cln_add FROM client"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
return dt;
}
}
}
}
}
}
解决方案
Quote:I think there is mistake in single quote and double quote in onclick event which I used.
You think correctly! :)
Try:
html.Append("<tr style=\"cursor:pointer;\" onclick=\"window.location.href='http://localhost:52582/track/UserProfile.aspx';\">");
这篇关于如何在ASP.NET中单击tr标签时重定向到另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文