1、GridView 行的多选

<asp:TemplateField ControlStyle-Width="30" HeaderText="选择"    >
<ItemTemplate>
<asp:CheckBox ID="DeleteThis" onclick="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" onclick="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();
}
}
}

ASP.WEB Form 几点知识的更多相关文章

  1. ASP.Net Web Form<一> aspx文件编译及呈现

    对比复习下JSP 1.jsp的本质是Servlet ,会在第一次被访问时会被翻译成一个类文件,从此对这个页面的访问都是由这个类文件执行后进行输出. aspx 本质是IHttpHandler 2.jsp ...

  2. ASP.NET MVC与ASP.NET Web Form简单区别与适用场景

    概论: Asp.net  微软 提供web开发框架或者技术.分Web Form和ASP.NET MVC.下面简单说明各自优缺点及使用场景. Web Form 优点: 1.支持丰富的服务器控件.如:Gr ...

  3. Web Form 和asp.net mvc 差别

    Asp.net MVC 和web Form的基本区别 Web Form ASP.NET MVC 视图和逻辑紧密耦合 视图和逻辑分离 页面(给予文件的URL) 控制器(基于路由的URL) 状态管理(视图 ...

  4. Asp.net web form url route使用总结

    asp.net web form 使用URL路由 注不是mvc中的路由 一.前台控件使用路由,通过表达式生成url地址,注意给路由参数赋值,防止使用了其他路由表达式值方式1:<asp:Hyper ...

  5. ASP.NET Web Form和MVC中防止F5刷新引起的重复提交问题

    转载 http://www.cnblogs.com/hiteddy/archive/2012/03/29/Prevent_Resubmit_When_Refresh_Reload_In_ASP_NET ...

  6. 转载ASP.NET MVC 和ASP.NET Web Form简单区别

    转载原地址 http://www.cnblogs.com/lei2007/p/3315431.html 概论: Asp.net  微软 提供web开发框架或者技术.分Web Form和ASP.NET  ...

  7. 关于asp.net web form 和 asp.net mvc 的区别

    asp.net web forms 有什么缺陷? 1.视图状态臃肿:服务器和客户端传输过程中包含了大量的试图状态——在现在的web程序中甚至多达几百kb,而且每次往返都会请求,导致服务器请求带宽增加, ...

  8. 在asp.net web form项目中添加webapi接口

    我有一个支付宝服务网关是ASP.NET WEB FORM项目,但是最近这个网关需要对外提供几个接口,想了下,使用web api比较合适,实现很简单,GO 1,首先添加一个文件夹名字叫App_Start ...

  9. ASP.NET MVC与ASP.NET Web Form简单区别

    概论: Asp.net  微软 提供web开发框架或者技术.分Web Form和ASP.NET MVC.下面简单说明各自优缺点及使用场景. Web Form 优点: 1.支持丰富的服务器控件.如:Gr ...

随机推荐

  1. IOS设置图片背景

    在UIViewController里面这样设置: self.view.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageN ...

  2. Unity3D引擎之渲染技术系列一

    笔者介绍:姜雪伟,IT公司技术合伙人,IT高级讲师,CSDN社区专家,特邀编辑,畅销书作者.国家专利发明人;已出版书籍:<手把手教你架构3D游戏引擎>电子工业出版社和<Unity3D ...

  3. erlang的非平衡的二叉树的操作

    -module(tree1). -export([test1/0]). lookup(Key,nil) -> not_found; lookup(Key,{Key,Value,_,_}) -&g ...

  4. 转载:SQL 字符串操作函数

    http://www.cnblogs.com/jiajiayuan/archive/2011/06/16/2082488.html 以下所有例子均Studnet表为例:  计算字符串长度len()用来 ...

  5. selenium实现在新窗口打开链接

    问题:页面代码中不存在target="_blank",怎么实现点击一个按钮,在新窗口中打开? WebElement link = element.findElement(By.ta ...

  6. cobbler pxe-menu

    对应的文件在 /var/lib/tftpboot/pxelinux.cfg下 如果profile的pxe-menu设置为1的话,就可以默认显示在menu上了.可以手动选择要下发哪一个profile. ...

  7. Hadoop 101: Programming MapReduce with Native Libraries, Hive, Pig, and Cascading

    和Hadoop交互的四种方法: 1. Native Libraries 2. Hive 3. Pig 4. Cascading At a high level, people use the nati ...

  8. Sum of Remainders(数学题)

    F - Sum of Remainders Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I ...

  9. xlrd python excel

     xlrd python excel

  10. Notepad++ Tidy2 插件的核心配置

    在已有配置的基础上加上这四行: 以免符号被转换成HTML实体了 preserve-entities: yes quote-ampersand: yes quote-marks: no quote-nb ...