My GridView displays a list of names. On double clicking the name, the name should be set in a textbox. This should happen without any postback. We will use client side scripts for the OnDblClick event handler.

To set client side event handlers, use the RowCreated event of GridView.

<asp:TextBox ID="txtSearch" runat="server"/>
<asp:GridView ID="gvMain" runat="server" AutoGenerateColumns="false"
	 OnRowCreated="gvMain_RowCreated">
	<Columns>
	    <asp:BoundField HeaderText="Name" DataField="Name" />
        </Columns>
</asp:GridView>

RowCreated event handler sets the OnDblClick event handler.…

Read More

Repeater displays a list of items with a custom template. Our repeater shows the top 10 items. Instead of regular pagination, we have a Show More link. On clicking the link, we show all the remaining items.

We create a repeater with HeaderTemplate, ItemTemplate and FooterTemplate. HeaderTemplate begins an unordered list using the ul tag. ItemTemplate uses the li tag to show a list of items.…

Read More

GridView in ASP.NET displays tabular data. We will explore how to export this data as an excel file. Let us assume that the GridView represents a report. And we want to send the report as an email attachment. Below code exports the GridView and prepares an email attachment.

protected void Submit_Click(object sender, EventArgs e)
{
    // Render the contents of the GridView into a string
    StringBuilder sb = new StringBuilder();
    StringWriter sw = new StringWriter(sb);
    HtmlTextWriter htw = new HtmlTextWriter(sw);
    GridView1.RenderControl(htw);
Read More