private void btnExport_Click(object sender, EventArgs e) { if (exportFieldsCheckBoxList.SelectedItem == null) { ShowMsg("请选择需要导出的分销商信息", false); } else { IList <string> fields = new List <string>(); IList <string> list2 = new List <string>(); foreach (ListItem item in exportFieldsCheckBoxList.Items) { if (item.Selected) { fields.Add(item.Value); list2.Add(item.Text); } } DataTable distributorsNopage = DistributorHelper.GetDistributorsNopage(fields); StringBuilder builder = new StringBuilder(); foreach (string str in list2) { builder.Append(str + ","); if (str == list2[list2.Count - 1]) { builder = builder.Remove(builder.Length - 1, 1); builder.Append("\r\n"); } } foreach (DataRow row in distributorsNopage.Rows) { foreach (string str2 in fields) { builder.Append(row[str2]).Append(","); if (str2 == fields[list2.Count - 1]) { builder = builder.Remove(builder.Length - 1, 1); builder.Append("\r\n"); } } } Page.Response.Clear(); Page.Response.Buffer = false; Page.Response.Charset = "GB2312"; if (exportFormatRadioButtonList.SelectedValue == "csv") { Page.Response.AppendHeader("Content-Disposition", "attachment;filename=DistributorInfo.csv"); Page.Response.ContentType = "application/octet-stream"; } else { Page.Response.AppendHeader("Content-Disposition", "attachment;filename=DistributorInfo.txt"); Page.Response.ContentType = "application/vnd.ms-word"; } Page.Response.ContentEncoding = Encoding.GetEncoding("GB2312"); Page.EnableViewState = false; Page.Response.Write(builder.ToString()); Page.Response.End(); } }
private void btnExport_Click(object sender, System.EventArgs e) { if (this.exportFieldsCheckBoxList.SelectedItem == null) { this.ShowMsg("请选择需要导出的分销商信息", false); return; } System.Collections.Generic.IList <string> list = new System.Collections.Generic.List <string>(); System.Collections.Generic.IList <string> list2 = new System.Collections.Generic.List <string>(); foreach (System.Web.UI.WebControls.ListItem listItem in this.exportFieldsCheckBoxList.Items) { if (listItem.Selected) { list.Add(listItem.Value); list2.Add(listItem.Text); } } System.Data.DataTable distributorsNopage = DistributorHelper.GetDistributorsNopage(new DistributorQuery { GradeId = this.gradeId, Username = this.userName, RealName = this.realName }, list); System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); foreach (string current in list2) { stringBuilder.Append(current + ","); if (current == list2[list2.Count - 1]) { stringBuilder = stringBuilder.Remove(stringBuilder.Length - 1, 1); stringBuilder.Append("\r\n"); } } foreach (System.Data.DataRow dataRow in distributorsNopage.Rows) { foreach (string current2 in list) { stringBuilder.Append(dataRow[current2]).Append(","); if (current2 == list[list2.Count - 1]) { stringBuilder = stringBuilder.Remove(stringBuilder.Length - 1, 1); stringBuilder.Append("\r\n"); } } } this.Page.Response.Clear(); this.Page.Response.Buffer = false; this.Page.Response.Charset = "GB2312"; if (this.exportFormatRadioButtonList.SelectedValue == "csv") { this.Page.Response.AppendHeader("Content-Disposition", "attachment;filename=DistributorInfo.csv"); this.Page.Response.ContentType = "application/octet-stream"; } else { this.Page.Response.AppendHeader("Content-Disposition", "attachment;filename=DistributorInfo.txt"); this.Page.Response.ContentType = "application/vnd.ms-word"; } this.Page.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); this.Page.EnableViewState = false; this.Page.Response.Write(stringBuilder.ToString()); this.Page.Response.End(); }