Showing posts with label tips. Show all posts
Showing posts with label tips. Show all posts

Monday, April 26, 2010

c# | asp.net | DataBinder.Eval DataFormatString

Short date pattern. Format : {0:d}

<asp:TemplateField HeaderText="Position Inclusive Dates"   HeaderStyle-Width="75px" SortExpression="">
<ItemTemplate>
<asp:Label ID="_lblPositionIncDate" width="75px" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.PositionIncDate") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="_tbPositionIncDate" width="75px" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.PositionIncDate") %>'></asp:TextBox>
</EditItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
</asp:TemplateField>


More on => BoundField::DataFormatString Property

Saturday, April 24, 2010

ASP.NET | GridView Tips

Extract GridView data to Xls file:

protected void _btnOutputGridViewToXls(object sender, EventArgs e)
{
Response.AddHeader("content-disposition", "attachment;filename=MySample.xls");
Response.Charset = String.Empty;
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter strWr = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmWr = new HtmlTextWriter(strWr);
GridView1.RenderControl(htmWr);
Response.Write(strWr.ToString());
Response.End();
}