本文整理汇总了C#中System.Web.UI.WebControls.DataGrid类的典型用法代码示例。如果您正苦于以下问题:C# DataGrid类的具体用法?C# DataGrid怎么用?C# DataGrid使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataGrid类属于System.Web.UI.WebControls命名空间,在下文中一共展示了DataGrid类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: save
private void save(DataTable dt,string filename)
{
DataGrid excel = new DataGrid();
System.Web.UI.WebControls.TableItemStyle AlternatingStyle = new TableItemStyle();
System.Web.UI.WebControls.TableItemStyle headerStyle = new TableItemStyle();
System.Web.UI.WebControls.TableItemStyle itemStyle = new TableItemStyle();
AlternatingStyle.BackColor = System.Drawing.Color.LightGray;
headerStyle.BackColor = System.Drawing.Color.LightGray;
headerStyle.Font.Bold = true;
headerStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
itemStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center; ;
excel.AlternatingItemStyle.MergeWith(AlternatingStyle);
excel.HeaderStyle.MergeWith(headerStyle);
excel.ItemStyle.MergeWith(itemStyle);
excel.GridLines = GridLines.Both;
excel.HeaderStyle.Font.Bold = true;
DataSet ds = new DataSet();
ds.Tables.Add(dt);
excel.DataSource = ds; //输出DataTable的内容
excel.DataBind();
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
excel.RenderControl(oHtmlTextWriter);
Response.AddHeader("Content-Disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8) + ".xls");
Response.ContentType = "application/ms-excel";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.Write(oHtmlTextWriter.InnerWriter.ToString());
Response.End();
}
开发者ID:bsimp6983,项目名称:BackupDashes,代码行数:32,代码来源:ExportXLS.aspx.cs
示例2: GetFooter
private DataGridItem GetFooter(DataGrid grid)
{
Control table = grid.Controls[0];
DataGridItem footer = table.Controls[table.Controls.Count-1] as DataGridItem;
if(footer.ItemType==ListItemType.Footer) return footer;
return null;
}
开发者ID:rags,项目名称:playground,代码行数:7,代码来源:frmGridHeader.aspx.cs
示例3: ConfigureDataGrid
public static void ConfigureDataGrid(ref DataGrid dgResults, DataTable dt, bool showColumnHeadings, bool useAlternatingRowColor, bool showGridLines, Int16 cellPadding, string columnLabels)
{
dgResults.ShowHeader = showColumnHeadings;
dgResults.AlternatingItemStyle.BackColor = useAlternatingRowColor ? dgResults.BorderColor : dgResults.BackColor;
if (showGridLines)
{
dgResults.GridLines = GridLines.Both;
dgResults.BorderStyle = BorderStyle.Solid;
}
else
{
dgResults.GridLines = GridLines.None;
dgResults.BorderStyle = BorderStyle.None;
}
dgResults.CellPadding = cellPadding;
if (showColumnHeadings)
{
String[] strColumnLabel = columnLabels.Split(',');
for (var i = 0; i < dt.Columns.Count; i++)
{
try
{
dt.Columns[i].ColumnName = strColumnLabel[i].Trim();
}
catch
{
}
}
}
}
开发者ID:mohearn,项目名称:jics-simple-query,代码行数:35,代码来源:OutputHelper.cs
示例4: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
//if (Session["Type"].ToString() == "Excel")
//{
DataSet ds = Session["ExcelDs"] as DataSet;
Response.Clear();
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=ExcelName.xls");
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
System.Web.UI.WebControls.DataGrid dg = new System.Web.UI.WebControls.DataGrid();
dg.DataSource = ds.Tables[0];
dg.DataBind();
dg.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
//}
//else
//{
// Response.ContentType = "application/pdf";
// string path = Server.MapPath("~/PDFS/TestM10.pdf");
// byte[] bts = System.IO.File.ReadAllBytes(path);
// Response.Clear();
// Response.ClearHeaders();
// Response.AddHeader("Content-Type", "Application/octet-stream");//octet-stream
// Response.AddHeader("Content-Length", bts.Length.ToString());
// Response.AddHeader("Content-Disposition", "attachment; filename=1.pdf");
// Response.BinaryWrite(bts);
// Response.Flush();
// Response.TransmitFile(path);
// Response.End();
//}
}
开发者ID:hugo-mirad,项目名称:Test-car-sales,代码行数:34,代码来源:DownloadPageTest.aspx.cs
示例5: UploadDataTableToExcel
private void UploadDataTableToExcel(DataTable feedBacks)
{
HttpResponse response = HttpContext.Current.Response;
try
{
response.Clear();
response.Charset = string.Empty;
response.ContentType = "application/vnd.ms-excel";
response.AddHeader("Content-Disposition", "attachment;filename=\"FeedBack.xls\"");
using (StringWriter stringWriter = new StringWriter())
{
using (HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter))
{
DataGrid dataGrid = new DataGrid();
dataGrid.DataSource = feedBacks;
dataGrid.DataBind();
dataGrid.RenderControl(htmlTextWriter);
response.Write(stringWriter.ToString());
}
}
response.End();
}
catch (ThreadAbortException ex)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
}
}
开发者ID:dheerajmishra77,项目名称:TCPedia,代码行数:27,代码来源:download.aspx.cs
示例6: ExportToExcel
public void ExportToExcel(DataTable dt)
{
if (dt.Rows.Count > 0)
{
string filename = "Test1234.xls";
string excelHeader = "Quiz Report";
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
DataGrid dgGrid = new DataGrid();
dgGrid.DataSource = dt;
dgGrid.DataBind();
// Report Header
hw.WriteLine("<b><u><font size=’3′> " + excelHeader + " </font></u></b>");
//Get the HTML for the control.
dgGrid.RenderControl(hw);
//Write the HTML back to the browser.
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + "");
this.EnableViewState = false;
Response.Write(tw.ToString());
Response.End();
}
}
开发者ID:usuresh,项目名称:CloudApp,代码行数:27,代码来源:Default.aspx.cs
示例7: DataTable2Excel
/// <summary>
/// 导出Excel文件,转换为可读模式
/// </summary>
public static void DataTable2Excel(System.Data.DataTable dtData)
{
DataGrid dgExport = null;
HttpContext curContext = HttpContext.Current;
StringWriter strWriter = null;
HtmlTextWriter htmlWriter = null;
if (dtData != null)
{
curContext.Response.ContentType = "application/vnd.ms-excel";
curContext.Response.ContentEncoding = System.Text.Encoding.UTF8;
curContext.Response.Charset = "";
strWriter = new StringWriter();
htmlWriter = new HtmlTextWriter(strWriter);
dgExport = new DataGrid();
dgExport.DataSource = dtData.DefaultView;
dgExport.AllowPaging = false;
dgExport.DataBind();
try
{
dgExport.RenderControl(htmlWriter);
}
catch (Exception e)
{
Log4Net.LogWrite("err", e.Message);
}
curContext.Response.Write(strWriter.ToString());
curContext.Response.End();
}
}
开发者ID:wawa0210,项目名称:jgq,代码行数:33,代码来源:ExcelHelper.cs
示例8: ExportToExcelFile
/// <summary>
/// Exporta la información a Excel.
/// </summary>
/// <param name="response">HttpResponse actual.</param>
/// <param name="data">Datos a exportar.</param>
/// <param name="nombreArchivo">Nombre del archivo Excel</param>
public static void ExportToExcelFile(HttpResponse response, DataView data, string nombreArchivo)
{
var dg = new DataGrid { DataSource = data };
dg.DataBind();
response.Clear();
response.Buffer = true;
//application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
response.AddHeader("Content-Disposition", "filename=" + nombreArchivo);
response.ContentType = "application/vnd.ms-excel";
response.Charset = "UTF-8";
response.ContentEncoding = System.Text.Encoding.Default;
var stringWriter = new StringWriter();
var htmlWriter = new HtmlTextWriter(stringWriter);
dg.RenderControl(htmlWriter);
response.Write(stringWriter.ToString());
//resp.Flush();
try
{
response.End();
}
catch (Exception ex)
{
ISException.RegisterExcepcion(ex);
throw ex;
}
}
开发者ID:preguntoncojonero,项目名称:test,代码行数:36,代码来源:ISExcel.cs
示例9: ExecuteResult
public override void ExecuteResult(ControllerContext context)
{
var r = context.HttpContext.Response;
r.Clear();
r.ContentType = "application/vnd.ms-excel";
if (!string.IsNullOrEmpty(FileName))
r.AddHeader("content-disposition",
"attachment;filename=" + FileName);
const string header =
@"<html xmlns:x=""urn:schemas-microsoft-com:office:excel"">
<head>
<meta http-equiv=Content-Type content=""text/html; charset=utf-8"">
<style>
<!--table
br {mso-data-placement:same-cell;}
tr {vertical-align:top;}
-->
</style>
</head>
<body>";
r.Write(header);
r.Charset = "";
var dg = new DataGrid();
dg.EnableViewState = false;
dg.DataSource = Data;
dg.DataBind();
dg.RenderControl(new HtmlTextWriter(r.Output));
r.Write("</body></HTML>");
}
开发者ID:stevesloka,项目名称:bvcms,代码行数:30,代码来源:ExcelResult.cs
示例10: ToExcel
public void ToExcel(object sender, System.EventArgs e)
{
try
{
DataTable dtData = GetDTList();
System.Web.UI.WebControls.DataGrid dgExport = null;
System.Web.HttpContext curContext = System.Web.HttpContext.Current;
System.IO.StringWriter strWriter = null;
System.Web.UI.HtmlTextWriter htmlWriter = null;
if (dtData != null && dtData.Rows.Count > 0)
{
curContext.Response.ContentType = "application/vnd.ms-excel";
curContext.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
curContext.Response.Charset = "UTF-8";
curContext.Response.Write("<meta http-equiv=Content-Type content=text/html;charset=gb2312 >");
strWriter = new System.IO.StringWriter();
htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);
dgExport = new System.Web.UI.WebControls.DataGrid();
dgExport.DataSource = dtData.DefaultView;
dgExport.AllowPaging = false;
dgExport.DataBind();
for (int i = 0; i < dgExport.Items.Count; i++)
{
for (int j = 0; j < 3; j++)
{
dgExport.Items[i].Cells[j].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
}
}
dgExport.RenderControl(htmlWriter);
curContext.Response.Write(strWriter.ToString());
curContext.Response.End();
WriteAlertInfo(AlertSuccess);
}
else
{
WriteAlertInfo(AlertNoData);
}
}
catch (FisException fe)
{
this.GridViewExt1.DataSource = GetTable();
this.GridViewExt1.DataBind();
writeToAlertMessage(fe.mErrmsg);
}
catch (Exception ex)
{
this.GridViewExt1.DataSource = GetTable();
this.GridViewExt1.DataBind();
writeToAlertMessage(ex.Message);
}
finally
{
endWaitingCoverDiv();
}
}
开发者ID:wra222,项目名称:testgit,代码行数:60,代码来源:DTPalletControl.aspx.cs
示例11: Convert
public static void Convert(System.Data.DataSet ds, System.Web.HttpResponse response, string ExcelName)
{
try
{
//first let's clean up the response.object
response.Clear();
response.Charset = "";
//set the response mime type for excel
response.ContentType = "application/vnd.ms-excel";
//create a string writer
//response.AddHeader("Content-Disposition", "attachment;filename=Shilpa.xls");
response.AddHeader("Content-Disposition", "attachment;filename=" + ExcelName + ".xls");
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
//create an htmltextwriter which uses the stringwriter
System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
//instantiate a datagrid
System.Web.UI.WebControls.DataGrid dg = new System.Web.UI.WebControls.DataGrid();
//set the datagrid datasource to the dataset passed in
dg.DataSource = ds.Tables[0];
//bind the datagrid
dg.DataBind();
//tell the datagrid to render itself to our htmltextwriter
dg.RenderControl(htmlWrite);
//all that's left is to output the html
response.Write(stringWrite.ToString());
response.End();
}
catch (Exception ex)
{
throw ex;
}
}
开发者ID:BInny1,项目名称:United-Car-Exchange,代码行数:35,代码来源:DataSetToExcel.cs
示例12: ExecuteResult
public override void ExecuteResult(ControllerContext context)
{
var Response = context.HttpContext.Response;
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
var dg = new DataGrid();
string filename = null;
switch (type)
{
case "donorfundtotals":
filename = "DonorFundTotals";
dg.DataSource = ExportPeople.ExcelDonorFundTotals(Dt1, Dt2, fundid, campusid, pledges, nontaxdeductible, IncUnclosedBundles);
break;
case "donortotals":
filename = "DonorTotals";
dg.DataSource = ExportPeople.ExcelDonorTotals(Dt1, Dt2, campusid, pledges, nontaxdeductible, IncUnclosedBundles);
break;
case "donordetails":
filename = "DonorDetails";
dg.DataSource = ExportPeople.DonorDetails(Dt1, Dt2, fundid, campusid, pledges, nontaxdeductible, IncUnclosedBundles);
break;
}
dg.DataBind();
Response.AddHeader("Content-Disposition", "attachment;filename={0}.xls".Fmt(filename));
dg.RenderControl(new HtmlTextWriter(Response.Output));
}
开发者ID:rossspoon,项目名称:bvcms,代码行数:27,代码来源:ContributionsExcelResult.cs
示例13: SpanRow
public static void SpanRow(DataGrid dg, int groupColumn, int compareColumn)
{
int i = 0;
int j = 0;
int rowSpan;
string strTemp = "";
for (i = 0; i < dg.Items.Count; i++)
{
rowSpan = 1;
strTemp = dg.Items[i].Cells[compareColumn].Text;
for (j = i + 1; j < dg.Items.Count; j++)
{
if (string.Compare(strTemp, dg.Items[j].Cells[compareColumn].Text) == 0)
{
rowSpan += 1;
dg.Items[i].Cells[groupColumn].RowSpan = rowSpan;
dg.Items[j].Cells[groupColumn].Visible = false;
}
else
{
break;
}
}
i = j - 1;
}
}
开发者ID:TaylorLi,项目名称:WorkStudioEnhance,代码行数:27,代码来源:DataGridHelper.cs
示例14: ExecuteResult
public override void ExecuteResult(ControllerContext context)
{
var Response = context.HttpContext.Response;
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=CMSPeople.xls");
Response.Charset = "";
var name = "ExtraExcelResult " + DateTime.Now;
var tag = DbUtil.Db.PopulateSpecialTag(qid, DbUtil.TagTypeId_ExtraValues);
var roles = CMSRoleProvider.provider.GetRolesForUser(Util.UserName);
var xml = XDocument.Parse(DbUtil.Db.Content("StandardExtraValues.xml", "<Fields/>"));
var fields = (from ff in xml.Root.Elements("Field")
let vroles = ff.Attribute("VisibilityRoles")
where vroles != null && (vroles.Value.Split(',').All(rr => !roles.Contains(rr)))
select ff.Attribute("name").Value);
var nodisplaycols = string.Join("|", fields);
var cmd = new SqlCommand("dbo.ExtraValues @p1, @p2, @p3");
cmd.Parameters.AddWithValue("@p1", tag.Id);
cmd.Parameters.AddWithValue("@p2", "");
cmd.Parameters.AddWithValue("@p3", nodisplaycols);
cmd.Connection = new SqlConnection(Util.ConnectionString);
cmd.Connection.Open();
var dg = new DataGrid();
dg.DataSource = cmd.ExecuteReader();
dg.DataBind();
dg.RenderControl(new HtmlTextWriter(Response.Output));
}
开发者ID:hkouns,项目名称:bvcms,代码行数:32,代码来源:ExtraExcelResult.cs
示例15: ASPNetDatagridDecorator
private ASPNetDatagridDecorator(DataGrid DatagridToDecorate, ArrayList HeaderCells)
{
//
// TODO: Add constructor logic here
//
this.DatagridToDecorate = DatagridToDecorate;
AddMergeHeader(HeaderCells);
}
开发者ID:marlonps,项目名称:OpenSARC,代码行数:8,代码来源:ASPNetDatagridDecorator.cs
示例16: Bind
public static void Bind(DataTable dt, DataGrid dg)
{
if (dt != null)
{
dg.DataSource = dt;
dg.DataBind();
}
}
开发者ID:romanu6891,项目名称:fivemen,代码行数:8,代码来源:MyDataBinder.cs
示例17: BindAndSort
/// <summary>
/// Bind datagrid with sorting dataview.
/// </summary>
/// <param name="dv">DataView</param>
/// <param name="dataGrid">DataGrid</param>
/// <param name="sortField">Sorting Field</param>
/// <param name="keyField">DataGrid's Key Field</param>
public static void BindAndSort(DataView dv,DataGrid dataGrid,string sortField,string keyField)
{
if(dv != null)
dv.Sort = sortField;
dataGrid.DataSource = dv;
dataGrid.DataKeyField=keyField;
dataGrid.DataBind();
}
开发者ID:TheProjecter,项目名称:wgiadunion,代码行数:15,代码来源:HelperDatagrid.cs
示例18: DataGridWebControlSupport
public void DataGridWebControlSupport()
{
var command = new NpgsqlCommand("select * from data;", Conn);
var dr = command.ExecuteReader();
//Console.WriteLine(dr.FieldCount);
var dg = new DataGrid();
dg.DataSource = dr;
dg.DataBind();
}
开发者ID:kristofen,项目名称:Npgsql,代码行数:9,代码来源:DataReaderTests.cs
示例19: GetHtmlTagsfromDatagrid
private static System.IO.StringWriter GetHtmlTagsfromDatagrid(DataTable datatable)
{
System.IO.StringWriter stringWriter = new System.IO.StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWriter);
DataGrid dg = new DataGrid();
dg.DataSource = datatable;
dg.DataBind();
dg.RenderControl(htmlWrite);
return stringWriter;
}
开发者ID:nullqube,项目名称:Michael-Sync-s-blog-sample,代码行数:10,代码来源:Default.aspx.cs
示例20: GenerateCols
private void GenerateCols(DataTable dt,DataGrid dg)
{
foreach(DataColumn dc in dt.Columns)
{
BoundColumn bc = new BoundColumn();
bc.HeaderText=dc.ColumnName;
bc.DataField=dc.ColumnName;
dg.Columns.Add(bc);
}
}
开发者ID:rags,项目名称:playground,代码行数:10,代码来源:frmMDXToGrid.aspx.cs
注:本文中的System.Web.UI.WebControls.DataGrid类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论