GridView中的RadioButton单选的方法

方法一,客户端

 //绑定

  protected void gvAssDealReport_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                RadioButton rb = (RadioButton)e.Row.FindControl("raButton");

                rb.Attributes.Add("onclick", "judge(this)");//给RadioButton添加onclick属性

            }


        }

脚本


         var last = null;//最后访问的RadioButton的ID
         function judge(obj)
        {

             if(last == null)

            {

                 last = obj.id;

            //      alert(last);

             }

             else

            {

                 var lo = document.getElementById(last);

                 lo.checked = "";

          //        alert(last + "   " + lo.checked);

                 last = obj.name;

             }

             obj.checked = "checked";

             var dealid = document.getElementById("");
            
             //dealid.value = obj.;

         }

   

方法二,服务器端

    protected void raButton_CheckedChanged(object sender, EventArgs e)
        {
            清空checkbox
            foreach (GridViewRow row in this.gvAssDealReport.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    RadioButton rb = (RadioButton)row.FindControl("raButton");
                    rb.Checked = false;                  
                }

            }

           选中
            RadioButton btn = sender as RadioButton;
            btn.Checked = true;

            foreach (GridViewRow row in this.gvAssDealReport.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    RadioButton rb = (RadioButton)row.FindControl("raButton");

                    if (rb.Checked)
                    {
                        txtDealID.Text = row.Cells[1].Text.Trim();
                        btnQueryDealReport_Click(null, null);
                        break;
                    }
                }

            }


        }

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12639172/viewspace-664084/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/12639172/viewspace-664084/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值