首页  ·  知识 ·  
Label
      编辑:  图片来源:网络

方法一,客户端

 //绑定

  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属性

            }


        }

脚本

<script type="text/javascript">
         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("<%=txtDealID.ClientID %>");
            
             //dealid.value = obj.;

         }

    </script>

方法二,服务器端

    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;
                    }
                }

            }


        }

本文作者:网友 来源: http://www.cnblogs.com/valensoft/
CIO之家 www.ciozj.com 微信公众号:imciow
   
免责声明:本站转载此文章旨在分享信息,不代表对其内容的完全认同。文章来源已尽可能注明,若涉及版权问题,请及时与我们联系,我们将积极配合处理。同时,我们无法对文章内容的真实性、准确性及完整性进行完全保证,对于因文章内容而产生的任何后果,本账号不承担法律责任。转载仅出于传播目的,读者应自行对内容进行核实与判断。请谨慎参考文章信息,一切责任由读者自行承担。
延伸阅读
也许感兴趣的
我们推荐的
主题最新
看看其它的
收藏至微信