本文介绍了如何使网格可选的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好。我有GridView,我想让行可选。但是我有错误EnableEventValidation =true。如何使用RegisterForEventValidation解决这个问题?
C#Net.Framework 2.0
Hi. I Have GridView and I want to make the row selectable . But I have error "EnableEventValidation="true" . How to solve this problem using RegisterForEventValidation ?
C# Net.Framework 2.0
// Button opens grid
public void FindAdr_click(object sender, EventArgs e)
{
adres_data.SelectParameters.Remove(adres_data.SelectParameters["ul"]);
adres_data.SelectParameters.Add("ul", adr_name.Text.ToString());
adres_data.SelectParameters["ul"].DefaultValue = adr_name.Text.ToString();
}
// RowDataBound
protected void adrTabl_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton _singleClickButton = (LinkButton)e.Row.Cells[0].Controls[0];
string _jsSingle = ClientScript.GetPostBackClientHyperlink(_singleClickButton, "Select$" + e.Row.RowIndex);
e.Row.Style["cursor"] = "hand";
e.Row.Attributes["onclick"] = _jsSingle;
e.Row.Attributes["onmouseover"] = "this.style.cursor='pointer';this.style.textDecoration='underline';";
e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
}
}
}
// Select row
protected void adrTabl_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow selectedRow = adrTabl.SelectedRow;
adres.Text = selectedRow.Cells[1].Text + ",," + selectedRow.Cells[2].Text;
adresF.Text = selectedRow.Cells[1].Text + ",," + selectedRow.Cells[2].Text;
}
推荐答案
if (!IsPostBack)
{
//Your code for Bind data
}
这篇关于如何使网格可选的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!