c# - 如何在单击 gridview 行时调用函数。这两个函数都放在 aspx 页面的脚本标签中

标签 c# asp.net gridview

我希望在单击 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/

相关文章:

c# - 在 c# winform 应用程序中使用安装的字体时出现问题

c# - 仅当数据不存在时如何将数据添加到表中?

c# - 如何在.Net Core中使用REST API访问azure表存储

c# - Membership(+ roles) VS session state VS 表单认证

c# - 为用户添加角色(Windows 身份验证)

asp.net - 从 EF 6 Code First 迁移和多个配置生成完整的 SQL 脚本

c# - Gridview 编辑更新删除行点击 Asp.net

c# - C#中的数组切割和合并

jquery - 打开并显示我的 jquery 对话框时出现问题

c# - 在 gridview 中使用 HyperLinkField 进行 URL 导航