ASP.WEB Form 几点知识

1、GridView 行的多选

     

<asp:TemplateField ControlStyle-Width="30" HeaderText="选择"    >
                                <ItemTemplate>
                                    <asp:CheckBox ID="DeleteThis" οnclick="javascript:CCA(this);" runat="server" />
                                </ItemTemplate>
                            </asp:TemplateField>        


private string GetSelIDlist()
        {
            string idlist = "";
            bool BxsChkd = false;
            for (int i = 0; i < gridView.Rows.Count; i++)
            {
                CheckBox ChkBxItem = (CheckBox)gridView.Rows[i].FindControl("DeleteThis");
                if (ChkBxItem != null && ChkBxItem.Checked)
                {
                    BxsChkd = true;
                    //#warning 代码生成警告:请检查确认Cells的列索引是否正确
                    if (gridView.DataKeys[i].Value != null)
                    {                        
                        idlist += gridView.DataKeys[i].Value.ToString() + ",";
                    }
                }
            }
            if (BxsChkd)
            {
                idlist = idlist.Substring(0, idlist.LastIndexOf(","));
            }
            return idlist;
        }
/// <summary>
  /// 批量删除数据
  /// </summary>
  public bool DeleteList(string Idlist )
  {
   StringBuilder strSql=new StringBuilder();
   strSql.Append("delete from General_KnowledgePoint ");
   strSql.Append(" where Id in ("+Idlist + ")  ");
   int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
   if (rows > 0)
   {
    return true;
   }
   else
   {
    return false;
   }
  }

 

 方式二:

    <script type="text/JavaScript">
        function CheckBoxAll() {
            if ($("input[id*='ContentPlaceHolder1_GVListShow_chkAllProp']").attr("checked") == true) {
                $("input[id*='chkSelect']").attr("checked", true);
            }
            else {
                $("input[id*='chkSelect']").attr("checked", false);
            }
        }
    </script>

                    <asp:TemplateField HeaderText="选择">
                        <HeaderTemplate>
                            <input type="checkbox" id="chkAllProp" runat="server" οnclick="CheckBoxAll()" />全选
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:CheckBox ID="chkSelect" runat="server" Text="选择" />
                        </ItemTemplate>
                    </asp:TemplateField>

        //取主键值
        string GetIndexKey()
        {
            string indexKey = "";
            for (int i = 0; i <= GVListShow.Rows.Count - 1; i++)
            {
                CheckBox cbox = (CheckBox)GVListShow.Rows[i].FindControl("chkSelect");
                if (cbox.Checked == true)
                {
                    if (indexKey == "")
                    {
                        indexKey = GVListShow.Rows[i].Cells[0].Text.Trim();
                    }
                    else
                    {
                        indexKey += "," + GVListShow.Rows[i].Cells[0].Text.Trim();
                    }
                }
            }
            return indexKey;
        }

相关实例:
//批量删除
        protected void btnDelect_Click(object sender, EventArgs e)
        {
            string indexKeys = GetIndexKey();
            if (indexKeys != "")
            {
                string strWhere = string.Format("Id in ({0})", indexKeys);
                DotNet.BLL.Web_Article BLL = new DotNet.BLL.Web_Article();
                if (1 <= BLL.DeleteWhere(strWhere, null))
                {
                    Web_ArticleBind();
                }
            }
        }

        protected void btnTop_Click(object sender, EventArgs e)
        {
            string indexKeys = GetIndexKey();
            if (indexKeys != "")
            {
                DotNet.BLL.Web_Article BLL = new DotNet.BLL.Web_Article();
                int maxTopNum = 0;
                string strGetWhere = "ComanyId = " + USER.SchoolId;
                object selMaxTopNum = BLL.GetSingle("Max(OrderNum)", strGetWhere, null);
                string strWhere = string.Format("Id in ({0})", indexKeys);
                if (selMaxTopNum != null)
                {
                    maxTopNum = int.Parse(selMaxTopNum.ToString()) + 1;
                    if (1 <= BLL.Update("OrderNum = " + maxTopNum, strWhere, null))
                    {
                        Web_ArticleBind();
                    }
                }
            }
        }

        protected void btnCancelTop_Click(object sender, EventArgs e)
        {
            string indexKeys = GetIndexKey();
            if (indexKeys != "")
            {
                DotNet.BLL.Web_Article BLL = new DotNet.BLL.Web_Article();
                int maxTopNum = 0;
                //object selMaxTopNum = BLL.GetSingle("Max(top_num)", "", null);
                string strWhere = string.Format("Id in ({0})", indexKeys);
                if (1 <= BLL.Update("OrderNum = " + maxTopNum, strWhere, null))
                {
                    Web_ArticleBind();
                }
            }
        }

        //审核新闻
        protected void btnPass_Click(object sender, EventArgs e)
        {
            string indexKeys = GetIndexKey();
            if (indexKeys != "")
            {
                DotNet.BLL.Web_Article BLL = new DotNet.BLL.Web_Article();
                string strWhere = string.Format("Id in ({0})", indexKeys);
                if (1 <= BLL.Update("StateNum = 2,StateName='已审核' ", strWhere, null))
                {
                    //Response.Redirect(Request.Url.ToString());
                    Web_ArticleBind();

                }
            }
        }

        //取消审核
        protected void btnUnpass_Click(object sender, EventArgs e)
        {
            string indexKeys = GetIndexKey();
            string strUpdate = "SavedOn=getdate()";
            if (indexKeys != "")
            {
                DotNet.BLL.Web_Article BLL = new DotNet.BLL.Web_Article();
                string strWhere = string.Format("Id in ({0})", indexKeys);
                if (1 <= BLL.Update(strUpdate+",StateNum = 1,StateName='未审核'", strWhere, null))
                {
                    //Web_NewsBind();
                    //Response.Redirect(Request.Url.ToString());
                    Web_ArticleBind();
                }
            }
        }

        //转移新闻栏目
        protected void btnChangeCategory_Click(object sender, EventArgs e)
        {
            if (DdlCategoryIdNew.SelectedValue.Trim() == "0")
            {
                DotNet.Common.MessageBox.Show(this, "请选择栏目");
                return;
            }

            string indexKeys = GetIndexKey();
            if (indexKeys != "")
            {
                DotNet.BLL.Web_Article BLL = new DotNet.BLL.Web_Article();
                string strField = "CategoryId = @CategoryId,CategoryName = @CategoryName";
                Hashtable ht = new Hashtable();
                ht.Add("@CategoryId", DdlCategoryIdNew.SelectedValue.Trim());
                ht.Add("@CategoryName", DdlCategoryIdNew.SelectedItem.Text.Trim());
                string strWhere = string.Format("Id in ({0})", indexKeys);
                if (1 <= BLL.Update(strField, strWhere, ht))
                {
                    Web_ArticleBind();
                }
            }
        }

 

 

转载于:https://www.cnblogs.com/chenmfly/p/4382886.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值