{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onclick"] = "location.href='MailsByOne.aspx?id=" + DataBinder.Eval(e.Row.DataItem, "id") + "'";
e.Row.Attributes["style"] = "cursor:pointer";
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
contacts connn = new contacts();
int index = GridView1.SelectedRow.RowIndex;
int ID = Convert.ToInt32(GridView1.SelectedRow.Cells[0].Text);
string message = "Row Index: " + index + "\\ContactID: " + connn.ContactID;
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + message + "');", true);
}
ASP.Net中的GridView Row点击事件我想获取id并在点击行时将其发送到另一个页面。
答案 0 :(得分:0)
试试这个:
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onclick"] =
this.Page.ClientScript.
GetPostBackClientHyperlink(this.grdList, "Select$" + e.Row.RowIndex);
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow SelectedRow = grdList.SelectedRow;
string id = SelectedRow.Cells[0].Text;
Response.Redirect("~/Mail/ShowMail.aspx?q="+id);
}
答案 1 :(得分:0)
void GridView1_SelectedIndexChanged(Object sender, EventArgs e)
{
// Get the currently selected row using the SelectedRow property.
GridViewRow row = gridview1.SelectedRow;
//now get the labels if you use Template Fields
Label _LabelId = row.FindControl("LabelId") as Label;
//if You use Bound Fields then
int ID = Convert.ToInt32(GridView1.SelectedRow.Cells[0].Text);
Response.Redirect("~/Mail/ShowMail.aspx?q="+id);
}
答案 2 :(得分:0)
您可以在gridview中使用Datakeynames属性
<asp:GridView DataKeyNames="your Id you want to send">
并在您的.cs代码中
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
string id= gvCustomReports.DataKeys[int.Parse(e.CommandArgument.ToString())].Values[0].ToString();
Response.Redirect("MailsByOne.aspx?contactid="+id);
}
答案 3 :(得分:0)
default: &default
adapter: mysql2
encoding: utf8
pool: 5
host: localhost
port: 3306
socket: /var/run/mysqld/mysqld.sock
development:
<<: *default
database: wallet_development
username: <%= ENV['WALLET_DATABASE_DEVELOPMENT_USER] %>
password: <%= ENV['WALLET_DATABASE_DEVELOPMENT_PASSWORD'] %>
祝你好运:)