對(duì)GridView的行加顏色并彈出Kindeditor的實(shí)現(xiàn)思路
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript">
function tureDelete() {
if (confirm('真的要?jiǎng)h除嗎?') == false)
{ return false;}
}
function showdiv()
{
document.getElementByIdx_x("show1").style.display = "block";
document.getElementByIdx_x("showDiv").style.display = "block";
}
</script>
<link rel="stylesheet" href="Kindeditor/themes/default/default.css" />
<link rel="stylesheet" href="Kindeditor/plugins/code/prettify.css" />
<script charset="utf-8" src="Kindeditor/kindeditor.js"></script>
<script charset="utf-8" src="Kindeditor/lang/zh_CN.js"></script>
<script charset="utf-8" src="Kindeditor/plugins/code/prettify.js"></script>
<script>
KindEditor.ready(function (K) {
var editor1 = K.create('#content1', {
cssPath: 'Kindeditor/plugins/code/prettify.css',
uploadJson: 'Kindeditor/asp.net/upload_json.ashx',
fileManagerJson: 'Kindeditor/asp.net/file_manager_json.ashx',
allowFileManager: true,
afterCreate: function () {
var self = this;
K.ctrl(document, 13, function () {
self.sync();
K('form[name=example]')[0].submit();
});
K.ctrl(self.edit.doc, 13, function () {
self.sync();
K('form[name=example]')[0].submit();
});
}
});
prettyPrint();
});
</script>
<style type="text/css">
#showDiv {
position:absolute;
top:50%;
left:50%;
margin-left:-350px;
margin-top:-250px;
}
</style>
</head>
<body>
<asp:Label ID="Label1" runat="server" Visible="false" Text=""></asp:Label>
<form id="form1" runat="server">
<div id="show1" style="display:none;background-color: Black;position:absolute; width:100%;height:100%;top:0px;left:0px; opacity:0.3;"></div>
<div id="showDiv" style="display:none;background-color:bisque;">
<table>
<tr>
<td>
標(biāo)題
</td>
<td>
<asp:TextBox ID="txtTitle" runat="server" Width="250px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
內(nèi)容
</td>
<td>
<textarea id="content1" cols="100" rows="8" style="width:700px;height:500px;visibility:hidden;" runat="server"></textarea>
</td>
</tr>
<tr>
<td>
類別
</td>
<td>
<asp:DropDownList ID="ddlClassName" runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
用戶
</td>
<td>
<asp:DropDownList ID="ddlUser" runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:Button ID="btnUpdate" runat="server" Text="保存" />
</td>
</tr>
</table>
</div>
<div >
<table>
<tr>
<td>
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" OnSorting="GridView1_Sorting" OnRowDataBound="GridView1_RowDataBound" ShowFooter="True">
<Columns>
<asp:TemplateField HeaderText="選擇">
<ItemTemplate>
<asp:CheckBox ID="ck1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="標(biāo)題">
<ItemTemplate>
<a href='WebForm1.aspx?id=<%#eval_r("Id") %>'><%#eval_r("NewsTitle") %></a>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="NewsContent" HeaderText="內(nèi)容" />
<asp:BoundField DataField="RealName" HeaderText="創(chuàng)建者" SortExpression="RealName" />
<asp:BoundField DataField="CreateTime" DataFormatString="{0:yyyy-mm-dd hh:mm:ss}" HeaderText="創(chuàng)建時(shí)間" SortExpression="CreateTime" />
<asp:BoundField DataField="ClassName" HeaderText="類型" />
<asp:TemplateField HeaderText="操作">
<ItemTemplate>
<asp:LinkButton ID="linkbtnEdit" CommandArgument='<%# eval_r("Id") %>' runat="server">編輯</asp:LinkButton>
<asp:LinkButton ID="linkDelete" CommandArgument='<%# eval_r("Id") %>' runat="server">刪除</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
<tr>
<td>
<asp:LinkButton ID="lbtnFirst" runat="server" OnClick="lbtnFirst_Click">第一頁(yè)</asp:LinkButton>
<asp:LinkButton ID="lbtnProc" runat="server" OnClick="lbtnProc_Click">上一頁(yè)</asp:LinkButton>
<asp:LinkButton ID="lbtnNext" runat="server" OnClick="lbtnNext_Click">下一頁(yè)</asp:LinkButton>
<asp:LinkButton ID="lbtnLast" runat="server" OnClick="lbtnLast_Click">最后一頁(yè)</asp:LinkButton>
<asp:Button ID="Button1" runat="server" Text="刪除" OnClick="Button1_Click" OnClientClick="return tureDelete()" />
<asp:Button ID="Button2" runat="server" Text="彈出層" OnClick="Button2_Click1" />
</td>
</tr>
</table>
</div>
</form>
</body>
后臺(tái)代碼:
public partial class GridView : System.Web.UI.Page
{
string constr = "data source=.;initial catalog=News;user id=sa;password=111111;";
string sql = "select T1.Id,T1.NewsTitle,SUBSTRING(T1.NewsContent,0,20) as NewsContent,T2.RealName,T1.CreateTime,T3.ClassName from (select ROW_NUMBER() over (order by Id) as rownumber,* from T_News) T1 left join T_User T2 on T1.NewsCreator=T2.UserId left join T_NewsClass T3 on T1.ClassId=T3.ClassId where rownumber>(@pageIndex-1)*@pageSize and rownumber<=@pageIndex*@pageSize";
int count;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["pageIndex"] = 1;
DataPage(sql);
}
}
private void DataPage(string sql)
{
SqlConnection conn = new SqlConnection(constr);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
// string sql = "select T1.Id,T1.NewsTitle,SUBSTRING(T1.NewsContent,0,20) as NewsContent,T2.RealName ,T1.CreateTime,T3.ClassName from T_News1 T1 join T_User T2 on T1.NewsCreator=T2.UserId join T_NewsClass T3 on T1.ClassId=T3.ClassId";
cmd.Parameters.AddWithValue("@pageSize", 10);
cmd.Parameters.AddWithValue("@pageIndex", Convert.ToInt32(ViewState["pageIndex"]));
cmd.CommandText = sql;
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
string sql1 = "select count(*) from T_News";
cmd.CommandText = sql1;
int i =Convert.ToInt32(cmd.ExecuteScalar());
if (i % 10 == 0)
{
ViewState["pageCount"] = i / 10;
}
else
{ ViewState["pageCount"] = i / 10+1; }
conn.Close();
conn.Dispose();
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void lbtnFirst_Click(object sender, EventArgs e)
{
ViewState["pageIndex"] = 1;
DataPage(sql);
}
protected void lbtnProc_Click(object sender, EventArgs e)
{
int i=Convert.ToInt32(ViewState["pageIndex"]) ;
if (i>1)
{
i--;
ViewState["pageIndex"] = i;
DataPage(sql);
}
}
protected void lbtnNext_Click(object sender, EventArgs e)
{
int i = Convert.ToInt32(ViewState["pageIndex"]);
if (i <Convert.ToInt32(ViewState["pageCount"]))
{
i++;
ViewState["pageIndex"] = i;
DataPage(sql);
}
}
protected void lbtnLast_Click(object sender, EventArgs e)
{
ViewState["pageIndex"] = ViewState["pageCount"];
DataPage(sql);
}
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
if (ViewState["sortExp"] == null)
{
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add(e.SortExpression, "ASC");
ViewState["sortExp"] = dic;
sql += " Order by " + e.SortExpression + " " + dic[e.SortExpression];
DataPage(sql);
}
else
{
//判斷用戶本次點(diǎn)擊的排序字段是否和上次點(diǎn)擊的排序字段一致,如果一致的話,那么就更改此字段的排序規(guī)則,如果不是就清除上次的排序字段,添加新的排序字段和規(guī)則(這是根據(jù)一個(gè)字段排序的情況)
Dictionary<string, string> dic = ViewState["sortExp"] as Dictionary<string, string>;
if (dic.ContainsKey(e.SortExpression))
{
if (dic[e.SortExpression] == "ASC")
{
dic[e.SortExpression] = "DESC";
}
else
{
dic[e.SortExpression] = "ASC";
}
}
else//如果不包含的話就生新創(chuàng)建一個(gè)
{
//dic.Clear();
dic.Add(e.SortExpression, "ASC");
}
sql +=" Order by "+ e.SortExpression + " " + dic[e.SortExpression];
DataPage(sql);
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
if (e.Row.Cells[i].Controls.Count > 0)
{
LinkButton link = e.Row.Cells[i].Controls[0] as LinkButton;
string sortexp = link.CommandArgument;
if (ViewState["sortExp"] != null)
{
Dictionary<string, string> dic = ViewState["sortExp"] as Dictionary<string, string>;
if (dic.ContainsKey(sortexp))
{
Literal li = new Literal();
if (dic[sortexp] == "ASC")
{
li.Text = "↑";
}
else
{
li.Text = "↓";
}
e.Row.Cells[i].Controls.Add(li);
}
}
}
}
}
//按條件給gridview的行加背景顏色
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[3].Text == "肖唯哲")
{
e.Row.BackColor = Color.Red;
//根據(jù)條件統(tǒng)計(jì)當(dāng)前頁(yè)的記錄數(shù)
count++;
}
}
if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells.RemoveAt(6);
e.Row.Cells.RemoveAt(5);
e.Row.Cells.RemoveAt(4);
e.Row.Cells.RemoveAt(3);
e.Row.Cells.RemoveAt(2);
e.Row.Cells.RemoveAt(1);
e.Row.Cells[0].ColumnSpan = 8;
e.Row.Cells[0].HorizontalAlign = HorizontalAlign.Right;
e.Row.Cells[0].Text = string.Format("肖唯哲:{0}", count);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string sqlid = string.Empty;
foreach (GridViewRow row in this.GridView1.Rows)
{
CheckBox ck1=row.Cells[0].FindControl("ck1") as CheckBox;
if (ck1.Checked == true)
{
LinkButton link=row.Cells[6].FindControl("linkbtnEdit") as LinkButton;
sqlid +=" "+link.CommandArgument + " ,";
}
}
string sql1 = "delete from T_News where Id in (" + sqlid.TrimEnd(',')+")";
int i= DeleteDatas(sql1);
if (i > 0)
{
ClientScript.RegisterStartupScript(this.GetType(), "key", "alert('刪除成功!')", true);
DataPage(sql);
}
}
private int DeleteDatas(string sql1)
{
SqlConnection conn = new SqlConnection(constr);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = sql1;
int num = Convert.ToInt32(cmd.ExecuteNonQuery());
return num;
conn.Dispose();
}
protected void Button2_Click1(object sender, EventArgs e)
{
//Response.Write("<script type='text/javascript'>showdiv()</script>");
ClientScript.RegisterStartupScript(this.GetType(), "key", "showdiv()", true);
}
}
- kindeditor編輯器點(diǎn)中圖片滾動(dòng)條往上頂?shù)腷ug
- kindeditor修復(fù)會(huì)替換script內(nèi)容的問(wèn)題
- nodejs 整合kindEditor實(shí)現(xiàn)圖片上傳
- Angularjs編寫KindEditor,UEidtor,jQuery指令
- dotnet封裝的kindeditor編輯器控件
- jQuery讀取和設(shè)定KindEditor值的方法
- KindEditor圖片上傳的Asp.net代碼實(shí)例
- ASP.NET網(wǎng)站使用Kindeditor富文本編輯器配置步驟
- jQuery編輯器KindEditor4.1.4代碼高亮顯示設(shè)置教程
- 使用JavaScript為Kindeditor自定義按鈕增加Audio標(biāo)簽
相關(guān)文章
.Net平臺(tái)開發(fā)實(shí)踐的一些點(diǎn)滴總結(jié)(技術(shù)規(guī)范與實(shí)踐精華)
以下是本人對(duì).Net平臺(tái)開發(fā)實(shí)踐的一些點(diǎn)滴總結(jié)。這里的技術(shù)規(guī)范主要是開發(fā)過(guò)程的代碼規(guī)范、數(shù)據(jù)庫(kù)設(shè)計(jì)規(guī)范、Com和.Net互操作規(guī)范;實(shí)踐精華是對(duì)技術(shù)實(shí)踐過(guò)程中的部分總結(jié)。2010-04-04
ASP.NET State service狀態(tài)服務(wù)的問(wèn)題解決方法
每次重啟機(jī)器以后,在.NET2005上跑Web程序老是遇到這樣的問(wèn)題2008-11-11
ASP.NET使用AjaxPro實(shí)現(xiàn)前端跟后臺(tái)交互詳解
這篇文章主要為大家詳細(xì)介紹了ASP.NET使用AjaxPro實(shí)現(xiàn)前端跟后臺(tái)交互,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07
Silverlight4 多語(yǔ)言實(shí)現(xiàn)的方法
這篇文章介紹了Silverlight4 多語(yǔ)言實(shí)現(xiàn)的方法,有需要的朋友可以參考一下2013-10-10
.Net通過(guò)TaskFactory.FromAsync簡(jiǎn)化APM
這篇文章介紹了.Net通過(guò)TaskFactory.FromAsync簡(jiǎn)化APM的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-06-06
用ASP.NET做的個(gè)性化的郵件發(fā)送系統(tǒng)
如果要你用ASP來(lái)做一個(gè)郵件發(fā)送系統(tǒng),你一定認(rèn)為這是一個(gè)比較復(fù)雜的工作。其實(shí)也的確是這樣。但當(dāng)他的后繼產(chǎn)品ASP.NET被推出以后,他的強(qiáng)大功能就使的這一切就變的相對(duì)簡(jiǎn)單了。真的這樣神奇么?我們就通過(guò)ASP.NET做一個(gè)郵件發(fā)送系統(tǒng),看看到底有什么奧秘,是不是真的簡(jiǎn)單。2008-02-02
Asp.Net其他頁(yè)面如何調(diào)用Web用戶控件寫的分頁(yè)
這篇文章主要介紹了Asp.Net其他頁(yè)面如何調(diào)用Web用戶控件寫的分頁(yè),需要的朋友可以參考下2014-05-05
如何為asp.net網(wǎng)站項(xiàng)目添加子項(xiàng)目
最近要給公司的電子商務(wù)網(wǎng)站添加個(gè)圈子的功能.網(wǎng)站功能本來(lái)就包含有新聞發(fā)布,會(huì)員管理,商品購(gòu)物,后臺(tái)管理等,現(xiàn)在又要再加上圈子的功能,網(wǎng)站項(xiàng)目越來(lái)越復(fù)雜,每次編譯生成的dll超過(guò)100k.這樣每次修改任何一個(gè)功能中的任何一個(gè)小問(wèn)題都要上傳整個(gè)dll,并導(dǎo)致整個(gè)website的首次訪問(wèn)的重新編譯.2008-10-10
1個(gè)文件如何輕松搞定Asp.net core 3.1動(dòng)態(tài)頁(yè)面轉(zhuǎn)靜態(tài)頁(yè)面
這篇文章主要給大家介紹了關(guān)于如何通過(guò)1個(gè)文件輕松搞定Asp.net core 3.1動(dòng)態(tài)頁(yè)面轉(zhuǎn)靜態(tài)頁(yè)面的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Asp.net core 3.1具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05

