DataGrid实现增删(带提示)改和分页

<% @Pagelanguage = " c# " Codebehind = " WebForm5.aspx.cs " AutoEventWireup = " false " Inherits = " csdn.WebForm5 " %>
<! DOCTYPEHTMLPUBLIC " -//W3C//DTDHTML4.0Transitional//EN " >
< HTML >
< HEAD >
< title > WebForm5 </ title >
< metacontent = " MicrosoftVisualStudio.NET7.1 " name = " GENERATOR " >
< metacontent = " C# " name = " CODE_LANGUAGE " >
< metacontent = " JavaScript " name = " vs_defaultClientScript " >
< metacontent = " http://schemas.microsoft.com/intellisense/ie5 " name = " vs_targetSchema " >
</ HEAD >
< body >
< formid = " Form1 " method = " post " runat = " server " >
< inputtype = " hidden " id = " rd " runat = " server " name = " rd " >
< asp:textboxid = " TextBox1 " runat = " server " Width = " 88px " ></ asp:textbox >
< asp:TextBoxid = " TextBox2 " runat = " server " Width = " 40px " ></ asp:TextBox >
< asp:Buttonid = " Button1 " runat = " server " Text = " 添加 " ></ asp:Button >
< asp:TextBoxid = " TextBox3 " runat = " server " Width = " 128px " ></ asp:TextBox >
< asp:Buttonid = " Button2 " runat = " server " Text = " 筛选 " ></ asp:Button >
< asp:Buttonid = " Button3 " runat = " server " Text = " 下载 " ></ asp:Button >
< asp:DataGridID = " DataGrid1 " runat = " server " AutoGenerateColumns = " False " DataKeyField = " ID " AllowPaging = " True "
PageSize
= " 20 " OnEditCommand = " edit " OnCancelCommand = " cancel " OnUpdateCommand = " update " >
< columns >
< asp:TemplateColumnHeaderText = " 多选 " >
< itemtemplate >
< inputtype = " hidden " id = " SelectedID " runat = " server "
value
= ' <%#Container.ItemIndex%> ' name = " SelectedID " />
< asp:CheckBoxID = " chkExport " runat = " server " />
</ itemtemplate >
</ asp:TemplateColumn >
< asp:TemplateColumnHeaderText = " 单选 " >
< itemtemplate >
<% #Container.ItemIndex + 1 %>
< inputtype = radioname = " rad " value = ' <%#Container.ItemIndex+1%> ' >
</ itemtemplate >
</ asp:TemplateColumn >
< asp:TemplateColumnHeaderText = " 姓名 " >
< itemtemplate >
<% #myfunc(DataBinder.Eval(Container.DataItem, " vName " )) %>
</ itemtemplate >
< edititemtemplate >
< asp:TextBoxID = " name " runat = " server " Text = ' <%#DataBinder.Eval(Container.DataItem,"vName")%> ' Width = " 88px " > </ asp:TextBox >
</ edititemtemplate >
</ asp:TemplateColumn >
< asp:TemplateColumnHeaderText = " 年龄 " >
< itemtemplate >
<% #DataBinder.Eval(Container.DataItem, " iAge " ) %>
</ itemtemplate >
< edititemtemplate >
< asp:TextBoxID = " age " runat = " server " Text = ' <%#DataBinder.Eval(Container.DataItem,"iAge")%> ' Width = " 40px " > </ asp:TextBox >
</ edititemtemplate >
</ asp:TemplateColumn >
< asp:TemplateColumnHeaderText = " 打开 " >
< itemtemplate >
< asp:HyperLinkText = " 打开 " NavigateUrl = ' <%#"newpage.aspx?name="+DataBinder.Eval(Container.DataItem,"vname")+"&age="+DataBinder.Eval(Container.DataItem,"iage")%> ' runat = " server " Target = " _blank " > </ asp:HyperLink >
</ itemtemplate >
</ asp:TemplateColumn >
< asp:TemplateColumnHeaderText = " 打开 " >
< itemtemplate >
< asp:HyperLinkText = " 打开 " NavigateUrl = ' <%#myfunc2(DataBinder.Eval(Container.DataItem,"vName"),DataBinder.Eval(Container.DataItem,"iAge"))%> ' runat = " server " Target = " _blank " ID = " Hyperlink1 " > </ asp:HyperLink >
</ itemtemplate >
</ asp:TemplateColumn >
< asp:EditCommandColumnButtonType = " LinkButton " UpdateText = " 更新 " CancelText = " 取消 " EditText = " 编辑 " ></ asp:EditCommandColumn >
< asp:ButtonColumnText = " 删除 " CommandName = " del " ></ asp:ButtonColumn >
</ columns >
< pagerstyleMode = " NumericPages " ></ pagerstyle >
</ asp:DataGrid >
< asp:Labelid = " Label1 " runat = " server " ></ asp:Label >
< asp:ButtonID = " button4 " runat = " server " Text = " 单选结果 " ></ asp:Button >
< asp:Buttonid = " Button5 " runat = " server " Text = " 多选结果 " ></ asp:Button >
< asp:Buttonid = " Button6 " runat = " server " Text = " 选中所有 " ></ asp:Button >
< asp:Buttonid = " Button7 " runat = " server " Text = " 取消所有 " ></ asp:Button ></ form >
< p >& nbsp; </ p >
< p >& nbsp; </ p >
</ body >
</ HTML >
后台代码:
// C#Document
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls; using System.IO;

namespace csdn
{
/**//**//**////<summary>
///WebForm5的摘要说明。
///</summary>

publicclassWebForm5:System.Web.UI.Page
{
protectedSystem.Web.UI.WebControls.TextBoxTextBox1;
protectedSystem.Web.UI.WebControls.TextBoxTextBox2;
protectedSystem.Web.UI.WebControls.ButtonButton1;
protectedSystem.Web.UI.WebControls.TextBoxTextBox3;
protectedSystem.Web.UI.WebControls.ButtonButton2;
protectedSystem.Web.UI.WebControls.ButtonButton3;
protectedSystem.Web.UI.WebControls.LabelLabel1;
protectedSystem.Web.UI.HtmlControls.HtmlInputHiddenrd;
protectedSystem.Web.UI.WebControls.Buttonbutton4;
protectedSystem.Web.UI.WebControls.ButtonButton5;
protectedSystem.Web.UI.WebControls.ButtonButton6;
protectedSystem.Web.UI.WebControls.DataGridDataGrid1;
protectedSystem.Web.UI.WebControls.ButtonButton7;

privatevoidPage_Load(objectsender,System.EventArgse)
{

stringjs="";
js
+="<script>\r\n";
js
+="functionld(){\r\n";
js
+="for(i=0;i<document.getElementsByName('rad').length;i++)\r\n";
js
+="if(document.getElementsByName('rad')[i].value==";
js
+="document.getElementById('rd').value)";
js
+="document.getElementsByName('rad')[i].checked=true\r\n";
js
+="}\r\n";
js
+="window.onload=ld\r\n";
js
+="</script>\r\n";
this.RegisterClientScriptBlock("js",js);

if(!IsPostBack)
{
SetBind();
}


}


protectedvoidSetBind()
{

SqlConnectionconn
=newSqlConnection(System.Configuration.ConfigurationSettings.AppSettings["conn"]);
SqlDataAdapterda
=newSqlDataAdapter("select*fromtb1",conn);
DataSetds
=newDataSet();
da.Fill(ds,
"table1");
this.DataGrid1.DataSource=ds.Tables["table1"];
this.DataGrid1.DataBind();
this.Label1.Text=ds.Tables["table1"].Compute("avg(iAge)","iAge>20").ToString();
}


protectedcolor: #00000

你可能感兴趣的:(JavaScript,c,UI,Web,asp)