.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

Add an empty line in Gridview on specific dayofweek

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

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();



View Complete Post

More Related Resource Links

Empty template support for GridView


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: #

Autoscroll down to a specific line on the webpage



I wonder about how this autoscroll is working on a page. For example when entering a page that I have set up named "test.aspx",

I want to 'autoscroll' down to a specific textrow that I have so that textrow exactly will be on the very top of the browser window.


I wonder how you do this task? Thanks! 

How to return back to a specific page in a gridview list?

Hello,  I have a gridview with paging. So for instance, I'm on say the page number 10, and I open the form details on a specific record_id (link). After I update/submit the form, it returns to page number 10. But, if I go to another page, for instance page 5, and submit the form, it returns to page 10. I've tried some things, for instance history.back(), but it returns to the first page I went to, in this case page number 10 (or whatever the first page I go to). Hopefully this code helps to understand what I'm asking: <asp:GridView DataKeyNames="Referral ID" ID="gvList" runat="server" CellPadding="4"     ForeColor="#333333" GridLines="None" OnRowCommand="gvList_RowCommand"     OnRowDataBound="gvList_RowDataBound" OnRowDeleted="gvList_RowDeleted"     OnRowDeleting="gvList_RowDeleting" AllowPaging="True" PageSize="20"     AutoGenerateColumns="False" OnPageIndexChanging="gvList_PageIndexChanging"    OnRowCreated="OnRowCreated" AllowSorting="True" OnSorting="OnSort"> protected void gvList_PageIndexChanging(object sender, GridViewPageEventArgs e)        {   &nb

how to Freeze specific columns in GridView

My question is how to freeze specifi columns of Gridview control ?Freeze means...for example say if we are freezing the first column of grid then on scrolling a horizontal scroll bar of the grid will scroll all columns other than the first column. That means the first column will be visible always without any movement. But the first column should move if we use the vertical scroll bar. thanks is advance satish  

gridview vertical line not coming

hi all, i have an Grdiview within that two table is there, one is for header another is for body section, now the horizontal line  is coming on the gridview but vertical line is not coming, below is my code <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"                             CellSpacing="1"  CellPadding="0" AllowPaging="True" PageSize="200"                             CssClass="searchResult" OnRowCommand="GridView1_RowCommand"                             OnRowDataBound="GridView1_RowDataBound"> <HeaderStyle CssClass="searchResultHeader" HorizontalAlign="Center"/><RowStyle BackColor="#ecf5ff" ForeColor="#333" Font-Size="11px" Height="30px"/>                     &n

Databind on Gridview throwing System.InvalidCastException. Specific Cast Not Valid

Hello, I am working on a web app where when the user enters data into a text box and presses a filter radio button it should filter the Gridview on the page to the criteria entered.  I have done this before in previous applications with the same code listed below, but for some reason I am now getting the InvalidCastExeption error.  Any help would be appreciated, the source database is SQL and the data field is set to nvarchar and I am using a string to compare as you will see in the code.  I am just unsure why this worked in the past and is not working in this scenario. Thanks, Pete protected void filterLName_CheckedChanged(object sender, EventArgs e) { SHCDataContext existingCustomers = new SHCDataContext(); var filterExistingCustomers = existingCustomers.Customers.Where(c => c.custLastName.Contains(lNameTB.Text.ToString())); displayCustGV.DataSource = null; displayCustGV.DataSourceID = null; displayCustGV.DataSource = filterExistingCustomers; displayCustGV.DataBind(); }   Here is the stack trace....  Specified cast is not valid. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.I

Footer and Header in Empty GridView

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

How to find specific nested object type in Gridview

Dears, I have a gridview with a nested placeholder in each rows. I nested some checkboxes in each placeholders in each rows dynamically, so their ServerIDs are not the same (I dont want to use nested gridview). at the end in a button event I want to count checked checkboxes in gridview while I can not use findcontrol() method in each rows to find checkboxes due to their different ServerIDs. How can I do this?

make onle specific cells in gridview as hyperlink

Dear all,   i have gridview and im displaying the employement history of employee. and im providing a hyperlink in empid to open employee page with update mode ..so that user can update the record. i have an issue here.only if the employeeresigned = "N" empid should be hyperlink, if its "Y" it should not be a hyperlink. How to do this.  <asp:TemplateField HeaderText="empid" SortExpression="empid">   <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" OnCommand ="empDetails_disp" Text='<%# Eval("empid") %>' CommandArgument='<%# Eval("empid", "{0}") %>' ForeColor="#0000C0"></asp:LinkButton> </ItemTemplate> </asp:TemplateField> am wondering how to do this 1) shall i replace all the linkbutton with label if the resignedstatus = "Y" - how to do this? 2) or shall i make the empid as boundfields instead of templatefields and write code on rowbound...with checkin that if resigned = "Y" then e.Row.Cells(0).BackColor = Drawing.Color.blue  e.Row.Cells(0).Attributes.Add("onclick", "empDetails_disp")  e.Row.Cells(0).Attributes.Add("class", "statusclass") ...... in this case i can use only javascript fu

Line chart with no breaks over empty values

I'm sure that I'm just missing a property but I can't find it.  I have a line chart with a contiguous range of dates on the X-axis.  If the series field has an empty value, I'd like to see the line plotted from the previous non-empty point to the next non-empty point rather than seeing a break in the line for that date.  Thanks in advance.Paul Turley, MVP [Hitachi Consulting] SQLServerBIBlog.com

Javascript code to copy specific cell of gridview row

Dears, I need a javascript code to copy the text content of a cell of a row in gridview. I have a button in each row that users click it and the text content a cell of that row should be copied in a textbox out of gridview

Print a specific Access Report with selected GridView record

I have my code output a gridview with all the data with an option to select records. I'm trying to make a code which would allow me to select a record, and then print this record using a specific Report stored in MS Access. I've located the code to print the Report it self, but it prints ether all the records or a range. Any ideas? 

Bind a GridView to a DataTable (in Viewstate) with full in-line CRUD


Hello fellow devs!

I need a bit of help with a scenario. I am working on a web application that requires huge amounts of data to be Added, Deleted, and Updated. The data entry forms are divided into logical groups through Multiviews. All the information is saved when the mighty Finish button is pressed. The current setup (previous developer) does not allow me to use transactions. Therefore, if I am to save a new Courier to the database, I need to add his/her Distance and Rate info. In addition, I need to add his/her Banned Areas info (Area Name, Post Code).

This is where it gets interesting. Obviously, the DistamceAndRate table and the BannedArea table in my SQL Server will have the CourierID as a foreign key. Since I'm going to save the Courier as well as the Rates and Areas info in one go, I cannot have the newly created CourierID before. Therefore, I cannot bind my Grids for Distance + Rates and Banned Areas directly to database.
What I am doing is creating two DataTables and managing them in Viewstate through properties as follow:

        private DataTable TableDistancesAndRates {
            get {
                object objTableDistancesAndRates = ViewState["vTableDistancesAndRates"];

                if (objTableDistancesAndRates!=null) {
                    return (DataTable)objTableD

how to show specific data label or legend in the line chart


I have a line chart with date (X axis) for average numbers. I wanted to show only one number for the month at the chart or legend area. But i can show or hide whole data labels. Is it possible to have an expression box in chart area?

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!

Gridview column line wrap question


I have a ASP.NET gridview (embedded into a DIV) with several columns. For some columns line wraps are definied and for some not(with ItemStyle.Wrap = true/false). For all columns ItemStyle.Width is set to a specific value. Now I am wondering, that there is a line wrap in a column, where ItemStyle.Wrap = false. What could be the reason for that?

Show column headers when gridview returns empty data set




I have in my code a gridview that I redirect to excel, it works fine when I have data in the data set. waht I want is to show column headers when there is no data right now what i get is empty sheet. 

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