gpt4 book ai didi

c#-4.0 - 在gridview中单击鼠标选择一行

转载 作者:行者123 更新时间:2023-12-04 18:22:50 25 4
gpt4 key购买 nike

我有一个问题,我想通过鼠标单击在 gridview 中选择一行。

我的代码是这样的:

protected void PeopleGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';";
e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";

e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.gvdetails, "Select$" + e.Row.RowIndex);
}
}

它不工作。我不知道为什么?

请就此向我提出建议。

“谢谢”

最佳答案

找到关于ASP.Net select row in gridview的教程
在 GridView 标签下的 ASPX 页面中添加:

<SelectedRowStyle BackColor="Orange" />

在后面的代码中尝试以下操作:
protected override void Render(System.Web.UI.HtmlTextWriter writer) 
{
foreach (GridViewRow row in PeopleGridView.Rows) {
if (row.RowType == DataControlRowType.DataRow) {
row.Attributes["onmouseover"] =
"this.style.cursor='hand';this.style.textDecoration='underline';";
row.Attributes["onmouseout"] =
"this.style.textDecoration='none';";
// Set the last parameter to True
// to register for event validation.
row.Attributes["onclick"] =
ClientScript.GetPostBackClientHyperlink(PeopleGridView,
"Select$" + row.DataItemIndex, true);
}
}
base.Render(writer);
}

然后,您可以使用 RowCommand (类似)捕获此事件。
private void PeopleGridView_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e) 
{
if (e.CommandName == "Select") {
// Get the list of customers from the session
List<Customer> customerList =
Session["Customers"] as List<Customer>;

Debug.WriteLine(customerList[Convert.ToInt32(e.CommandArgument)].LastName);
}
}

关于c#-4.0 - 在gridview中单击鼠标选择一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10314215/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com