.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Empty template support for GridView

Posted By:      Posted Date: August 21, 2010    Points: 0   Category :ASP.Net

Just add the following to support the empty text in the GridView.


protected override void RenderContents(HtmlTextWriter writer)
	if (Extender.AdapterEnabled)
		GridView gridView = Control as GridView;
		if (gridView != null)
			if ((gridView.Rows.Count == 0) && !String.IsNullOrEmpty(gridView.EmptyDataText))
				writer.WriteAttribute("class", "AspNet-GridView-Empty");

Example of tag to be added to the css
.NiceGridView .AspNet-GridView div.AspNet-GridView-Empty
	border-width: 1px;
	border-style: solid;
	border-color: # 

View Complete Post

More Related Resource Links

Find and Set DetailsView Controls In Empty Data Template in Gridview



I would like to find controls in the detailsview control placed in the EmptyData Template of the gridview.   I am trying to create Insert new record for the gridview control.

1. If there are existing records in the table - works fine and sets my two values:
 placed Detailsview and Insert Button in the footer of the gridview.  I needed to set the values of two fields.  When I click on the Insert button it saves new record and sets the field with the value (code attached - works fine).  I also have a popup extender that opens detailsview - this works just fine.

2, If ther are not records in the table - saves record but cannot find and set controls on the detailsview
Same thing setup in the EmptyData Template.  The record is saved but I cannot Find and set the field value on the control.

Here is code:

1.  Link button (on click) in the gridview footer (works fine)

protected void LinkButton1_Click1(object sender, EventArgs e)


        string zupa1;

        zupa1 = ddlSelectEmployee.SelectedValue;





Add an empty line in Gridview on specific dayofweek


Hey all,

Havin quite a bit of trouble with this one.  I have a bunch of days that I worked in my database...mostly monday-friday and some saturdays.  What I want the gridview to do is add an empty line between each sunday and monday so that it seperates out my work weeks and makes it easier to read in the gridview.  I got some help here a few days ago on how to clone the db etc and I have all that working properly but I can't seem to wrap my head around how to do add these empty lines in the proper spots.  Here is my code so far:

private DataTable AddEmptyRow()
        DataTable originalDataTable = GetItems();
        DataTable newDataTable = originalDataTable.Clone();
        DateTime testdate = Convert.ToDateTime("7/20/2010");

            for (int i = 0; i < originalDataTable.Rows.Count; i++)
                DayOfWeek day = testdate.DayOfWeek;

                if (day == DayOfWeek.Sunday)
                    DataRow newDataRow = newDataTable.NewRow();



jquery datepicker not popping up in Gridview Edit Template textbox


I have a gridview that I can't for the life of me get the datepicker calender to pop up for.  I've been using the datepicker for months very successfully for a variety of textboxes on the page and inside of formviews but this is the first time I've tried using with gridview.  I didn't expect any issues however can't seem to find anything to work.  I have searched the forums for 2 days and attempted any suggestions found within the solutions to no avail.  I've tried using the CSS to link the datepicker but everything stopped working when I changed the code and my page which uses a css style already got all distorted looking.  Please help!

Here is my gridview (only included a part b/c it is large and am only having problem with the datepicker for the date completed text box)

<asp:GridView ID="GridViewCompleted" runat="server" AllowPaging="True" AllowSorting="True"
        AutoGenerateColumns="False" BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid"
        BorderWidth="3px" CellPadding="4" DataKeyNames="job_id" DataSourceID="SourceJobProjectCompleted"
        ForeColor="Black" CellSpacing="2">

Dynamically creating Gridview Template - Linkbutton Click not working



I have written some code to dynamically generate template columns for gridview which works well. However, each cell in the gridview has to be a linkbutton, which when clicked does a db update and redirects to a specific url with some parameters in it.

I have attached a click event handler to the linkbutton in the InstantiateIn method but the event does not seem to fire.

Could someone please help? the code is below -

//Dynamically creating the Grid

protected void btnAnalyze_Click(object sender, EventArgs e)

How to export gridview to excel template

I have a gridview that I need to export to Excel. Excel is not installed on the server, but I would like to put a template on the server so that when the user exports the data it will use the template and open the file on the user's local machine. To make things slightly more complex, I need to export the data to Sheet2 because Sheet1 needs to be a graph (thus the need for the template). I cannot use any third party software and I have no ability to modify anything on the server. This is used in a corporate environment on a shared server that I don't have any control over. Any sample code would be very helpful. I'm running ASP.NET 3.5 with Visual Studio 2008.

Footer and Header in Empty GridView

How to make GridView to show Header and Footer when it hasn't got any rows?

Is possible...? set enter key button for gridview footer template..

http://geekswithblogs.net/dotNETvinz/archive/2009/06/04/adding-dynamic-rows-in-gridview-with-textboxes.aspxI have used the above grid view in my application . Its working good, no problem. Upon clicking the Addnewrowbutton, it uses to create a new row dynamically. What i need is, new row should also be created dynamically, upon pressing enter key in the last textbox on a particular gird view row.  User always can't go and click addnewrowbutton every time to create new row. Instead of it, user can press enter in the last textbox on a particular grid view row to create new row. Hope you guys have understood. Please Note: Here I have used master page.

Referencing a linkbutton which is within a formview which is within a gridview template

Hello forum.  I have a gridview (gridview1) which contains a formview(formview1) which formview contains a linkbutton(linkbutton1).  I'm trying to  get the linkbutton's click event to redirect to page2 with a querystring value that's the linkbutton's text value. Something like this:   Response.Redirect("~/Page2.aspx" + "?" + "E=" + LinkButton1.Text)How do I reference LinkButton1's text value in code behind so I can pass it to Page2 through the query? Thank you  

Gridview with a linbutton in the template field

hi,i have a gridview as follows,<asp:GridView  runat="server" ID="gvPO"  AutoGenerateColumns="False"   >    <Columns>                    <asp:TemplateField HeaderText="PO No."><ItemTemplate>       <asp:LinkButton ID="lnkPo" runat="server" Text='<%#Eval("Purchase_order_no") %>' ></asp:LinkButton>   </ItemTemplate></asp:TemplateField>              </Columns>   </asp:GridView>The linbutton shows  Purchase_order_no.  When i clicked on a paricular purchase_order_no., it will navigate to another page with a gridview that shows details of that particular Purchase_order_no..... Pls help

gridview item template

Hi, I have a gridview which the columns are created programmatically.When a button is click i will clear all columns and add the columns that I want. Im adding a boundfield which is not a problem. When I add a template field, I must add also the item template which is my problem.How can I add a item template in the template field I created which is binded in my datasource. Also what event handler should I use to do this.Here's the part of my code:Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click GridView1.Columns.Clear() Dim en As New BoundField en.HeaderText = "Employee Number" en.DataField = "Employee Number" GridView1.Columns.Add(en) Dim n As New TemplateField n.HeaderText = "Name" GridView1.Columns.Add(n) AccessDataSource1.SelectCommand = "Select * from Employee" GridView1.DataBind() End Sub Someone know how can  I bind a label item template from the datasource. The label item template should be firstname + middlename + lastname.If im not doing it programatically, it will be just concatenating eval(). But how can create item template and bind it programmatically??.

Creating dynamic template columns in gridview

how to create dynamic template columns in gridview  . I have writing some of the code but it gives me error The type or namespace name 'GridViewLabelTemplatecould' not be found (are you missing a using directive or an assembly reference?)    I have paste some my code /con.Open();        string strsql = "select ID,CompanyName from tblcompany";               SqlCommand cmd = new SqlCommand();        cmd.CommandType = CommandType.Text;        cmd.CommandText = strsql;        cmd.Connection = con;        SqlDataAdapter adpt = new SqlDataAdapter();        adpt.SelectCommand = cmd;        adpt.Fill(dt);        GridView1.Columns.Clear();        for (int i = 0; i < dt.Columns.Count; i++)        {            TemplateField tf = new TemplateField();            // create the data rows       

Gridview Template...not overriding CSS style?

I have a web application that has a CSS file for all the style in the web application.  I just added a gridview to the page, and I chose one of the predefined templates.  But the template specifications don't show up, instead my CSS styles do (for example, table background).  How can I override the CSS styles and show the actual template styles for the gridview?Thanks in advance. :)

Dropdown select message in item template gridview dropdwon list ???

Hi ....I have used gridview item template , which has two dropdown list .The first dropdown list is binded from database to the dropdown list I have using the below code , to show the select message in dropdown list before selecting any item from dropdown list.In first row its show me --Select-- message and my vaues.. if i select some value form dropdownlist and click add new button it will create a new row dynamic then in previous row again it come back --Select-- message... on going to second row....I need to remain first row user selected value on going to next row.The New row will show --select-- message..Please go to my code and let me know what to do<asp:DropDownList id="DropDonList2" tabIndex=11 runat="server"          OnSelectedIndexChanged="DropDonList2_SelectedIndexChanged" AutoPostBack="True"          DataTextField="SizeRange" DataValueField="SizeRange"          OnDataBound="DropDonList2_DataBound" __designer:wfdid="w10"          AppendDataBoundItems="True">  <asp:ListItem Value="-1">Select</asp:ListItem> </asp:DropDownList><asp:DropDownList id="DropDonList2" tabIndex=11 runat="server" 

Calculating total of template textbox inside gridview



I have been asking this for a long time.But the answer what i get is not want i need.I have a  gridview with two template text box (t1 and t2) inside gridview and four textboxes outside the gridview on the form (txt1,txt2,txt3,txt4).All these textboxes allow only integer value to be entered.What i need is to get the total of all these textboxes (ie,template textboxes as well as textboxes outside gridview) in a textbox named Total at the same time we enter values in a textbox.Also if i change the value of a textbox later that too should be reflected in the Total textbox .I know how to calculate the total of the textboxes outside the gridview.But i need the total of all textboxes including template as well as textboxes outside simultaneously

Pls help and thanks in advance

GridView empty rows.


I bind data to GridView from SqlDataSource. GridView have <19 rows. But i want that all 19 rows are written. If Rows in SqlDataSource are empty it's must be empty in GridView but must be there!

Ajax, Smart Parts(web part w/ ajax support), User Control, and a GridView


So I am playing around with a user control that I created that adds some functionality to a SPList. I have scoured the web looking for a way to get a web part that had a gridview with custom buttons that is bound to certain Items in a sharepoint list. I found Smart Parts and created an Ajax enabled User Control. the problem is that the label is updating but the gridview is not. and on a site note how can I format the Time on Board column to not include milliseconds(the fields are showing up like '1.02:48:31.8633636') i just want 1.02:48 and maybe the 31:

here is my ascx:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AlertControlWebPart.ascx.cs"
  Inherits="AlertControlWebPart.AlertControlWebPart, AlertControlWebPart, Version=, Culture=neutral, PublicKeyToke

Up and Down arrows support for GridView inside a PopupControl Extender


Hi All,

I am a newbie ++ ;) so please be kind.

I have a grid view that is inside a popupcontrol extender. shown when clicked on a textbox or written something. when the textbox is shown i cannot use up and down arrow keys to move down or up and select a row when pressed enter or tab.


Please help me here I am stuck... I have searched thoroughout the forum not finding the solution or finding that is not working for me!

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend