aspx页面代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="custom.aspx.cs" Inherits="kf_custom" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>无标题页</title> <mce:script type="text/javascript" src="../js/popcalendar.js" mce_src="js/popcalendar.js"></mce:script> <mce:script type="text/javascript" src="../js/popcalendar2.js" mce_src="js/popcalendar2.js"></mce:script> <mce:style type="text/css"><!-- body{font-size:12px;background-color:white;} div#GridView{} div#search1{width:900px;height:100%;background-color:white;margin-bottom:5px;} .mylink{text-decoration:none;color:infotext;font-weight:bold;float:left;} --></mce:style><style type="text/css" mce_bogus="1"> body{font-size:12px;background-color:white;} div#GridView{} div#search1{width:900px;height:100%;background-color:white;margin-bottom:5px;} .mylink{text-decoration:none;color:infotext;font-weight:bold;float:left;} </style> </head> <body> <form id="form1" runat="server"> <div> <div id="search1"> 公司名称:<asp:TextBox ID="txtname" runat="server" Width="110px" Height="16px"></asp:TextBox> 业务范围:<asp:DropDownList ID="ddlfanwei" runat="server" Width="100px" Height="22px"> <asp:ListItem Selected="true" Value="-1" Text="所有"></asp:ListItem> <asp:ListItem Value="1" Text="国"></asp:ListItem> <asp:ListItem Value="2" Text="私"></asp:ListItem> <asp:ListItem Value="3" Text="内贸"></asp:ListItem> <asp:ListItem Value="4" Text="外贸"></asp:ListItem> <asp:ListItem Value="5" Text="内外贸"></asp:ListItem> <asp:ListItem Value="6" Text="其它"></asp:ListItem> </asp:DropDownList> 区域:<asp:TextBox ID="txtarea" runat="server" Width="110px" Height="16px"></asp:TextBox> 行业:<asp:DropDownList ID="ddlhangye" runat="server" Width="180px" Height="22px"> <asp:ListItem Selected="true" Value="-1" Text="所有"></asp:ListItem> <asp:ListItem Value="1" Text="01.旅游餐饮娱乐休闲"></asp:ListItem> <asp:ListItem Value="2" Text="02.机械设备"></asp:ListItem> <asp:ListItem Value="3" Text="03.通用零部件"></asp:ListItem> <asp:ListItem Value="4" Text="04.汽车工业"></asp:ListItem> <asp:ListItem Value="5" Text="05.日常服务"></asp:ListItem> <asp:ListItem Value="6" Text="06.纺织皮革服装鞋帽"></asp:ListItem> <asp:ListItem Value="7" Text="07.零售业家具生活用品食品"></asp:ListItem> <asp:ListItem Value="8" Text="08.通信邮政计算机网络"></asp:ListItem> <asp:ListItem Value="9" Text="09.医疗保健社会福利"></asp:ListItem> <asp:ListItem Value="10" Text="10.电子电器仪器仪表"></asp:ListItem> <asp:ListItem Value="11" Text="11.金融保险证券投资"></asp:ListItem> <asp:ListItem Value="12" Text="12.交通物流运输设备"></asp:ListItem> <asp:ListItem Value="13" Text="13.城建房产建材装潢"></asp:ListItem> <asp:ListItem Value="14" Text="14.石油化工橡胶塑料"></asp:ListItem> <asp:ListItem Value="15" Text="15.钟表眼镜工艺品礼品"></asp:ListItem> <asp:ListItem Value="16" Text="16.造纸纸品印刷包装"></asp:ListItem> <asp:ListItem Value="17" Text="17.新闻出版科研教育留学培训"></asp:ListItem> <asp:ListItem Value="18" Text="18.农林牧渔"></asp:ListItem> <asp:ListItem Value="19" Text="19.广告会展商务办公咨询业"></asp:ListItem> <asp:ListItem Value="20" Text="20.冶金冶炼金属及非金属制品"></asp:ListItem> <asp:ListItem Value="21" Text="21.贸易批发市场"></asp:ListItem> <asp:ListItem Value="22" Text="22.党政机关社会团体"></asp:ListItem> <asp:ListItem Value="23" Text="23.其它"></asp:ListItem> </asp:DropDownList> <br /> <br /> 主营业务:<asp:TextBox ID="txtmain" runat="server" Width="110px" Height="16px"></asp:TextBox> 业务形态:<asp:DropDownList ID="ddlxintai" runat="server" Width="100px" Height="22px"> <asp:ListItem Selected="true" Value="-1" Text="所有"></asp:ListItem> <asp:ListItem Value="1" Text="B to B"></asp:ListItem> <asp:ListItem Value="2" Text="B to C"></asp:ListItem> <asp:ListItem Value="3" Text="Both"></asp:ListItem> <asp:ListItem Value="4" Text="Others"></asp:ListItem> </asp:DropDownList> 起始时间:<asp:textbox id="txt_StartCPXG_DATE" runat="server" Width="80px" CssClass="edLine" Height="20px"></asp:textbox> <img alt="" id="Image_blqx1" style="CURSOR: hand" mce_style="CURSOR: hand" οnclick="popUpCalendar(this,document.forms[0].txt_StartCPXG_DATE,'yyyy-mm-dd')" src="../images/calendar.gif" mce_src="images/calendar.gif" /> 截止时间:<asp:textbox id="txt_StartCPXG_DATE2" runat="server" Width="80px" CssClass="edLine" Height="20px"></asp:textbox> <img alt="" id="Image_blqx12" style="CURSOR: hand" mce_style="CURSOR: hand" οnclick="popUpCalendar(this,document.forms[0].txt_StartCPXG_DATE2,'yyyy-mm-dd')" src="../images/calendar.gif" mce_src="images/calendar.gif" /> <br /> <br /> 电 话:<asp:TextBox ID="txttel" runat="server" Width="110px" Height="16px"></asp:TextBox> <br /> <br /> <br /> <asp:Button ID="search" runat="server" Font-Size="10pt" Text="搜 索" Height="23px" Width="111px" OnClick="search_Click"/> <asp:Button ID="add" runat="server" Font-Size="10pt" Text="增加" Height="23px" Width="120px" OnClick="add_Click"/> <asp:Button ID="btnTotal" runat="server" Font-Size="10pt" Text="统计信息" Height="23px" Width="120px" OnClick="btnTotal_Click"/> <asp:Button ID="btnAddAA" runat="server" Font-Size="10pt" Text="添加意向客户" Height="23px" Width="120px" OnClick="btnAddAA_Click"/> <br /> <asp:Label ID="lblcount" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label> <br /> </div> <div id="GridView"> <asp:GridView ID="GridView1" runat="server" Font-Size="12px" AutoGenerateColumns="False" CellPadding="3" ForeColor="#333333" AllowSorting="true" PageSize="100" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging" Height="344px" OnRowDataBound="GridView1_RowDataBound" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnRowCancelingEdit="GridView1_RowCancelingEdit" Width="1250px" BorderColor="gray"> <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> <Columns> <asp:BoundField DataField="ID" HeaderText="序号" ReadOnly="True" /> <asp:HyperLinkField ControlStyle-CssClass= "mylink " HeaderText="公司名称" Text="COM_NAME" DataNavigateUrlFields="id" DataNavigateUrlFormatString="customInfo.aspx?cid={0}" Target="_blank" NavigateUrl="customInfo.aspx" DataTextField="COM_NAME"> </asp:HyperLinkField> <asp:BoundField DataField="COM_TEL" HeaderText="公司电话" /> <asp:BoundField DataField="CONTACT_PERSON_1" HeaderText="联系人1" /> <asp:BoundField DataField="CONTACT_PERSON_1_PHONE" HeaderText="手机1" /> <asp:BoundField DataField="CONTACT_PERSON_1_TITLE" HeaderText="职位1" /> <asp:BoundField DataField="CONTACT_PERSON_2" HeaderText="联系人2" /> <asp:BoundField DataField="CONTACT_PERSON_2_PHONE" HeaderText="手机2" /> <asp:BoundField DataField="CONTACT_PERSON_2_TITLE" HeaderText="职位2" /> <asp:BoundField DataField="CONTACT_PERSON_3" HeaderText="联系人3" /> <asp:BoundField DataField="CONTACT_PERSON_3_PHONE" HeaderText="手机3" /> <asp:BoundField DataField="CONTACT_PERSON_3_TITLE" HeaderText="职位3" /> <asp:BoundField DataField="BUSINESS_ID" HeaderText="行业" /> <asp:BoundField DataField="REGION" HeaderText="区域" /> <asp:TemplateField HeaderText="业务范围"> <ItemTemplate> <asp:DropDownList ID="ddlfanwei2" runat="server" Width="90px" Height="21px"> </asp:DropDownList> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="业务形态"> <ItemTemplate> <asp:DropDownList ID="ddlxintai2" runat="server" Width="90px" Height="21px"> </asp:DropDownList> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="MAINFUNCTION" HeaderText="主营业务" /> <asp:BoundField DataField="COM_NAME" HeaderText="名称" /> <asp:CommandField HeaderText="修改" ShowEditButton="True" /> <asp:TemplateField HeaderText="选择"> <ItemTemplate> <asp:CheckBox ID="CheckBox1" runat="server" /> </ItemTemplate> </asp:TemplateField> </Columns> <RowStyle ForeColor="#000066" HorizontalAlign="Center" /> <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Center" /> <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" /> </asp:GridView> <asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="True" Font-Size="9pt" OnCheckedChanged="CheckBox2_CheckedChanged" Text="全选" /> <asp:Button ID="btncancel" runat="server" Font-Size="9pt" Text="取消" OnClick="btncancel_Click"/> <asp:Button ID="btndel" runat="server" Font-Size="9pt" Text="删除" OnClick="btndel_Click"/> <asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource> </div> </div> </form> </body> </html> cs文件 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 i_salesDAL; using i_salesModels; using i_salesBLL; using MySql.Data.MySqlClient; public partial class kf_custom : System.Web.UI.Page { string strCon = "server=localhost;user id=root;password=root;database=google;CharSet=gb2312;"; MySqlConnection mysqlcon; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { bind(); string sql = "select count(*) from v_company"; int all = DBHelper.GetScalar(sql); lblcount.Text ="共有数据:"+all+"条"; } } //绑定GridView1 public void bind() { string sqlstr = "select * from v_company order by TIME desc"; //防止程序池溢出 using (mysqlcon = new MySqlConnection(strCon)) { MySqlDataAdapter myda = new MySqlDataAdapter(sqlstr, mysqlcon); DataSet myds = new DataSet(); mysqlcon.Open(); myda.Fill(myds, "v_company"); GridView1.DataSource = myds; GridView1.DataKeyNames = new string[] { "id" };//主键 GridView1.DataBind(); } } //编辑 protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; bind(); } //更新 protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { string sqlstr = "update v_company set COM_NAME='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[17].Controls[0])).Text.ToString().Trim() + "',BUSINESS_ID='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[12].Controls[0])).Text.ToString().Trim() + "',REGION='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[13].Controls[0])).Text.ToString().Trim() + "',TRADETYPE_ID='" + ((DropDownList)(GridView1.Rows[e.RowIndex].Cells[14].FindControl("ddlfanwei2"))).SelectedValue + "',SERVICE_ID='" + ((DropDownList)(GridView1.Rows[e.RowIndex].Cells[15].FindControl("ddlxintai2"))).SelectedValue + "',MAINFUNCTION='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[9].Controls[0])).Text.ToString().Trim() + "',CONTACT_PERSON_1='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + "',CONTACT_PERSON_1_PHONE='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim() + "',CONTACT_PERSON_1_TITLE='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim() + "',CONTACT_PERSON_2='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[6].Controls[0])).Text.ToString().Trim() + "',CONTACT_PERSON_2_PHONE='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[7].Controls[0])).Text.ToString().Trim() + "',CONTACT_PERSON_2_TITLE='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[8].Controls[0])).Text.ToString().Trim() + "',CONTACT_PERSON_3='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[9].Controls[0])).Text.ToString().Trim() + "',CONTACT_PERSON_3_PHONE='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[10].Controls[0])).Text.ToString().Trim() + "',CONTACT_PERSON_3_TITLE='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[11].Controls[0])).Text.ToString().Trim() + "' where id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'"; DBHelper.ExecuteCommand(sqlstr); GridView1.EditIndex = -1; bind(); } //取消 protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { GridView1.EditIndex = -1; bind(); } //手动写分页时必须添加的事件 protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { string sqlstr = "select * from v_company order by TIME desc"; //防止程序池溢出 using (mysqlcon = new MySqlConnection(strCon)) { MySqlDataAdapter myda = new MySqlDataAdapter(sqlstr, mysqlcon); DataSet myds = new DataSet(); mysqlcon.Open(); myda.Fill(myds, "v_company"); GridView1.PageIndex = e.NewPageIndex; GridView1.DataSource = myds; GridView1.DataBind(); } } //行事件,鼠标移到GridView某一行时改变该行的背景色方法 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { //如果是绑定数据行 if (e.Row.RowType == DataControlRowType.DataRow) { //鼠标经过时,行背景色变 e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#9999CC'"); //鼠标移出时,行背景色变 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'"); //绑定主营业务 //绑定业务范围ddlfanwei2,行事件 DropDownList ddl = e.Row.Cells[15].FindControl("ddlfanwei2") as DropDownList; if (ddl != null) { string sqlstr = "select * from tradetype"; using (mysqlcon = new MySqlConnection(strCon)) { MySqlDataAdapter myda = new MySqlDataAdapter(sqlstr, mysqlcon); DataSet myds = new DataSet(); mysqlcon.Open(); myda.Fill(myds, "tradetype"); ddl.DataSource = myds.Tables["tradetype"].DefaultView; ddl.DataTextField = myds.Tables["tradetype"].Columns[2].ColumnName;//id ddl.DataValueField = myds.Tables["tradetype"].Columns[0].ColumnName;//info zhongwen ddl.DataBind(); } if (V_companyManager.GetTradetype_IDById(int.Parse(e.Row.Cells[0].Text)) == 1) { ddl.Items[0].Selected = true; } if (V_companyManager.GetTradetype_IDById(int.Parse(e.Row.Cells[0].Text)) == 2) { ddl.Items[1].Selected = true; } if (V_companyManager.GetTradetype_IDById(int.Parse(e.Row.Cells[0].Text)) == 3) { ddl.Items[2].Selected = true; } if (V_companyManager.GetTradetype_IDById(int.Parse(e.Row.Cells[0].Text)) == 4) { ddl.Items[3].Selected = true; } if (V_companyManager.GetTradetype_IDById(int.Parse(e.Row.Cells[0].Text)) == 5) { ddl.Items[4].Selected = true; } if (V_companyManager.GetTradetype_IDById(int.Parse(e.Row.Cells[0].Text)) == 6) { ddl.Items[5].Selected = true; } } //绑定业务形态ddlxintai2,行事件 DropDownList ddl2 = e.Row.Cells[15].FindControl("ddlxintai2") as DropDownList; if (ddl != null) { string sqlstr = "select * from service"; using (mysqlcon = new MySqlConnection(strCon)) { MySqlDataAdapter myda = new MySqlDataAdapter(sqlstr, mysqlcon); DataSet myds = new DataSet(); mysqlcon.Open(); myda.Fill(myds, "service"); ddl2.DataSource = myds.Tables["service"].DefaultView; ddl2.DataTextField = myds.Tables["service"].Columns[2].ColumnName;//id ddl2.DataValueField = myds.Tables["service"].Columns[0].ColumnName;//info zhongwen ddl2.DataBind(); } if (V_companyManager.GetService_IDById(int.Parse(e.Row.Cells[0].Text)) == 1) { ddl2.Items[0].Selected = true; } if (V_companyManager.GetService_IDById(int.Parse(e.Row.Cells[0].Text)) == 2) { ddl2.Items[1].Selected = true; } if (V_companyManager.GetService_IDById(int.Parse(e.Row.Cells[0].Text)) == 3) { ddl2.Items[2].Selected = true; } if (V_companyManager.GetService_IDById(int.Parse(e.Row.Cells[0].Text)) == 4) { ddl2.Items[3].Selected = true; } } } //把前台的第一列的表头该为“序号”,因为以前的第一列被“遮盖”了。GridView实现自动编号 if (e.Row.RowIndex != -1) { int id = e.Row.RowIndex + 1; e.Row.Cells[0].Text = id.ToString(); } } protected void add_Click(object sender, EventArgs e) { Response.Redirect("addCustom.aspx"); } //搜索 protected void search_Click(object sender, EventArgs e) { string name = this.txtname.Text; string fanwei; if (int.Parse(this.ddlfanwei.SelectedItem.Value) == -1)//如果所有int.Parse(this.ddlfanwei.SelectedItem.Value); { fanwei = ""; } else { fanwei = " and TRADETYPE_ID=" + int.Parse(this.ddlfanwei.SelectedItem.Value) + ""; } string area = this.txtarea.Text; string hangye; if (int.Parse(this.ddlhangye.SelectedItem.Value) == -1) { hangye = ""; } else { hangye = " and BUSINESS_ID=" + int.Parse(this.ddlfanwei.SelectedItem.Value) + ""; } string main = this.txtmain.Text; //int xt = int.Parse(this.ddlxintai.SelectedItem.Value); string xt; if (int.Parse(this.ddlxintai.SelectedItem.Value) == -1) { xt = ""; } else { xt = " and SERVICE_ID=" + int.Parse(this.ddlxintai.SelectedItem.Value) + ""; } string comtel = this.txttel.Text.Trim(); string time1 =this.txt_StartCPXG_DATE.Text.Trim(); string time2 =this.txt_StartCPXG_DATE2.Text.Trim(); // if(time1!=null||time1!="") string sqlstr = "select * from v_company where COM_NAME like '%" + name + "%'"+fanwei+" and REGION like '%" + area + "%' and COM_TEL like '%" + comtel + "%'"+hangye+" and MAINFUNCTION like '%" + main + "%'"+xt+" order by TIME desc";// and (TIME between '%" + time1 + "%' and '%" + time2 + "%') //防止程序池溢出 using (mysqlcon = new MySqlConnection(strCon)) { MySqlDataAdapter myda = new MySqlDataAdapter(sqlstr, mysqlcon); DataSet myds = new DataSet(); mysqlcon.Open(); myda.Fill(myds, "v_company"); GridView1.DataSource = myds; GridView1.DataKeyNames = new string[] { "id" };//主键 GridView1.DataBind(); } } //checkbox all protected void CheckBox2_CheckedChanged(object sender, EventArgs e) { for (int i = 0; i <= GridView1.Rows.Count - 1; i++) { CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1"); if (CheckBox2.Checked == true) { cbox.Checked = true; } else { cbox.Checked = false; } } } //del out protected void btncancel_Click(object sender, EventArgs e) { CheckBox2.Checked = false; for (int i = 0; i <= GridView1.Rows.Count - 1; i++) { CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1"); cbox.Checked = false; } } //del all protected void btndel_Click(object sender, EventArgs e) { for (int i = 0; i <= GridView1.Rows.Count - 1; i++) { CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1"); if (cbox.Checked == true) { //根据用户id批量删除客户 string strCon = "delete from v_company where id='" + GridView1.DataKeys[i].Value + "'"; DBHelper.ExecuteCommand(strCon); //string strCon2 = "delete from convey_company where COM_ID='" + GridView1.DataKeys[i].Value + "'"; //DBHelper.ExecuteCommand(strCon2); //string strCon3 = "delete from d_company where COM_ID='" + GridView1.DataKeys[i].Value + "'"; //DBHelper.ExecuteCommand(strCon3); //string strCon4 = "delete from date_info where COM_ID='" + GridView1.DataKeys[i].Value + "'"; //DBHelper.ExecuteCommand(strCon4); //string strCon5 = "delete from msales_company where company_ID='" + GridView1.DataKeys[i].Value + "'"; //DBHelper.ExecuteCommand(strCon5); //string strCon6 = "delete from msales_trace_company where company_ID='" + GridView1.DataKeys[i].Value + "'"; //DBHelper.ExecuteCommand(strCon6); //string strCon7 = "delete from public_company where COM_ID='" + GridView1.DataKeys[i].Value + "'"; //DBHelper.ExecuteCommand(strCon7); //string strCon8 = "delete from sales_company where COMPANY_ID='" + GridView1.DataKeys[i].Value + "'"; //DBHelper.ExecuteCommand(strCon8); //string strCon9 = "delete from sales_trace_company where COM_ID='" + GridView1.DataKeys[i].Value + "'"; //DBHelper.ExecuteCommand(strCon9); //string strCon10 = "delete from telephone_company where COMPANY_ID='" + GridView1.DataKeys[i].Value + "'"; //DBHelper.ExecuteCommand(strCon10); //string strCon11 = "delete from telephone_trace_company where COMPANY_ID='" + GridView1.DataKeys[i].Value + "'"; } } Page.RegisterStartupScript("", "<mce:script type="text/javascript"><!-- alert('删除成功!') // --></mce:script>"); bind(); } protected void btnTotal_Click(object sender, EventArgs e) { Response.Redirect("total.aspx"); } protected void btnAddAA_Click(object sender, EventArgs e) { Response.Redirect("addAACustom.aspx"); } }