gridview与checkbox,button,新闻发布v1.0版 by yfdong22
相对于数据绑定的数据库操作就不写出来了,这也很烦,无谓再写出来;里头的只是一点点的小知识,基本上都是基础知识,网站开发也用不了高深的知识,所这个好合菜鸟学习!
效果:
前台代码:
代码
BorderWidth
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<%@ Page Language="C#" MasterPageFile="~/admin/adminmasterpage.master" AutoEventWireup="true" CodeFile="NewsList.aspx.cs" Inherits="admin_News_NewsList" Title="Untitled Page"%>
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer"%>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table class="table" width="99%" border="0" align="center" cellpadding="0" cellspacing="1">
<tr class="bg_tr">
<td>
<div style="text-align:left; float:left; width:40%;">
<asp:Button ID="btDelete" runat="server" Text="删除所选" OnClick="btDelete_Click"/>
<asp:Button ID="btAllData" runat="server" Text="显示所有" OnClick="btAllData_Click"/>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="分类管理"/> <asp:Button
ID="Button2" runat="server" OnClick="Button2_Click" Text="添加新闻"/></div>
<div style="text-align:right; width:60%; float:left;">
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<asp:Button ID="btSearch" runat="server" Text="搜索" OnClick="btSearch_Click"/></div></td>
</tr>
</table>
<table class="table" width="96%" border="0" align="center" cellpadding="0" cellspacing="1">
<tr align="center" valign="top">
<td class="td_bg">
<asp:GridView ID="Gridview1" CssClass="top" runat="server" EmptyDataText="没有此信息"
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer"%>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table class="table" width="99%" border="0" align="center" cellpadding="0" cellspacing="1">
<tr class="bg_tr">
<td>
<div style="text-align:left; float:left; width:40%;">
<asp:Button ID="btDelete" runat="server" Text="删除所选" OnClick="btDelete_Click"/>
<asp:Button ID="btAllData" runat="server" Text="显示所有" OnClick="btAllData_Click"/>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="分类管理"/> <asp:Button
ID="Button2" runat="server" OnClick="Button2_Click" Text="添加新闻"/></div>
<div style="text-align:right; width:60%; float:left;">
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<asp:Button ID="btSearch" runat="server" Text="搜索" OnClick="btSearch_Click"/></div></td>
</tr>
</table>
<table class="table" width="96%" border="0" align="center" cellpadding="0" cellspacing="1">
<tr align="center" valign="top">
<td class="td_bg">
<asp:GridView ID="Gridview1" CssClass="top" runat="server" EmptyDataText="没有此信息"
AutoGenerateColumns="False"
OnRowCommand="Gridview1_RowCommand" PageSize="2" width="100%" BackColor="White"
OnRowCommand="Gridview1_RowCommand" PageSize="2" width="100%" BackColor="White"
BorderColor="#CCCCCC" BorderStyle="None"
BorderWidth
DataBinder.Eval(Container.DataItem, "title").ToString().Substring(0, 55) +"..." :
DataBinder.Eval(Container.DataItem, "title")%>
<br />
<%# DataBinder.Eval(Container.DataItem, "title_en").ToString().Length >55 ?
<br />
<%# DataBinder.Eval(Container.DataItem, "title_en").ToString().Length >55 ?
DataBinder.Eval(Container.DataItem, "title_en").ToString().Substring(0, 55) +"..." :
DataBinder.Eval(Container.DataItem, "title_en")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="类别(中/英)">
<ItemTemplate >
<%# DataBinder.Eval(Container.DataItem,"class")%>
<br />
<%# DataBinder.Eval(Container.DataItem,"class_en")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="发布时间">
<ItemTemplate >
<%# DataBinder.Eval(Container.DataItem,"date","{0:d}")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="阅读数">
<ItemTemplate >
<asp:HiddenField ID="HiddenFieldnum" Value='<%# Eval("num") %>' runat="server" />
<asp:TextBox ID="tbnum" BorderStyle="solid" BorderWidth="1" BorderColor="#e6f5fa"
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="类别(中/英)">
<ItemTemplate >
<%# DataBinder.Eval(Container.DataItem,"class")%>
<br />
<%# DataBinder.Eval(Container.DataItem,"class_en")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="发布时间">
<ItemTemplate >
<%# DataBinder.Eval(Container.DataItem,"date","{0:d}")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="阅读数">
<ItemTemplate >
<asp:HiddenField ID="HiddenFieldnum" Value='<%# Eval("num") %>' runat="server" />
<asp:TextBox ID="tbnum" BorderStyle="solid" BorderWidth="1" BorderColor="#e6f5fa"
runat="server" Text='<%# Eval("num") %>' Width="20px"></asp:TextBox>
<asp:ImageButton ID="imgbtnupdate1" ImageUrl="~/admin/images/update.gif"
<asp:ImageButton ID="imgbtnupdate1" ImageUrl="~/admin/images/update.gif"
AlternateText="更新阅读数" OnClick="updatenum" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="排序">
<ItemTemplate >
<asp:HiddenField ID="HiddenFieldxuhao" Value='<%# Eval("xuhao") %>' runat="server" />
<asp:TextBox ID="tbxuhao" Text='<%# Eval("xuhao") %>' Width="20px"
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="排序">
<ItemTemplate >
<asp:HiddenField ID="HiddenFieldxuhao" Value='<%# Eval("xuhao") %>' runat="server" />
<asp:TextBox ID="tbxuhao" Text='<%# Eval("xuhao") %>' Width="20px"
BorderStyle="solid" BorderColor="#e6f5fa" runat="server"></asp:TextBox>
<asp:ImageButton ID="imgbtnup" ImageUrl="~/admin/images/up.gif" OnClick="upxuhao"
<asp:ImageButton ID="imgbtnup" ImageUrl="~/admin/images/up.gif" OnClick="upxuhao"
AlternateText="排序上升" runat="server"/>
<asp:ImageButton ID="imgbtndown" ImageUrl="~/admin/images/down.gif" AlternateText="排序下降"
<asp:ImageButton ID="imgbtndown" ImageUrl="~/admin/images/down.gif" AlternateText="排序下降"
OnClick="downxuhao" runat="server"/>
<asp:ImageButton ID="imgbtnupdate" ImageUrl="~/admin/images/update.gif" AlternateText="更新排序数"
<asp:ImageButton ID="imgbtnupdate" ImageUrl="~/admin/images/update.gif" AlternateText="更新排序数"
OnClick="updatexuhao" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="推荐">
<ItemTemplate >
<asp:CheckBox ID="cbtuijianpiliang" Visible="false" runat="server"/>
<asp:CheckBox ID="cbtuijian" runat="server" OnCheckedChanged="changedtuijian" AutoPostBack="true"/>
<asp:HiddenField ID="HiddenFieldtuijian" Value='<%# Eval("tuijian") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="显示">
<ItemTemplate >
<asp:CheckBox ID="cbshowpiliang" Visible="false" runat="server"/>
<asp:CheckBox ID="cbshow" runat="server" OnCheckedChanged="changedshow" AutoPostBack="true"/>
<asp:HiddenField ID="HiddenFieldshow" Value='<%# Eval("show") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="热点">
<ItemTemplate >
<asp:CheckBox ID="cbhitpiliang" Visible="false" runat="server"/>
<asp:CheckBox ID="cbhit" runat="server" OnCheckedChanged="changedhit" AutoPostBack="true"/>
<asp:HiddenField ID="HiddenFieldhit" Value='<%# Eval("hit") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False" HeaderText="编辑">
<itemtemplate>
<asp:LinkButton ID="lkbSee" runat="server" CommandName="View"
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="推荐">
<ItemTemplate >
<asp:CheckBox ID="cbtuijianpiliang" Visible="false" runat="server"/>
<asp:CheckBox ID="cbtuijian" runat="server" OnCheckedChanged="changedtuijian" AutoPostBack="true"/>
<asp:HiddenField ID="HiddenFieldtuijian" Value='<%# Eval("tuijian") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="显示">
<ItemTemplate >
<asp:CheckBox ID="cbshowpiliang" Visible="false" runat="server"/>
<asp:CheckBox ID="cbshow" runat="server" OnCheckedChanged="changedshow" AutoPostBack="true"/>
<asp:HiddenField ID="HiddenFieldshow" Value='<%# Eval("show") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="热点">
<ItemTemplate >
<asp:CheckBox ID="cbhitpiliang" Visible="false" runat="server"/>
<asp:CheckBox ID="cbhit" runat="server" OnCheckedChanged="changedhit" AutoPostBack="true"/>
<asp:HiddenField ID="HiddenFieldhit" Value='<%# Eval("hit") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False" HeaderText="编辑">
<itemtemplate>
<asp:LinkButton ID="lkbSee" runat="server" CommandName="View"
CommandArgument='<%# DataBinder.Eval(Container.DataItem,"id") %>' >编辑</asp:LinkButton>
</itemtemplate>
</asp:TemplateField>
</columns>
<RowStyle BorderWidth="1px" BackColor="White"/>
<FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True"/>
<HeaderStyle CssClass="bg_tr" BackColor="#E4F1FA" Font-Bold="True" ForeColor="#1E5494" Font-Size="12px"/>
<EditRowStyle BackColor="#2461BF"/>
<AlternatingRowStyle BackColor="White"/>
</asp:GridView>
<webdiyer:aspnetpager id="AspNetPager1" runat="server" ShowCustomInfoSection="Left" CustomInfoTextAlign="Center"
CustomInfoHTML="当前为第%CurrentPageIndex%/%PageCount%页 每页%PageSize%条" SubmitButtonText="Go"
</itemtemplate>
</asp:TemplateField>
</columns>
<RowStyle BorderWidth="1px" BackColor="White"/>
<FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True"/>
<HeaderStyle CssClass="bg_tr" BackColor="#E4F1FA" Font-Bold="True" ForeColor="#1E5494" Font-Size="12px"/>
<EditRowStyle BackColor="#2461BF"/>
<AlternatingRowStyle BackColor="White"/>
</asp:GridView>
<webdiyer:aspnetpager id="AspNetPager1" runat="server" ShowCustomInfoSection="Left" CustomInfoTextAlign="Center"
CustomInfoHTML="当前为第%CurrentPageIndex%/%PageCount%页 每页%PageSize%条" SubmitButtonText="Go"
ShowInputBox="Always" NextPageText="下一页" PrevPageText="上一页" LastPageText="尾页" FirstPageText="首页"
CustomInfoStyle="padding:6px 0 0 0;"
Height="23px" OnPageChanging="AspNetPager1_PageChanging" ShowPageIndexBox="Always" HorizontalAlign="Center"
Height="23px" OnPageChanging="AspNetPager1_PageChanging" ShowPageIndexBox="Always" HorizontalAlign="Center"
PagingButtonLayoutType="Span" TextAfterPageIndexBox=" 页" TextBeforePageIndexBox="转到 " Wrap="False"
NumericButtonCount="5"></webdiyer:aspnetpager>
<br />
</td>
</tr>
</table>
<table class="table" width="99%" border="0" align="center" cellpadding="0" cellspacing="1">
<tr class="bg_tr">
<td>
<div style="text-align:left; float:left; width:40%;">
</div>
<div style="text-align:right; width:60%; float:left;">
(是否启用批量修改)<asp:CheckBox ID="cbpiliang" runat="server" OnCheckedChanged="cbpiliang_changed" AutoPostBack="true"/>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="0" Text="==要批量修改的内容=="></asp:ListItem>
<asp:ListItem Value="xuhao" Text="排序"></asp:ListItem>
<asp:ListItem Value="num" Text="阅读数"></asp:ListItem>
<asp:ListItem Value="hit" Text="热点"></asp:ListItem>
<asp:ListItem Value="show" Text="显示"></asp:ListItem>
<asp:ListItem Value="tuijian" Text="推荐"></asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btnupdateall" runat="server" Text="更新" OnClick="btnupdateall_Click"/></div></td>
</tr>
</table>
</asp:Content>
<br />
</td>
</tr>
</table>
<table class="table" width="99%" border="0" align="center" cellpadding="0" cellspacing="1">
<tr class="bg_tr">
<td>
<div style="text-align:left; float:left; width:40%;">
</div>
<div style="text-align:right; width:60%; float:left;">
(是否启用批量修改)<asp:CheckBox ID="cbpiliang" runat="server" OnCheckedChanged="cbpiliang_changed" AutoPostBack="true"/>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="0" Text="==要批量修改的内容=="></asp:ListItem>
<asp:ListItem Value="xuhao" Text="排序"></asp:ListItem>
<asp:ListItem Value="num" Text="阅读数"></asp:ListItem>
<asp:ListItem Value="hit" Text="热点"></asp:ListItem>
<asp:ListItem Value="show" Text="显示"></asp:ListItem>
<asp:ListItem Value="tuijian" Text="推荐"></asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btnupdateall" runat="server" Text="更新" OnClick="btnupdateall_Click"/></div></td>
</tr>
</table>
</asp:Content>
="1px" CellPadding="4" ForeColor="Black" HorizontalAlign="Center" f GridLines="Horizontal" OnRowDataBound="Gridview1_RowDataBound">
<columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chAll" runat="server" AutoPostBack="true" OnCheckedChanged="chAll_CheckedChanged"/>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="mycheck" runat="server"/>
</ItemTemplate>
<ControlStyle Width="10px"/>
</asp:TemplateField>
<asp:BoundField DataField="id" HeaderText="编号">
<ControlStyle Width="10px"/>
</asp:BoundField>
<asp:TemplateField HeaderText="标题(中/英)">
<ItemTemplate >
<asp:HiddenField ID="HiddenFieldid" Value='<%# Eval("id") %>' runat="server" />
<%# DataBinder.Eval(Container.DataItem, "title").ToString().Length >55 ?
后台代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SystemBll;
using SystemNewsBll;
using SystemChars;
publicpartialclass admin_News_NewsList : System.Web.UI.Page
{
BLL bll =new BLL();
//NewsBll nbll = new NewsBll();
protectedvoid Page_Load(object sender, EventArgs e)
{
btDelete.Attributes["onclick"] ="javascript:return confirm('是否确定删除?')";
//下面这行是自动换行
Gridview1.Attributes.Add("style", "word-break:break-all;word-wrap:break-word");
if (!Page.IsPostBack)
{
if (Request.Cookies["searchname"] !=null)
{
Response.Cookies["searchname"].Expires = DateTime.Now.AddDays(-1);
Response.Cookies["searchname_s"].Expires = DateTime.Now.AddDays(-1);
}
BindAspNetPagerSearch(null, null);
BindFeedbackDataSearch(null, null);
}
}
#region 数据绑定与翻页总数与翻页
//绑定精选内容翻页数
privatevoid BindAspNetPagerSearch(string search, string SearchName)
{
AspNetPager1.AlwaysShow =true;
AspNetPager1.PageSize =10;
AspNetPager1.RecordCount = NewsBll.CountSearch(search, SearchName);
}
//搜索精选内容
privatevoid BindFeedbackDataSearch(string search, string SearchName)
{
Gridview1.DataSource = NewsBll.GetMsgSearch(AspNetPager1, search, SearchName);
Gridview1.DataBind();
}
//翻页
protectedvoid AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
bindreset();//重新绑定
}
#endregion
#region 编辑修改 删除 搜索
//编辑
protectedvoid Gridview1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName =="View")
{
int a = Convert.ToInt32(e.CommandArgument.ToString());
Response.Redirect("NewsEdit.aspx?id="+ a);
}
}
//删除
protectedvoid btDelete_Click(object sender, EventArgs e)
{
if (Gridview1.Rows.Count !=0)
{
int Nresult =0;
for (int j =0; j <= Gridview1.Rows.Count -1; j++)
{
CheckBox cbox = (CheckBox)Gridview1.Rows[j].FindControl("mycheck");
if (cbox.Checked ==true)
{
Nresult =1;
}
}
if (Nresult ==0)
{
MessageBox.Show(Page, "请选择你要删除的内容");
}
else
{
int nResult =-1;
for (int i =0; i <= Gridview1.Rows.Count -1; i++)
{
CheckBox cbox = (CheckBox)Gridview1.Rows[i].FindControl("mycheck");
if (cbox.Checked ==true)
{
int id = Convert.ToInt32(Convert.ToInt32(Gridview1.Rows[i].Cells[1].Text));
Common.Deletesql("news", "id="+ id);
nResult =1;
}
}
if (nResult !=-1)
{
//重新绑定 aspnet
bindresetaspnet();
}
}
MessageBox.Show(Page, "删除数据成功!");
}
else
{
MessageBox.Show(Page, "没有可删除的数据!");
}
}
//搜索
protectedvoid btSearch_Click(object sender, EventArgs e)
{
if (txtSearch.Text ==""|| txtSearch.Text ==null)
{
MessageBox.Show(Page, "请输入搜索关键字!");
}
else
{
string search = txtSearch.Text.Trim();
string SearchName ="";
Response.Cookies["searchname"].Value = search;
Response.Cookies["searchname_s"].Value = SearchName;
BindAspNetPagerSearch(search, SearchName);
BindFeedbackDataSearch(search, SearchName);
}
}
#endregion
#region 选择 显示所有数据 特效
//特效
protectedvoid Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
{
int a = e.Row.Cells.Count;
//控制字符显示长度,若大于18个字符,显示前18个,后加"..." 只针对BoundField绑定的字段,其它无效
for (int i =0; i < e.Row.Cells.Count; i++)
{
if (e.Row.Cells[i].Text.Length >20)
{
e.Row.Cells[i].Text = e.Row.Cells[i].Text.Substring(0, 20) +"...";
}
}
//行背景色变
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标经过时,行背景色变
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
//鼠标移出时,行背景色变
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
}
//只能输入数字
TextBox tbxuhao = (TextBox)e.Row.FindControl("tbxuhao");
if (tbxuhao !=null)
{
tbxuhao.Attributes["onkeyup"] ="value=value.replace(/[^\\d]/g,'')";
}
TextBox tbnum = (TextBox)e.Row.FindControl("tbnum");
if (tbnum !=null)
{
tbnum.Attributes["onkeyup"] ="value=value.replace(/[^\\d]/g,'')";
}
for (int i =0; Gridview1.Rows.Count > i; i++)
{
//推荐
CheckBox cbtuijian = (CheckBox)Gridview1.Rows[i].FindControl("cbtuijian");
CheckBox cbtuijianpiliang = (CheckBox)Gridview1.Rows[i].FindControl("cbtuijianpiliang");
HiddenField hiddtuijian = (HiddenField)Gridview1.Rows[i].FindControl("HiddenFieldtuijian");
if (hiddtuijian.Value =="1")
{
cbtuijian.Checked =true;
cbtuijianpiliang.Checked =true;
}
//显示
CheckBox cbshow = (CheckBox)Gridview1.Rows[i].FindControl("cbshow");
CheckBox cbshowpiliang = (CheckBox)Gridview1.Rows[i].FindControl("cbshowpiliang");
HiddenField hiddshow = (HiddenField)Gridview1.Rows[i].FindControl("HiddenFieldshow");
if (hiddshow.Value =="1")
{
cbshow.Checked =true;
cbshowpiliang.Checked =true;
}
//热点
CheckBox cbhit = (CheckBox)Gridview1.Rows[i].FindControl("cbhit");
CheckBox cbhitpiliang = (CheckBox)Gridview1.Rows[i].FindControl("cbhitpiliang");
HiddenField hiddhit = (HiddenField)Gridview1.Rows[i].FindControl("HiddenFieldhit");
if (hiddhit.Value =="1")
{
cbhit.Checked =true;
cbhitpiliang.Checked =true;
}
}
}
//全选
protectedvoid chAll_CheckedChanged(object sender, EventArgs e)
{
if (Gridview1.Rows.Count !=0)
{
CheckBox chAll = (CheckBox)Gridview1.HeaderRow.FindControl("chAll");
for (int i =0; i <= Gridview1.Rows.Count -1; i++)
{
CheckBox cbox = (CheckBox)Gridview1.Rows[i].FindControl("mycheck");
if (chAll.Checked ==true)
{
cbox.Checked =true;
}
else
{
cbox.Checked =false;
}
}
}
else
{
MessageBox.Show(Page, "没有可选!");
}
}
//显示所有数据
protectedvoid btAllData_Click(object sender, EventArgs e)
{
Response.Cookies["searchname"].Expires = DateTime.Now.AddDays(-1);
Response.Cookies["searchname_s"].Expires = DateTime.Now.AddDays(-1);
BindAspNetPagerSearch(null, null);
BindFeedbackDataSearch(null, null);
}
#endregion 选择
#region button shijian
protectedvoid Button1_Click(object sender, EventArgs e)
{
Response.Redirect("NewsClassList.aspx");
}
protectedvoid Button2_Click(object sender, EventArgs e)
{
Response.Redirect("NewsAdd.aspx");
}
#endregion
#region 显示
protectedvoid changedshow(object sender, EventArgs e)
{
GridViewRow row = ((CheckBox)sender).Parent.Parent as GridViewRow;
HiddenField hdshow = (HiddenField)(row.FindControl("HiddenFieldshow"));
HiddenField hdid = (HiddenField)(row.FindControl("HiddenFieldid"));
if (hdshow.Value =="1")
{
int count = Common.update("news", "show=0", "id="+int.Parse(hdid.Value));
if (count >0)
{
MessageBox.Show(Page, "修改成功!");
bindreset();//重新绑定
}
}
else
{
int count = Common.update("news", "show=1", "id="+int.Parse(hdid.Value));
if (count >0)
{
MessageBox.Show(Page, "修改成功!");
bindreset();//重新绑定
}
}
}
#endregion
#region 推荐
protectedvoid changedtuijian(object sender, EventArgs e)
{
GridViewRow row = ((CheckBox)sender).Parent.Parent as GridViewRow;
HiddenField hdtuijian = (HiddenField)(row.FindControl("HiddenFieldtuijian"));
HiddenField hdid = (HiddenField)(row.FindControl("HiddenFieldid"));
if (hdtuijian.Value =="1")
{
int count = Common.update("news", "tuijian=0", "id="+int.Parse(hdid.Value));
if (count >0)
{
MessageBox.Show(Page, "修改成功!");
//重新绑定
bindreset();//重新绑定
}
}
else
{
int count = Common.update("news", "tuijian=1", "id="+int.Parse(hdid.Value));
if (count >0)
{
MessageBox.Show(Page, "修改成功!");
//重新绑定
bindreset();//重新绑定
}
}
}
#endregion
#region 热点
protectedvoid changedhit(object sender, EventArgs e)
{
GridViewRow row = ((CheckBox)sender).Parent.Parent as GridViewRow;
HiddenField hdhit = (HiddenField)(row.FindControl("HiddenFieldhit"));
HiddenField hdid = (HiddenField)(row.FindControl("HiddenFieldid"));
if (hdhit.Value =="1")
{
int count = Common.update("news", "hit=0", "id="+int.Parse(hdid.Value));
if (count >0)
{
MessageBox.Show(Page, "修改成功!");
//重新绑定
bindreset();//重新绑定
}
}
else
{
int count = Common.update("news", "hit=1", "id="+int.Parse(hdid.Value));
if (count >0)
{
MessageBox.Show(Page, "修改成功!");
//重新绑定
bindreset();//重新绑定
}
}
}
#endregion
#region 排序升一位也就是减一
protectedvoid upxuhao(object sender, EventArgs e)
{
GridViewRow row = ((ImageButton)sender).Parent.Parent as GridViewRow;
HiddenField hdxuhao = (HiddenField)(row.FindControl("HiddenFieldxuhao"));
HiddenField hdid = (HiddenField)(row.FindControl("HiddenFieldid"));
if (hdxuhao.Value !="0")
{
int count = Common.update("[news]", "xuhao=xuhao-1", "id="+int.Parse(hdid.Value));
if (count >0)
{
MessageBox.Show(Page, "修改成功!");
bindreset();//重新绑定
}
}
else
{
MessageBox.Show(Page, "序号已是最高位置了!");
}
}
#endregion
#region 排序下一位也就是加1
protectedvoid downxuhao(object sender, EventArgs e)
{
GridViewRow row = ((ImageButton)sender).Parent.Parent as GridViewRow;
HiddenField hdxuhao = (HiddenField)(row.FindControl("HiddenFieldxuhao"));
HiddenField hdid = (HiddenField)(row.FindControl("HiddenFieldid"));
int count = Common.update("[news]", "xuhao=xuhao+1", "id="+int.Parse(hdid.Value));
if (count >0)
{
MessageBox.Show(Page, "修改成功!");
bindreset();//重新绑定
}
}
#endregion
#region 更新序号
protectedvoid updatexuhao(object sender, EventArgs e)
{
GridViewRow row = ((ImageButton)sender).Parent.Parent as GridViewRow;
HiddenField hdxuhao = (HiddenField)(row.FindControl("HiddenFieldxuhao"));
TextBox tbxuhao = (TextBox)(row.FindControl("tbxuhao"));
HiddenField hdid = (HiddenField)(row.FindControl("HiddenFieldid"));
//过滤特殊字符再转int型
int xuhao = Convert.ToInt32(Chars.FilteringStr(tbxuhao.Text.Trim()));
//更新
int count = Common.update("[news]", "xuhao="+ xuhao, "id="+int.Parse(hdid.Value));
if (count >0)
{
MessageBox.Show(Page, "修改成功!");
bindreset();//重新绑定
}
}
#endregion
#region 更新阅读数
protectedvoid updatenum(object sender, EventArgs e)
{
GridViewRow row = ((ImageButton)sender).Parent.Parent as GridViewRow;
HiddenField hdnum = (HiddenField)(row.FindControl("HiddenFieldnum"));
TextBox tbnum = (TextBox)(row.FindControl("tbnum"));
HiddenField hdid = (HiddenField)(row.FindControl("HiddenFieldid"));
//过滤特殊字符再转int型
int num = Convert.ToInt32(Chars.FilteringStr(tbnum.Text.Trim()));
//更新
int count = Common.update("[news]", "num="+ num, "id="+int.Parse(hdid.Value));
if (count >0)
{
MessageBox.Show(Page, "修改成功!");
bindreset();//重新绑定
}
}
#endregion
#region 是否批量更新
protectedvoid cbpiliang_changed(object sender, EventArgs e)
{
bindpiliang();
}
publicvoid bindpiliang()
{
//批量是
if (cbpiliang.Checked ==true)
{
for (int j =0; j <= Gridview1.Rows.Count -1; j++)
{
// CheckBox cbox = (CheckBox)Gridview1.Rows[j].FindControl("mycheck");
CheckBox cbshow = (CheckBox)Gridview1.Rows[j].FindControl("cbshow");
CheckBox cbtuijian = (CheckBox)Gridview1.Rows[j].FindControl("cbtuijian");
CheckBox cbhit = (CheckBox)Gridview1.Rows[j].FindControl("cbhit");
CheckBox cbshowpiliang = (CheckBox)Gridview1.Rows[j].FindControl("cbshowpiliang");
CheckBox cbtuijianpiliang = (CheckBox)Gridview1.Rows[j].FindControl("cbtuijianpiliang");
CheckBox cbhitpiliang = (CheckBox)Gridview1.Rows[j].FindControl("cbhitpiliang");
ImageButton imgbtnup = (ImageButton)Gridview1.Rows[j].FindControl("imgbtnup");
ImageButton imgbtndown = (ImageButton)Gridview1.Rows[j].FindControl("imgbtndown");
ImageButton imgbtnupdatexuhao = (ImageButton)Gridview1.Rows[j].FindControl("imgbtnupdate");
ImageButton imgbtnupdatenum = (ImageButton)Gridview1.Rows[j].FindControl("imgbtnupdate1");
//因为此都有触发事件
cbhit.Visible =false;
cbtuijian.Visible =false;
cbshow.Visible =false;
cbhitpiliang.Visible =true;
cbtuijianpiliang.Visible =true;
cbshowpiliang.Visible =true;
imgbtndown.Enabled =false;
imgbtnup.Enabled =false;
imgbtnupdatexuhao.Enabled =false;
imgbtnupdatenum.Enabled =false;
imgbtnupdatenum.AlternateText ="批量更新时不可用!";
imgbtnupdatexuhao.AlternateText ="批量更新时不可用!";
imgbtnup.AlternateText ="批量更新时不可用!";
imgbtndown.AlternateText ="批量更新时不可用!";
}
}
else//否
{
for (int j =0; j <= Gridview1.Rows.Count -1; j++)
{
//CheckBox cbox = (CheckBox)Gridview1.Rows[j].FindControl("mycheck");
CheckBox cbshow = (CheckBox)Gridview1.Rows[j].FindControl("cbshow");
CheckBox cbtuijian = (CheckBox)Gridview1.Rows[j].FindControl("cbtuijian");
CheckBox cbhit = (CheckBox)Gridview1.Rows[j].FindControl("cbhit");
CheckBox cbshowpiliang = (CheckBox)Gridview1.Rows[j].FindControl("cbshowpiliang");
CheckBox cbtuijianpiliang = (CheckBox)Gridview1.Rows[j].FindControl("cbtuijianpiliang");
CheckBox cbhitpiliang = (CheckBox)Gridview1.Rows[j].FindControl("cbhitpiliang");
ImageButton imgbtnup = (ImageButton)Gridview1.Rows[j].FindControl("imgbtnup");
ImageButton imgbtndown = (ImageButton)Gridview1.Rows[j].FindControl("imgbtndown");
ImageButton imgbtnupdatexuhao = (ImageButton)Gridview1.Rows[j].FindControl("imgbtnupdate");
ImageButton imgbtnupdatenum = (ImageButton)Gridview1.Rows[j].FindControl("imgbtnupdate1");
cbhit.Visible =true;
cbtuijian.Visible =true;
cbshow.Visible =true;
cbhitpiliang.Visible =false;
cbtuijianpiliang.Visible =false;
cbshowpiliang.Visible =false;
imgbtndown.Enabled =true;
imgbtnup.Enabled =true;
imgbtnupdatexuhao.Enabled =true;
imgbtnupdatenum.Enabled =true;
}
}
}
#endregion
#region 批量更新()
protectedvoid btnupdateall_Click(object sender, EventArgs e)
{
string piliangid = DropDownList1.SelectedValue.ToString();
switch (piliangid)
{
case"xuhao":
for (int i =0; i <= Gridview1.Rows.Count -1; i++)
{
TextBox tbxuhao = (TextBox)Gridview1.Rows[i].FindControl("tbxuhao");
HiddenField hdid = (HiddenField)Gridview1.Rows[i].FindControl("HiddenFieldid");
//该行的id
int id = Convert.ToInt32(hdid.Value);
int a = Common.update("[news]", "xuhao="+ Convert.ToInt32(Chars.FilteringStr(tbxuhao.Text.Trim())), "id="+ id);
}
MessageBox.Show(Page, "更新成功!");
bindreset();//重新绑定
break;
case"num":
for (int i =0; i <= Gridview1.Rows.Count -1; i++)
{
TextBox tbnum = (TextBox)Gridview1.Rows[i].FindControl("tbnum");
HiddenField hdid = (HiddenField)Gridview1.Rows[i].FindControl("HiddenFieldid");
//该行的id
int id = Convert.ToInt32(hdid.Value);
int a = Common.update("[news]", "num="+ Convert.ToInt32(Chars.FilteringStr(tbnum.Text.Trim())), "id="+ id);
}
MessageBox.Show(Page, "更新成功!");
bindreset();//重新绑定
break;
case"show":
for (int i =0; i <= Gridview1.Rows.Count -1; i++)
{
CheckBox cbshowpiliang = (CheckBox)Gridview1.Rows[i].FindControl("cbshowpiliang");
HiddenField hdid = (HiddenField)Gridview1.Rows[i].FindControl("HiddenFieldid");
int show =0;
if (cbshowpiliang.Checked ==true)
{
show =1;
}
//该行的id
int id = Convert.ToInt32(hdid.Value);
int a = Common.update("[news]", "show="+ show, "id="+ id);
}
MessageBox.Show(Page, "更新成功!");
bindreset();//重新绑定
break;
case"tuijian":
for (int i =0; i <= Gridview1.Rows.Count -1; i++)
{
CheckBox cbtuijianpiliang = (CheckBox)Gridview1.Rows[i].FindControl("cbtuijianpiliang");
HiddenField hdid = (HiddenField)Gridview1.Rows[i].FindControl("HiddenFieldid");
int tuijian =0;
if (cbtuijianpiliang.Checked ==true)
{
tuijian =1;
}
//该行的id
int id = Convert.ToInt32(hdid.Value);
int a = Common.update("[news]", "tuijian="+ tuijian, "id="+ id);
}
MessageBox.Show(Page, "更新成功!");
bindreset();//重新绑定
break;
case"hit":
for (int i =0; i <= Gridview1.Rows.Count -1; i++)
{
CheckBox cbhitpiliang = (CheckBox)Gridview1.Rows[i].FindControl("cbhitpiliang");
HiddenField hdid = (HiddenField)Gridview1.Rows[i].FindControl("HiddenFieldid");
int hit =0;
if (cbhitpiliang.Checked ==true)
{
hit =1;
}
//该行的id
int id = Convert.ToInt32(hdid.Value);
int a = Common.update("[news]", "hit="+ hit, "id="+ id);
}
MessageBox.Show(Page, "更新成功!");
bindreset();//重新绑定
break;
}
}
#endregion
#region 重新绑定
publicvoid bindreset()
{
//重新绑定
if (Request.Cookies["searchname"] ==null)
{
BindFeedbackDataSearch(null, null);
bindpiliang();
}
else
{
string searchname = Request.Cookies["searchname"].Value.ToString();
string searchname_s = Request.Cookies["searchname"].Value.ToString();
BindFeedbackDataSearch(searchname, searchname_s);
bindpiliang();
}
}
#endregion
#region 重新绑定 aspnet&&datasoure
publicvoid bindresetaspnet()
{
//重新绑定
if (Request.Cookies["searchname"] ==null)
{
BindFeedbackDataSearch(null, null);
BindAspNetPagerSearch(null, null);
bindpiliang();
}
else
{
string searchname = Request.Cookies["searchname"].Value.ToString();
string searchname_s = Request.Cookies["searchname"].Value.ToString();
BindFeedbackDataSearch(searchname, searchname_s);
BindAspNetPagerSearch(searchname, searchname_s);
bindpiliang();
}
}
#endregion
#region 更新是谁修改了内容(用户)
publicvoid updateuser()
{
}
#endregion
//public void updatepiliang(string sql)
//{
// for (int i = 0; i <= Gridview1.Rows.Count - 1; i++)
// {
// TextBox tbxuhao = (TextBox)Gridview1.Rows[i].FindControl("tbxuhao");
// int id = Convert.ToInt32(Convert.ToInt32(Gridview1.Rows[i].Cells[1].Text));
// }
//}
}
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SystemBll;
using SystemNewsBll;
using SystemChars;
publicpartialclass admin_News_NewsList : System.Web.UI.Page
{
BLL bll =new BLL();
//NewsBll nbll = new NewsBll();
protectedvoid Page_Load(object sender, EventArgs e)
{
btDelete.Attributes["onclick"] ="javascript:return confirm('是否确定删除?')";
//下面这行是自动换行
Gridview1.Attributes.Add("style", "word-break:break-all;word-wrap:break-word");
if (!Page.IsPostBack)
{
if (Request.Cookies["searchname"] !=null)
{
Response.Cookies["searchname"].Expires = DateTime.Now.AddDays(-1);
Response.Cookies["searchname_s"].Expires = DateTime.Now.AddDays(-1);
}
BindAspNetPagerSearch(null, null);
BindFeedbackDataSearch(null, null);
}
}
#region 数据绑定与翻页总数与翻页
//绑定精选内容翻页数
privatevoid BindAspNetPagerSearch(string search, string SearchName)
{
AspNetPager1.AlwaysShow =true;
AspNetPager1.PageSize =10;
AspNetPager1.RecordCount = NewsBll.CountSearch(search, SearchName);
}
//搜索精选内容
privatevoid BindFeedbackDataSearch(string search, string SearchName)
{
Gridview1.DataSource = NewsBll.GetMsgSearch(AspNetPager1, search, SearchName);
Gridview1.DataBind();
}
//翻页
protectedvoid AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
bindreset();//重新绑定
}
#endregion
#region 编辑修改 删除 搜索
//编辑
protectedvoid Gridview1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName =="View")
{
int a = Convert.ToInt32(e.CommandArgument.ToString());
Response.Redirect("NewsEdit.aspx?id="+ a);
}
}
//删除
protectedvoid btDelete_Click(object sender, EventArgs e)
{
if (Gridview1.Rows.Count !=0)
{
int Nresult =0;
for (int j =0; j <= Gridview1.Rows.Count -1; j++)
{
CheckBox cbox = (CheckBox)Gridview1.Rows[j].FindControl("mycheck");
if (cbox.Checked ==true)
{
Nresult =1;
}
}
if (Nresult ==0)
{
MessageBox.Show(Page, "请选择你要删除的内容");
}
else
{
int nResult =-1;
for (int i =0; i <= Gridview1.Rows.Count -1; i++)
{
CheckBox cbox = (CheckBox)Gridview1.Rows[i].FindControl("mycheck");
if (cbox.Checked ==true)
{
int id = Convert.ToInt32(Convert.ToInt32(Gridview1.Rows[i].Cells[1].Text));
Common.Deletesql("news", "id="+ id);
nResult =1;
}
}
if (nResult !=-1)
{
//重新绑定 aspnet
bindresetaspnet();
}
}
MessageBox.Show(Page, "删除数据成功!");
}
else
{
MessageBox.Show(Page, "没有可删除的数据!");
}
}
//搜索
protectedvoid btSearch_Click(object sender, EventArgs e)
{
if (txtSearch.Text ==""|| txtSearch.Text ==null)
{
MessageBox.Show(Page, "请输入搜索关键字!");
}
else
{
string search = txtSearch.Text.Trim();
string SearchName ="";
Response.Cookies["searchname"].Value = search;
Response.Cookies["searchname_s"].Value = SearchName;
BindAspNetPagerSearch(search, SearchName);
BindFeedbackDataSearch(search, SearchName);
}
}
#endregion
#region 选择 显示所有数据 特效
//特效
protectedvoid Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
{
int a = e.Row.Cells.Count;
//控制字符显示长度,若大于18个字符,显示前18个,后加"..." 只针对BoundField绑定的字段,其它无效
for (int i =0; i < e.Row.Cells.Count; i++)
{
if (e.Row.Cells[i].Text.Length >20)
{
e.Row.Cells[i].Text = e.Row.Cells[i].Text.Substring(0, 20) +"...";
}
}
//行背景色变
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标经过时,行背景色变
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
//鼠标移出时,行背景色变
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
}
//只能输入数字
TextBox tbxuhao = (TextBox)e.Row.FindControl("tbxuhao");
if (tbxuhao !=null)
{
tbxuhao.Attributes["onkeyup"] ="value=value.replace(/[^\\d]/g,'')";
}
TextBox tbnum = (TextBox)e.Row.FindControl("tbnum");
if (tbnum !=null)
{
tbnum.Attributes["onkeyup"] ="value=value.replace(/[^\\d]/g,'')";
}
for (int i =0; Gridview1.Rows.Count > i; i++)
{
//推荐
CheckBox cbtuijian = (CheckBox)Gridview1.Rows[i].FindControl("cbtuijian");
CheckBox cbtuijianpiliang = (CheckBox)Gridview1.Rows[i].FindControl("cbtuijianpiliang");
HiddenField hiddtuijian = (HiddenField)Gridview1.Rows[i].FindControl("HiddenFieldtuijian");
if (hiddtuijian.Value =="1")
{
cbtuijian.Checked =true;
cbtuijianpiliang.Checked =true;
}
//显示
CheckBox cbshow = (CheckBox)Gridview1.Rows[i].FindControl("cbshow");
CheckBox cbshowpiliang = (CheckBox)Gridview1.Rows[i].FindControl("cbshowpiliang");
HiddenField hiddshow = (HiddenField)Gridview1.Rows[i].FindControl("HiddenFieldshow");
if (hiddshow.Value =="1")
{
cbshow.Checked =true;
cbshowpiliang.Checked =true;
}
//热点
CheckBox cbhit = (CheckBox)Gridview1.Rows[i].FindControl("cbhit");
CheckBox cbhitpiliang = (CheckBox)Gridview1.Rows[i].FindControl("cbhitpiliang");
HiddenField hiddhit = (HiddenField)Gridview1.Rows[i].FindControl("HiddenFieldhit");
if (hiddhit.Value =="1")
{
cbhit.Checked =true;
cbhitpiliang.Checked =true;
}
}
}
//全选
protectedvoid chAll_CheckedChanged(object sender, EventArgs e)
{
if (Gridview1.Rows.Count !=0)
{
CheckBox chAll = (CheckBox)Gridview1.HeaderRow.FindControl("chAll");
for (int i =0; i <= Gridview1.Rows.Count -1; i++)
{
CheckBox cbox = (CheckBox)Gridview1.Rows[i].FindControl("mycheck");
if (chAll.Checked ==true)
{
cbox.Checked =true;
}
else
{
cbox.Checked =false;
}
}
}
else
{
MessageBox.Show(Page, "没有可选!");
}
}
//显示所有数据
protectedvoid btAllData_Click(object sender, EventArgs e)
{
Response.Cookies["searchname"].Expires = DateTime.Now.AddDays(-1);
Response.Cookies["searchname_s"].Expires = DateTime.Now.AddDays(-1);
BindAspNetPagerSearch(null, null);
BindFeedbackDataSearch(null, null);
}
#endregion 选择
#region button shijian
protectedvoid Button1_Click(object sender, EventArgs e)
{
Response.Redirect("NewsClassList.aspx");
}
protectedvoid Button2_Click(object sender, EventArgs e)
{
Response.Redirect("NewsAdd.aspx");
}
#endregion
#region 显示
protectedvoid changedshow(object sender, EventArgs e)
{
GridViewRow row = ((CheckBox)sender).Parent.Parent as GridViewRow;
HiddenField hdshow = (HiddenField)(row.FindControl("HiddenFieldshow"));
HiddenField hdid = (HiddenField)(row.FindControl("HiddenFieldid"));
if (hdshow.Value =="1")
{
int count = Common.update("news", "show=0", "id="+int.Parse(hdid.Value));
if (count >0)
{
MessageBox.Show(Page, "修改成功!");
bindreset();//重新绑定
}
}
else
{
int count = Common.update("news", "show=1", "id="+int.Parse(hdid.Value));
if (count >0)
{
MessageBox.Show(Page, "修改成功!");
bindreset();//重新绑定
}
}
}
#endregion
#region 推荐
protectedvoid changedtuijian(object sender, EventArgs e)
{
GridViewRow row = ((CheckBox)sender).Parent.Parent as GridViewRow;
HiddenField hdtuijian = (HiddenField)(row.FindControl("HiddenFieldtuijian"));
HiddenField hdid = (HiddenField)(row.FindControl("HiddenFieldid"));
if (hdtuijian.Value =="1")
{
int count = Common.update("news", "tuijian=0", "id="+int.Parse(hdid.Value));
if (count >0)
{
MessageBox.Show(Page, "修改成功!");
//重新绑定
bindreset();//重新绑定
}
}
else
{
int count = Common.update("news", "tuijian=1", "id="+int.Parse(hdid.Value));
if (count >0)
{
MessageBox.Show(Page, "修改成功!");
//重新绑定
bindreset();//重新绑定
}
}
}
#endregion
#region 热点
protectedvoid changedhit(object sender, EventArgs e)
{
GridViewRow row = ((CheckBox)sender).Parent.Parent as GridViewRow;
HiddenField hdhit = (HiddenField)(row.FindControl("HiddenFieldhit"));
HiddenField hdid = (HiddenField)(row.FindControl("HiddenFieldid"));
if (hdhit.Value =="1")
{
int count = Common.update("news", "hit=0", "id="+int.Parse(hdid.Value));
if (count >0)
{
MessageBox.Show(Page, "修改成功!");
//重新绑定
bindreset();//重新绑定
}
}
else
{
int count = Common.update("news", "hit=1", "id="+int.Parse(hdid.Value));
if (count >0)
{
MessageBox.Show(Page, "修改成功!");
//重新绑定
bindreset();//重新绑定
}
}
}
#endregion
#region 排序升一位也就是减一
protectedvoid upxuhao(object sender, EventArgs e)
{
GridViewRow row = ((ImageButton)sender).Parent.Parent as GridViewRow;
HiddenField hdxuhao = (HiddenField)(row.FindControl("HiddenFieldxuhao"));
HiddenField hdid = (HiddenField)(row.FindControl("HiddenFieldid"));
if (hdxuhao.Value !="0")
{
int count = Common.update("[news]", "xuhao=xuhao-1", "id="+int.Parse(hdid.Value));
if (count >0)
{
MessageBox.Show(Page, "修改成功!");
bindreset();//重新绑定
}
}
else
{
MessageBox.Show(Page, "序号已是最高位置了!");
}
}
#endregion
#region 排序下一位也就是加1
protectedvoid downxuhao(object sender, EventArgs e)
{
GridViewRow row = ((ImageButton)sender).Parent.Parent as GridViewRow;
HiddenField hdxuhao = (HiddenField)(row.FindControl("HiddenFieldxuhao"));
HiddenField hdid = (HiddenField)(row.FindControl("HiddenFieldid"));
int count = Common.update("[news]", "xuhao=xuhao+1", "id="+int.Parse(hdid.Value));
if (count >0)
{
MessageBox.Show(Page, "修改成功!");
bindreset();//重新绑定
}
}
#endregion
#region 更新序号
protectedvoid updatexuhao(object sender, EventArgs e)
{
GridViewRow row = ((ImageButton)sender).Parent.Parent as GridViewRow;
HiddenField hdxuhao = (HiddenField)(row.FindControl("HiddenFieldxuhao"));
TextBox tbxuhao = (TextBox)(row.FindControl("tbxuhao"));
HiddenField hdid = (HiddenField)(row.FindControl("HiddenFieldid"));
//过滤特殊字符再转int型
int xuhao = Convert.ToInt32(Chars.FilteringStr(tbxuhao.Text.Trim()));
//更新
int count = Common.update("[news]", "xuhao="+ xuhao, "id="+int.Parse(hdid.Value));
if (count >0)
{
MessageBox.Show(Page, "修改成功!");
bindreset();//重新绑定
}
}
#endregion
#region 更新阅读数
protectedvoid updatenum(object sender, EventArgs e)
{
GridViewRow row = ((ImageButton)sender).Parent.Parent as GridViewRow;
HiddenField hdnum = (HiddenField)(row.FindControl("HiddenFieldnum"));
TextBox tbnum = (TextBox)(row.FindControl("tbnum"));
HiddenField hdid = (HiddenField)(row.FindControl("HiddenFieldid"));
//过滤特殊字符再转int型
int num = Convert.ToInt32(Chars.FilteringStr(tbnum.Text.Trim()));
//更新
int count = Common.update("[news]", "num="+ num, "id="+int.Parse(hdid.Value));
if (count >0)
{
MessageBox.Show(Page, "修改成功!");
bindreset();//重新绑定
}
}
#endregion
#region 是否批量更新
protectedvoid cbpiliang_changed(object sender, EventArgs e)
{
bindpiliang();
}
publicvoid bindpiliang()
{
//批量是
if (cbpiliang.Checked ==true)
{
for (int j =0; j <= Gridview1.Rows.Count -1; j++)
{
// CheckBox cbox = (CheckBox)Gridview1.Rows[j].FindControl("mycheck");
CheckBox cbshow = (CheckBox)Gridview1.Rows[j].FindControl("cbshow");
CheckBox cbtuijian = (CheckBox)Gridview1.Rows[j].FindControl("cbtuijian");
CheckBox cbhit = (CheckBox)Gridview1.Rows[j].FindControl("cbhit");
CheckBox cbshowpiliang = (CheckBox)Gridview1.Rows[j].FindControl("cbshowpiliang");
CheckBox cbtuijianpiliang = (CheckBox)Gridview1.Rows[j].FindControl("cbtuijianpiliang");
CheckBox cbhitpiliang = (CheckBox)Gridview1.Rows[j].FindControl("cbhitpiliang");
ImageButton imgbtnup = (ImageButton)Gridview1.Rows[j].FindControl("imgbtnup");
ImageButton imgbtndown = (ImageButton)Gridview1.Rows[j].FindControl("imgbtndown");
ImageButton imgbtnupdatexuhao = (ImageButton)Gridview1.Rows[j].FindControl("imgbtnupdate");
ImageButton imgbtnupdatenum = (ImageButton)Gridview1.Rows[j].FindControl("imgbtnupdate1");
//因为此都有触发事件
cbhit.Visible =false;
cbtuijian.Visible =false;
cbshow.Visible =false;
cbhitpiliang.Visible =true;
cbtuijianpiliang.Visible =true;
cbshowpiliang.Visible =true;
imgbtndown.Enabled =false;
imgbtnup.Enabled =false;
imgbtnupdatexuhao.Enabled =false;
imgbtnupdatenum.Enabled =false;
imgbtnupdatenum.AlternateText ="批量更新时不可用!";
imgbtnupdatexuhao.AlternateText ="批量更新时不可用!";
imgbtnup.AlternateText ="批量更新时不可用!";
imgbtndown.AlternateText ="批量更新时不可用!";
}
}
else//否
{
for (int j =0; j <= Gridview1.Rows.Count -1; j++)
{
//CheckBox cbox = (CheckBox)Gridview1.Rows[j].FindControl("mycheck");
CheckBox cbshow = (CheckBox)Gridview1.Rows[j].FindControl("cbshow");
CheckBox cbtuijian = (CheckBox)Gridview1.Rows[j].FindControl("cbtuijian");
CheckBox cbhit = (CheckBox)Gridview1.Rows[j].FindControl("cbhit");
CheckBox cbshowpiliang = (CheckBox)Gridview1.Rows[j].FindControl("cbshowpiliang");
CheckBox cbtuijianpiliang = (CheckBox)Gridview1.Rows[j].FindControl("cbtuijianpiliang");
CheckBox cbhitpiliang = (CheckBox)Gridview1.Rows[j].FindControl("cbhitpiliang");
ImageButton imgbtnup = (ImageButton)Gridview1.Rows[j].FindControl("imgbtnup");
ImageButton imgbtndown = (ImageButton)Gridview1.Rows[j].FindControl("imgbtndown");
ImageButton imgbtnupdatexuhao = (ImageButton)Gridview1.Rows[j].FindControl("imgbtnupdate");
ImageButton imgbtnupdatenum = (ImageButton)Gridview1.Rows[j].FindControl("imgbtnupdate1");
cbhit.Visible =true;
cbtuijian.Visible =true;
cbshow.Visible =true;
cbhitpiliang.Visible =false;
cbtuijianpiliang.Visible =false;
cbshowpiliang.Visible =false;
imgbtndown.Enabled =true;
imgbtnup.Enabled =true;
imgbtnupdatexuhao.Enabled =true;
imgbtnupdatenum.Enabled =true;
}
}
}
#endregion
#region 批量更新()
protectedvoid btnupdateall_Click(object sender, EventArgs e)
{
string piliangid = DropDownList1.SelectedValue.ToString();
switch (piliangid)
{
case"xuhao":
for (int i =0; i <= Gridview1.Rows.Count -1; i++)
{
TextBox tbxuhao = (TextBox)Gridview1.Rows[i].FindControl("tbxuhao");
HiddenField hdid = (HiddenField)Gridview1.Rows[i].FindControl("HiddenFieldid");
//该行的id
int id = Convert.ToInt32(hdid.Value);
int a = Common.update("[news]", "xuhao="+ Convert.ToInt32(Chars.FilteringStr(tbxuhao.Text.Trim())), "id="+ id);
}
MessageBox.Show(Page, "更新成功!");
bindreset();//重新绑定
break;
case"num":
for (int i =0; i <= Gridview1.Rows.Count -1; i++)
{
TextBox tbnum = (TextBox)Gridview1.Rows[i].FindControl("tbnum");
HiddenField hdid = (HiddenField)Gridview1.Rows[i].FindControl("HiddenFieldid");
//该行的id
int id = Convert.ToInt32(hdid.Value);
int a = Common.update("[news]", "num="+ Convert.ToInt32(Chars.FilteringStr(tbnum.Text.Trim())), "id="+ id);
}
MessageBox.Show(Page, "更新成功!");
bindreset();//重新绑定
break;
case"show":
for (int i =0; i <= Gridview1.Rows.Count -1; i++)
{
CheckBox cbshowpiliang = (CheckBox)Gridview1.Rows[i].FindControl("cbshowpiliang");
HiddenField hdid = (HiddenField)Gridview1.Rows[i].FindControl("HiddenFieldid");
int show =0;
if (cbshowpiliang.Checked ==true)
{
show =1;
}
//该行的id
int id = Convert.ToInt32(hdid.Value);
int a = Common.update("[news]", "show="+ show, "id="+ id);
}
MessageBox.Show(Page, "更新成功!");
bindreset();//重新绑定
break;
case"tuijian":
for (int i =0; i <= Gridview1.Rows.Count -1; i++)
{
CheckBox cbtuijianpiliang = (CheckBox)Gridview1.Rows[i].FindControl("cbtuijianpiliang");
HiddenField hdid = (HiddenField)Gridview1.Rows[i].FindControl("HiddenFieldid");
int tuijian =0;
if (cbtuijianpiliang.Checked ==true)
{
tuijian =1;
}
//该行的id
int id = Convert.ToInt32(hdid.Value);
int a = Common.update("[news]", "tuijian="+ tuijian, "id="+ id);
}
MessageBox.Show(Page, "更新成功!");
bindreset();//重新绑定
break;
case"hit":
for (int i =0; i <= Gridview1.Rows.Count -1; i++)
{
CheckBox cbhitpiliang = (CheckBox)Gridview1.Rows[i].FindControl("cbhitpiliang");
HiddenField hdid = (HiddenField)Gridview1.Rows[i].FindControl("HiddenFieldid");
int hit =0;
if (cbhitpiliang.Checked ==true)
{
hit =1;
}
//该行的id
int id = Convert.ToInt32(hdid.Value);
int a = Common.update("[news]", "hit="+ hit, "id="+ id);
}
MessageBox.Show(Page, "更新成功!");
bindreset();//重新绑定
break;
}
}
#endregion
#region 重新绑定
publicvoid bindreset()
{
//重新绑定
if (Request.Cookies["searchname"] ==null)
{
BindFeedbackDataSearch(null, null);
bindpiliang();
}
else
{
string searchname = Request.Cookies["searchname"].Value.ToString();
string searchname_s = Request.Cookies["searchname"].Value.ToString();
BindFeedbackDataSearch(searchname, searchname_s);
bindpiliang();
}
}
#endregion
#region 重新绑定 aspnet&&datasoure
publicvoid bindresetaspnet()
{
//重新绑定
if (Request.Cookies["searchname"] ==null)
{
BindFeedbackDataSearch(null, null);
BindAspNetPagerSearch(null, null);
bindpiliang();
}
else
{
string searchname = Request.Cookies["searchname"].Value.ToString();
string searchname_s = Request.Cookies["searchname"].Value.ToString();
BindFeedbackDataSearch(searchname, searchname_s);
BindAspNetPagerSearch(searchname, searchname_s);
bindpiliang();
}
}
#endregion
#region 更新是谁修改了内容(用户)
publicvoid updateuser()
{
}
#endregion
//public void updatepiliang(string sql)
//{
// for (int i = 0; i <= Gridview1.Rows.Count - 1; i++)
// {
// TextBox tbxuhao = (TextBox)Gridview1.Rows[i].FindControl("tbxuhao");
// int id = Convert.ToInt32(Convert.ToInt32(Gridview1.Rows[i].Cells[1].Text));
// }
//}
}