.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

how to Freeze specific columns in GridView

Posted By:      Posted Date: August 31, 2010    Points: 0   Category :ASP.Net
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  

View Complete Post

More Related Resource Links

Hierarchical gridview with freeze columns



I want to make a hierarchical gridview with 1 freeze column.

can any body tell me how can i do this ?

i have freeze a column in general gridview but it was not working on internet explorer 8.

Please help me.

Adding Multiple Columns and Rows in GridView without using a Database

This article describes on how to add multiple columns and rows in GridView without using a database. Basically the GridView will be populated with data based on the values entered in each TextBoxes on Button Click and retain the GridView data on post back.

add columns with textboxes in gridview using C#

'm working on a shopping cart in a website and I have my items(which have been added to the cart) in an arraylist. And using these values I've read the rest of the values from the db and and have populated on the gridview successfully.

Sorting GridView Columns Manually

We all know that GridView columns can be sorted automatically when SQLDataSource is being used. But what if you are not using SqlDataSource to populate the GridView. Sorting the GridView manually is pretty straight forward task take a look at the code below

How to let user edit selected gridview columns, not entire row



I've got a gridview I would like to let the user edit a couple of columns.  Seems like everything I'm coming across so far makes the entire row editable.  

Hopefully the solution isn't too complicated.  Can someone point me in the right direction?


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



gridview help on each dynamic row solve this show values based on all columns

<asp:GridView style="Z-INDEX: 101; LEFT: 1px; POSITION: absolute; TOP: 183px" id="Gridview1" runat="server" Width="613px" Height="127px" ForeColor="Teal" Font-Size="12pt" Font-Names="Palatino Linotype" Font-Bold="True" Visible="False" BorderColor="Transparent" AutoGenerateColumns="false" CellSpacing="2" GridLines="None" OnRowCreated="Gridview1_RowCreated" SelectedIndex="5" ShowFooter="true" OnRowDataBound="Gridview1_RowDataBound"><Columns>  <asp:TemplateField HeaderText="ItemCode"><ItemTemplate> <asp:DropDownList id="DropDownList1" tabIndex=16 runat="server" AutoPostBack="True" DataValueField=" ItemCode " DataTextField=" ItemCode" ></asp:DropDownList></ItemTemplate></asp:TemplateField>  <asp:TemplateField HeaderText="ItemName"><ItemTemplate> <asp:DropDownList id="DropDownList2" tabIndex=16 runat="server" AutoPostBack="True" DataValueField="ItemName" DataTextField="ItemName" ></asp:DropDownList> </ItemTemplate> </asp:TemplateField>  <asp:TemplateField HeaderText="Category"&

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

DataGridView freeze columns issue

When i try to freeze a column that is off screen (to the right) when the DataGridView's (DGV) first displayed column is the first column in the DGV, the DGV refreshes and displays the DGV from the first column in the DGV. Also, the horizontal scrollbar on the bottom of the page disappears.  This means that i cannot see the unfrozen columns and i cant get over to view the column that I froze. This seems to behave differently from freezing a column in Excel, which freezes the columns you are currently viewing at that moment (not sending you back to the first row) and then the scroll bar applies to the frozen columns like normal. Is there a workaround for this? I tried setting the first displayed index for the column and I get an exception. I'm using .NET 3.5 on an XP machine.

AutoFilter GridView columns

Are there any good tutorials out there for making a GridView filterable by column within the GridView? For an example of what I mean, consider the jqGrid plugin. http://www.trirand.net/demoaspnet.aspxI don't understand why the native MS GridView has never been updated to include functionality like this... 

Insert the results of a stored procedure into specific columns

Hello, I'm trying to update a table with values from a stored procedure. Here is what I've got: Open My_Cursor DECLARE @username varchar(200), @add1 varchar(200), @add2 varchar(200), @city varchar(200), @st varchar(200), @zip varchar(200) Fetch NEXT FROM MY_Cursor INTO @username WHILE @@FETCH_STATUS = 0 BEGIN insert into sheet1$ (f19,f20,f21,f22,f23) EXEC [dbo].[GetPrimaryEEsAddress] @dependentUsername = @username WHERE username = @username FETCH NEXT FROM MY_Cursor INTO @username END Getting error: Msg 156, Level 15, State 1, Line 11 Incorrect syntax near the keyword 'WHERE'.

Insert columns into GridView and rendercontrol error

Hi I´m inserting columns into a gridview at run time using: gvRageReport.Columns.Insert(index, column) When I render the gridview in orther to export to excel all the excel columns are empty except the new insert columns, but when I add the new columns using gvRageReport.Columns.Add(column) the excell is exported successfully.Any idea?

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

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?

Want to show FormView in Edit mode with specific table columns depending on their Genre??

hi, I have  a table in my database called "Profiles". This holds data on Female and Male personal characteristics. On my aspx, I have a formview in edit mode which is binded to an object data source with a GetDataByUserId Select method which retrieves data from the "Profiles" Table via a DAL. The "Profiles" table has some columns which relates to females only and some just males and some are generic to both. See example below     UserId - / of Type GUID GenreId /  of Type BOOL. Hip Size (For females) Dress Size ( For Females) ChestSize (For Men ) TrouserSize (For Men) Weight ( For both )   When the User logs in , they go to an update Page which has the Formview in Edit Item Mode and contains drop down Lists which are binded to the Users Selected Value. The DDL are in turn bound to their related table such as HIP, Dress, Chest, Trouser etc. Objective If a female user logs in I just want to show them the (Hip Size) DDL  and DressSizeDDL in the Edit item template of the formview and not the ChestSize DDL or  TrouserSize DDL. At present the GetProfileByUserId returns all colums from the table My question is how do I do this and just show DDL which are relevant to the Female or Male Only. In some cases the user may not have selected an item in the previous form so they could also be

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

have print friendly page, want to hide columns of gridview

using vb.net/asp.net 2005I have linkbuttons calling the javascript function at the bottom of this post to print out the contents of a div and this is working ok but theissue that i have is inside the div is a gridview that displays links and another text column (among other colums) and I would like tohide the links and the text column next to it using css.Has anyone done this?btw, here is the javascript print function# function printThisDiv() # { # try{ # var sOption="toolbar=yes,location=no,directories=yes,menubar=yes,"; # sOption+="scrollbars=yes,width=750,height=600,left=100,top=25"; # # var sWinHTML = document.getElementById('dvTheDivIWantToPrint').innerHTML; # # # var winprint=window.open("","",sOption); # winprint.document.open(); # winprint.document.write('<html><body>'); # winprint.document.write(sWinHTML); # winprint.document.write('</body></html>'); # winprint.document.close(); # winprint.focus(); # # }catch(err){ # txt="There was an error on this page.\n\n"; # txt+="Error description: " + err.description + "\n\n"; # txt+="Click OK to continue.\n\n"; # alert(txt); # } }
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