Showing posts with label GridView. Show all posts
Showing posts with label GridView. Show all posts

Monday, March 10, 2014

How to access a div or HTML controls is inside a gridview?

Here is an example of how to access a div inside the TemplateColumn of a Grid:

aspx:

<asp:TemplateField HeaderText="Pick" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
<ItemStyle Width="60px" />
<ItemTemplate>
<div id="divpickstatus" runat="server">
</div>
</ItemTemplate>
</asp:TemplateField>



codebehind



protected void gridview_schedule_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
HtmlGenericControl divpickstatus = (HtmlGenericControl)e.Row.FindControl("divpickstatus");
}
}
Hope this helps.

Thursday, January 13, 2011

Export GridView to Excel in ASP.NET

Here is the same code to export GridView from C# in ASP.NET

protected void ExportButton_Click(object sender, EventArgs e)
{
   Response.AddHeader("content-disposition", "attachment;filename=Contacts.xls");
   Response.Charset = String.Empty;
   Response.ContentType = "application/vnd.xls";
   System.IO.StringWriter sw = new System.IO.StringWriter();
   System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(sw);
   ContactsGridView.RenderControl(hw);
   Response.Write(sw.ToString());
   Response.End();
 }
Hope this is useful Just kidding