datagrid有一个模板列CheckBox和一个模板列label,其中当label(GVlblflag)的值为1时,当勾选checkbox时:
   1. 就弹出提示是否发邮件对话框, 如果用户点击“确定”就发邮件,点击取消则不发送;
   2. 刚点的这一条的checkbox不可用、不被选中现我的做法是:在datagrid的RowDataBound事件里实现弹出对话框,当选择label的text值为1对应的checkbox时,弹出对话框,根据用户选择作相应动作,但chk的可用和不被选中的没能实现。
在js里不执行document.getElementById('btnsend').click();状态能控件,但邮件又发不出去。
  html:
     <asp:GridView ID="GVList" runat="server"   AutoGenerateColumns="False"  AllowPaging="True" OnPageIndexChanging="GVList_PageIndexChanging" PageSize="10" OnRowDataBound="GVList_RowDataBound"  >              
                    <Columns>                   
                         <asp:TemplateField >
                            <HeaderTemplate>
                            <asp:Button ID="btnimport" runat="server" SkinID="ButtonSkin_Menu"  Text="申请" CommandName="import" OnClick="btnimport_Click" />
                            </HeaderTemplate>
                            <ItemTemplate>
                            <asp:CheckBox ID="GVchkbox" runat="server" Checked='<%# Bind("chk") %>' /> 
                            <asp:Label ID="GVlblflag" runat="server"  Text='<%# Bind("flag") %>'></asp:Label>
                            </ItemTemplate>                           
                        </asp:TemplateField>                          
                        </asp:TemplateField>
            
                        <asp:TemplateField  SortExpression ="WareCD">
                            <HeaderTemplate>
                             <asp:LinkButton ID="GVlbtnWareCD" runat="server" >商品代码</asp:LinkButton>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:Label ID="GVlblWareCD" runat="server"  Text='<%# Bind("WareCD") %>'></asp:Label>
                            </ItemTemplate>                           
                        </asp:TemplateField>
                  ...
javascript:
    function IsConfirm(msg,rows)
    {     
       if(confirm(msg))  //确定
       {   
           var sn= parseInt(rows)+2;
           var gvlistid='GVList_ctl';             
           if(String(sn).length<2)
           {
               gvlistid=gvlistid+'0';
           }    
          var chk=gvlistid+sn+'_GVchkbox';      //得到是选中了哪个chk    
          document.getElementById('txtwarecd').value=document.getElementById('txtwarecd').value+",'"+document.getElementById(gvlistid+sn+'_GVlblWareCD').innerText+"'";   //邮件内容里用的字段值
         document.getElementById('btnsend').click();  //发邮件事件
         document.getElementById(chk).checked=false;     //控件chk不被选中   
         document.getElementById(chk).disabled=true;  //控制chk不可用
         return true;          
       }
       return true;
    }后台代码:
    protected void GVList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
               CheckBox chk = (CheckBox)e.Row.Cells[0].FindControl("GVchkbox");
               Label Lab = Labele.Row.Cells[0].FindControl("GVlblflag");                if (Lab.Text == "1")
                {
                    chk.Attributes.Add("onclick", "return IsConfirm('" + SystemContant.MESSAGE_Ware_ReInquire + "','" + e.Row.RowIndex + "');");                    //选中时,弹出提示对话框
                }
                else
                {
                    chk.Attributes.Add("onclick", "");                 
                }
    }  protected void btnsend_Click(object sender, EventArgs e)
        { 
            //发邮件
            EntB0010 entb0010 = new EntB0010(EmpNo);
            string warecd = txtwarecd.Text.Trim();
            SendEmail()...具体的发邮件
        }     

解决方案 »

  1.   

      发送邮件前台js调用后台服务器控件事件,方法错误... 
      document.getElementById('btnsend').click();  //发邮件事件 此功能有误!!!  解决方案:
      js: __doPostBack('CE_btnsend_Click', '');
      .cs:
      
          protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (this.IsPostBack)
            {
                if ((Request.Form["__EVENTTARGET"] != null) && (Request.Form["__EVENTTARGET"] != ""))
                {
                    if (Request.Form["__EVENTTARGET"].Substring(0, 3) == "CE_")
                    {
                        String strEventArgument = Request.Form["__EVENTARGUMENT"];
                        Type type = this.GetType();
                        /*using System.Reflection;*/
                        MethodInfo mi = type.GetMethod(Request.Form["__EVENTTARGET"], BindingFlags.Instance | BindingFlags.NonPublic);
                        if (mi != null)
                        {
                            mi.Invoke(this, new object[] { strEventArgument });
                        }
                    }
                }
            }
        }    /// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void CE_btnsend_Click(string param)
        {
            /*发送邮件*/
        }