我希望在单击 gridview 行时能够调用一个函数。怎么做
这是我处理 gridview 行点击的地方
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// somthing like
// e.Row.Attributes["onclick"] = go to Myfunction;
//OR
// e.Row.Attributes.Add("onclick", Myfunction);
}
}
这是我要调用的函数
protected void Myfunction(object sender, EventArgs e)
{
int id = 0;
foreach (GridViewRow myrow in GridView1.Rows)
{
RadioButton btn= (RadioButton)row.FindControl("RadioButton1");
if (btn.Checked)
{
id = Convert.ToInt32(GridView1.Rows[row.RowIndex].Cells[1].Text);
}
}
最佳答案
protected void rdb_select_CheckedChanged(object sender, EventArgs e)
{
RadioButton selectButton = (RadioButton)sender;
GridViewRow row = (GridViewRow)selectButton.Parent.Parent;
int a = row.RowIndex;
foreach (GridViewRow rw in GridView1.Rows)
{
if (selectButton.Checked)
{
if (rw.RowIndex != a)
{
RadioButton rd = rw.FindControl("rdb_select") as RadioButton;
rd.Checked = false;
}
}
}
}
关于c# - 如何在单击 gridview 行时调用函数。这两个函数都放在 aspx 页面的脚本标签中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16250051/