Click here to Skip to main content
15,890,527 members
Everything / Gridview

Gridview

Gridview

Great Reads

by Herre Kuijpers
Extending the standard ASP.NET GridView control to add a vertical scrollbar in the grid
by OriginalGriff
When I add a log reader, the size of the log can be huge, and get very slow to view. This makes the GridView do all the work of paging the data for you.
by Don Hoang
This post describes implementing ASP.NET Gridview using Bootstrap 4.
by Razi Syed
Easily bind a class to .NET data controls like GridView, FormView, etc., and get an updated object or list back in the code-behind effortlessly.

Latest Articles

by Telegram:@ArastoAhmadi
Tutorial to monitor database changes without using tools and by using a simpler trick
by Herre Kuijpers
Extending the standard ASP.NET GridView control to add a vertical scrollbar in the grid
by Don Hoang
This post describes implementing ASP.NET Gridview using Bootstrap 4.
by SagSD
Bootstrap pagination for gridview with CSS only

All Articles

Sort by Updated

Gridview 

7 Dec 2010 by #realJSOP
Three seconds for SQL Server to return a dataset is a LONG time. The more records you have, the longer everything is going to take, and that means binding as well.
17 Dec 2010 by #realJSOP
Do you update it by re-retrieving the data, or by manually setting properties in the contained items?Would it help to make the collection an ObservableCollection and binding to that?Are you adding/deleting entire rows?
17 Dec 2010 by #realJSOP
Try putting a try/catch block around the code, and then just eating the exception, and see if that at least makes the code run without interruption.If it's an index out of range exception, find out what index it's talking about and try to resolve it.
15 Jul 2011 by #realJSOP
If all of your data will fit in available memory, you could retrieve all of the data you need to display, and then extract only the items that will fit in a page. Psuedo code:0) retrieve data 1) Calculate number of pages you have - Math.Min(1, Math.Floor(records_retrieved /...
27 Mar 2018 by #realJSOP
Google is your friend. Pivot C# Array or DataTable: Convert a Column To a Row with LINQ - TechBrij[^]
2 Jul 2019 by #realJSOP
You can't do it with default parameters (for an array), but you can do it with an overload: public bool MyMethod() { string[] value = new string[] { "Id", "DataModified" }; return MyMethod(value); } public bool MyMethod(string[] value) { // do something with the string array ...
1 Dec 2021 by #realJSOP
Looks to me like the gridview is taller than the window. Your problem is only indirectly related to the grid being filled.
23 Jun 2014 by .Net Dada
Hi Everyone,I am using one ascx control of gridview from where i can use it in multiple pages.Now the issue is:I have an additional control in gridview and after binding i am checking the condition and make that control visible true or false on every row.It is binding and...
11 Sep 2014 by /\jmot
DataTable dt1 = new DataTable();dt1.Columns.Add("SiteName", typeof(string));dt1.Columns.Add("State", typeof(string));dt1.Columns.Add("Cluster", typeof(string));for (int i = 0; i
25 Oct 2014 by /\jmot
Try this..this will help you, i worked with it..working fine..foreach (GridViewRow row in gvItems.Rows){String Str=Convert.ToString(((TextBox)row.FindControl("TextboxID")).Text);}If this one not helping you, then place your code here, which's not working..or be more...
9 Dec 2014 by /\jmot
See here..http://www.aspsnippets.com/Articles/Exporting-Multiple-GridViews-To-Excel-SpreadSheet-in-ASP.Net.aspx[^]
10 Dec 2014 by /\jmot
what about this??function fcheck(index) { var index = index; $(this).find("#gridstudent_lblname_"+index).val("changedata");}
5 Dec 2011 by 07navneet
Similar type of problem but this time for update/delete using stored procedures in gridview:
6 Dec 2011 by 07navneet
public void delete(object sender, GridViewDeleteEventArgs e) { int id = Convert.ToInt32(gv1.Rows[e.RowIndex].Cells[4].Text); SqlConnection conn = new SqlConnection(str_con); conn.Open(); SqlCommand cmd1 = new SqlCommand("DeleteInfo",...
6 Dec 2011 by 07navneet
I want to update in gridview using procedures.Code(.cs):-public void update(object sender, GridViewUpdateEventArgs e) { SqlConnection conn = new SqlConnection(str_con); conn.Open(); SqlCommand cmd1 = new SqlCommand("UpdateInfo", conn); ...
8 Dec 2011 by 07navneet
use 'ItemTemplate' of gridview and 'findcontrol' of textboxes!
3 May 2017 by 07navneet
8 Dec 2011 by 07navneet
in template field of columns you can specify--->ControlStyle-Width='size'
9 Dec 2011 by 07navneet
At Page Load I was simply calling BindData function but the technique was to call it when its not Postback!if(!Page.IsPostBack) BindData();
4 Dec 2012 by 09hadi
Hi, I have been trying to get this straight but the requirements changed and now I cant seem to get it working. I am getting Data from an access database, and in that data there is an attribute titled "LINK_STATUS" which is a binary column. The values are limited to 0 and 1. First I was tasked...
20 Feb 2013 by 09hadi
First add a hyperlink field to the gridview and then:Quote: if (e.Row.DataItem != null) { DataRowView drv = (DataRowView)e.Row.DataItem; string link_status = drv["link_status"].ToString(); if (link_status == "0") ...
22 Nov 2015 by 12045649
Hello Friends,. How to move(drag and drop) rows in form view control and update in database..Can any one please help me with this..
22 Jun 2011 by 2irfanshaikh
Its better you set the Cascade relationship between both the tables.So, when once you delete the primary key data it will delete the foreign key rows from the foreign table.
22 Jun 2011 by 2irfanshaikh
This error is because we are not getting the DorpdownList SelectedValue, when we click on the Update button. It returns NULL to us. That's why it shows below error.Cannot insert the value NULL into column 'CompanyID', table 'RealValue.dbo.tbl_BikePrcInfo'; column does not allow nulls. UPDATE...
5 Jul 2011 by 2irfanshaikh
i think this link [^] will help you
7 Jul 2011 by 2irfanshaikh
Please check the below linkhttp://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.templatefield.alternatingitemtemplate.aspx[^]AlternatingItemTemplate will help you.
8 May 2010 by 4277480
Sample table to explain the problem (EmployeeID,EmployeeName,ManagerID)In my item template of my gridView I have a dropDownList which binds as follows:When you choose dataSource I set EmployeeName to be the field that is being displayed and the EmployeeID for the value. Then in the Edit...
28 Feb 2015 by 8421441333
following is my code to bind gridview ,I had successfully Binded it with checkbox but now am not able to get checkbox change event of checkbox which is in the grid ,ahead i want to do calculation of 2 column in 3rd column of selected row.$.ajax({ type: "POST", ...
27 Oct 2014 by @shok kumar mishra
I am working on a grid-view having many thousand of data and many column and column names.It is not possible to remember the all the column names as per the column index.So What i need that to freeze the header of the grid-view which show the column Header Name and easily search the particular...
31 Oct 2014 by @shok kumar mishra
Hay Friends Thank u for your Answers. Now I Have the best solution for freezing the header of the grid view by simple way.Click On below Link to show how to freeze grid view headerhttp://www.dotnetwithashok.blogspot.in/2014/10/freeze-gridview-header-row-in-aspnet.html[^]
6 Jan 2011 by [DK]KiloDunse
I have a gridview that uses entitydatasource (EF4) to select, update and delete.I use dropdownboxes in some columns.In the RowUpdating method, I get the selectedvalue of the dropdownbox and check the value.If the value is "0" then I set the NewValue to be Null like this: ...
6 Jan 2011 by [DK]KiloDunse
Already is: /// /// No Metadata Documentation available. /// [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] [DataMemberAttribute()] public Nullable TestUserID { get { ...
7 Jan 2011 by [DK]KiloDunse
Found the problem.I did not bind the property too anything in the EditItemTemplate in the gridview. Therefore, the property TestUserID did not get in the gridviews "BoundFieldValues" collection.As a result, the property did not get updated by the EntityDataSource.
9 Aug 2012 by __TR__
I was also facing the problem of duplicate records getting saved when user double clicks on save button. So I tried the below approach. Here the JavaScript function "HideButton()" hides the save button when its clicked there by not allowing the user to click on it again. The button reappears...
14 Jan 2013 by __TR__
Try formating the date as shown belowSELECT REPLACE(convert(varchar, getdate(), 102),'.','/') --2013/01/15ReferSQL Server Date Formats[^]How to format datetime & date in Sql Server[^]
15 Jan 2013 by __TR__
You can use BoundField.DataFormatString Property[^] to specify the display format for the value of the field.
16 Jan 2013 by __TR__
Lots of CP articles on this topic.Here are a few Insert, Update, Delete with Gridview ... Simple Way[^]Insert, Update, Delete in ASP.NET Gridview, DataSource as SQL Server, MS Access (mdb/accdb), XML and Framework as 2.0 / 3.0 / 3.5 / 4.0 (VS 2005/2008/2010)[^]GridView all in...
30 Jun 2012 by _Amy
Hi,Here is a grate article on grouping header:Group GridView Data[^] http://www.csharpaspnetarticles.com/2008/11/merging-gridview-headers-to-have.htmlhttp://redsouljaz.wordpress.com/2009/06/12/create-multiple-row-group-header-in-gridview-asp-net/Follow the above link..You'll find...
10 Jul 2012 by _Amy
Hi,Set the command name to the buttion at parent gridview header as "CollapsAll". Handle "CollapsAll" command as follows:protected void gvEmpDetails_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "CollapsAll") { ...
13 Jul 2012 by _Amy
Hi,As I think only one modification can find your solution.Try this:string strEmail=stirng.Empty;foreach (GridViewRow rw in grid1.Rows) { CheckBox chkBx = (CheckBox)rw.FindControl("Check"); if (chkBx != null && chkBx.Checked) { ...
17 Jul 2012 by _Amy
Hi,Instead of this:e.Row.Attributes.Add("onmouseover", "this.originalcolor=this.style.backgroundColor;" + " this.style.backgroundColor='#FDCB0A';");e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.originalcolor;")Try this:if(...
17 Jul 2012 by _Amy
Hi, Refer the links below:http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sorting.aspx[^]Sorting and Paging of an Generic GridView[^]Userful GridView ASP.NET[^]GridView Paging and Sorting[^]--Amit
24 Jul 2012 by _Amy
Hi,Your query seems to be perfect. Just try using this:protected void DeleteRecord(object sender, GridViewDeleteEventArgs e) { string id = gridRegistrationTableDetails.Rows[e.RowIndex].Cells[0].Text; deleterecordMethod(id); BindData(); } private...
24 Jul 2012 by _Amy
Hi,Use this://Dropdownlist selected value changed event. This can be done on button click event also.protected void DropDownList1_SelectIndexChanged(object sender, EventArgs e) { gvSorting.Sort(DropDownList1.SelectedValue, SortDirection.Ascending); ...
3 Aug 2012 by _Amy
In this case you can remove the columns by using DataTableCollection.RemoveAt function in front-end or you can limit the number of columns in database itself.I'll suggest you to go through following links:A Practical Guide to .NET DataTables, DataSets and DataGrids - Part 2[^] MSDN :...
3 Aug 2012 by _Amy
I can't help you through the code, because I have not seen the flow of your coding.In spite of that I can give you a little idea.Take a hidden field on the page and first time set is to 0. Definitely the last index will be +50 of the first index as you are telling that you are having 50 rows...
5 Aug 2012 by _Amy
Hi,I could have written the code which can solve you problem, but I would like to suggest you to read GridView Paging and Sorting[^]. This is a very nice article for the beginners.--Amit
6 Aug 2012 by _Amy
Hi,Add two more attributes, 1st remove the background color of particular cell on mouse hover and then add the previews background color on mouse out. Then only this parent style will work. Try this:protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e){ if...
8 Aug 2012 by _Amy
Hi,Check your Inherit & CodeFile attribute in the page directive. Remember your Inherit attribute should be the class name of code behind. There only you are missing something. Try tracing it out.'GridView3_RowDataBound' is not a member of 'ASP.webform3_aspx'This error occurs because of...
8 Aug 2012 by _Amy
Hi,Try this:window.open('../Test1.aspx', null, 'height=500, width=1100, status=no, resizable=no, scrollbars=yes, toolbar=no,location=no, menubar=no');[Edited]:, null,...
11 Aug 2012 by _Amy
Hi,MSDN is always provides the best articles and description about asp server controls. You should read this article step-by-step:MSDN : Table of Contents: GridView Examples for ASP.NET 2.0[^]You can also try this:ASP.NET GridView Control[^]--Amit
29 Aug 2012 by _Amy
Go to the RowCommand event of your GridView. Find the Button and change the text.Write the following in your RowCommand:Button btnMyBtn = (Button)e.Item.FindControl("btnMyBtn");btnMyBtn.Text = "New Text";--Amit
16 Sep 2012 by _Amy
Hi, Try this:HTML:(Inside the grid.) CodeBehind:protected void ddlInsuredTitle_SelectedIndexChanged(object sender, EventArgs e){ // Handle your event here}--Amit
1 Oct 2012 by _Amy
The below link demonstrates exactly what you need. You can refresh your gridview using AJAX Timer control. How to refresh GridView automatically using AJAX Timer[^]--Amit
4 Oct 2012 by _Amy
Your query seems to be good. There is no error in your coding. Just put a break-point in for loop, and try stepping through the codes. And check what value is coming for your CheckBox.Otherwise try this alternative:foreach(GridViewRow row in GridView1.Rows) { if(row.RowType ==...
10 Oct 2012 by _Amy
Hi,Write a simple linq query to get the values.As I assumed your DataTable is:1 Amit2 Test13 Test24 Test35 test4And your ID is:int[] id = new int []{ 1, 3, 5 };So your query should be something like this:var query = (from s in dt.AsEnumerable() ...
28 Jan 2013 by _Amy
If you want to open the file normally then you can use Response.Redirect(YourFilePath). And if you want to download the file then you can use the function below. Call the function in your RowCommand Event of GridView and pass the path of corresponding file. Try this:
28 Jan 2013 by _Amy
Are you talking about ]]> blocks?Refer the links below:Embedded Code and Inline Server Tags[^]A quick reference for the ASP.NET inline server tags[^] Hope it helps!--Amit
26 Feb 2013 by _Amy
A simple solution: use AutoGenerateColumns="True" and let the gridview to decide the number of columns dynamically.--Amit
27 Feb 2013 by _Amy
You can try using :MyGridView1.SelectedIndex = -1; But this is a server side code. You need to fire this on JavaScript page click event(Use __doPostBack( 'target', 'args')). Also check : How to use __doPostBack function[^].--Amit
19 Mar 2013 by _Amy
Loop through GridView Rows. Try this:protected void btn_3id_Click(object sender, EventArgs e){ string str = ""; string srr = ""; foreach (GridViewRow row in GridView1.Rows) { if (((CheckBox)row.FindControl("CheckBox1")).Checked) { if (str ==...
2 Jun 2013 by _Amy
Try using this Javascript:function FindElement(){ var grid = $find(""); var MasterTable = grid.get_masterTableView(); var length = MasterTable.get_dataItems().length; for (var i = 0; i
2 Jun 2013 by _Amy
It's obvious. Because your GridView is binding everytime on postbacks. If you are binding the GridView in Page_Load event, then check for postbacks. Bind your GridView under Not IsPostBack block. Try this:if(!IsPostBack){ //Bind your gridview here.}--Amit
12 Jun 2013 by _Amy
Try this:protected void btnSearch_Click(object sender, EventArgs e){ sqlcon = new SqlConnection(strconn); cmd = new SqlCommand("searchCriteriaSP", sqlcon); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@input", SqlDbType.VarChar)).Value...
27 Jun 2013 by _Amy
Try resizing your Column Width.HeaderStyle-Width="100px"See a similar thread : how to set width for templatefields in gridview in asp.net[^]--Amit
1 Jul 2013 by _Amy
Try search on Google[^] sometimes. I searched and got About 906,000 results (0.29 seconds). You can also try searching on Codeproject Articles[^] and Codeproject Questions and answer[^].Have a look at these similar threads and articles:Insert, Update, Delete with Gridview ... Simple...
22 Jul 2014 by _Amy
Why not Googled[^]?Try this:How to: Pass Values Between ASP.NET Web Pages[^]5 Ways to send data between ASP.NET Pages[^]Passing Value Between Pages in ASP.NET[^]    --Amy
31 Jul 2014 by _Amy
Follow the steps:1. Add the footer templates to gridview(i.e. Textbox, Dropdown and ImageButton). .... 2. Assign the CommandName Property of ImageButton to "Add". .... 3. Handle...
3 Dec 2013 by _Lovro_
I have very simple GridView as seen here called GridView1Inside of it I have dropdown list called DropDownList1
3 Dec 2013 by _Lovro_
For Each row As GridViewRow In GridView1.RowsDim dropDownListText As String = CType(row.FindControl("DropDownList1"),DropDownList).SelectedItem.ValueResponse.Write(dropDownListText)NextThis seems to be working but now I am 50% doneProblem is that now I dont know since there can be...
4 Dec 2013 by _Lovro_
I have a grid that looks like this and it has DropDownlist1 that populates data as seen here.When clicked on a button Update value from dropdownlist is stored to DB and thats fine.I want on a page load only for those values stored from dropdown list to select that particular value in...
24 Jan 2012 by _Maxxx_
So your drop down list shows just the lessons?Then when selected your grid shows the one lesson selected and all the dates?So you need to filter your lessonwithdate table to include just the dates for the lesson selected...Select date From lessonDate as LDInner join...
11 Aug 2012 by _Raj sinha
Try this link you will get all those things about gridview
19 Jul 2021 by _Starbug_
I want to design a custom gridview with image inside it. I fetch images from database and also other data. How can i do that? Thanks. below link is what i want to achive it. link What I have tried: I used asp.net toolbox control but i do not know how to implement image inside columns of it.
11 Oct 2011 by _Tushar Patil
Hi,Just Put all Controls On Update panel Except Cancel Button Which Will Close The Modal Popup.....
6 Jul 2012 by _Zorro_
Hi,You're talking about an Asp.Net GridView right?Take a look at this: http://forums.asp.net/t/1277793.aspx/1[^]Hope it helps.
20 Apr 2012 by A.Ebrahimi
As my question indicate, I need to show footer in empty gridview but when I put a checkbox and use imageurl with cast to get imageurl from code behind, it raise error, may anyone help me? Here is my code:
20 Apr 2012 by A.Ebrahimi
As I have found the main cause of this error is when table is empty then there is no value to pass to eval and it raise error. So change my question.
28 Jun 2012 by A.J Bosch
Hi thereI have this little problem as I am still VERY new to c# I need to show the total hours worked in the footer of my GridView and all the fields are auto generated cell no [7].INDX | CLIENTNAME | PROJECTNAME | NAME | DATE | START | END | HOURS_WORKED 1 | ME ...
2 Jul 2012 by A.J Bosch
honestly the best and easiest solution for me was to create a timediff field[TIME_SPENT] "datetime" and also a minutes field [MINUTES] as "int" in SQL then by running and update query protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) {if (e.CommandName ==...
8 Apr 2014 by a.pkumar
Hi,I need a grid with following Functionality->Freeze columns and first 2 rows->Cell click functionality and based on value in cell, open new window->totals in footer->if bulk data given also it should be fasterAre there any 3rd party controls or data grid's which full fill these...
21 Oct 2012 by a1mimo
here is the code for your problemprivate void button1_Click(object sender, EventArgs e) { foreach(DataGridViewRow Row in dataGridView1.Rows) { if (Row.IsNewRow) { } ...
6 Feb 2013 by a2ulthakur
this is the ccode i m using under gridview rowupdating event:protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { if (con.State == ConnectionState.Closed) { con.Open(); } int autoid =...
12 Feb 2013 by a2ulthakur
ok first of all make a function from which u will populate your gridview like this : public void show() { string str = "select * from table2"; SqlDataAdapter adp = new SqlDataAdapter(str, con); DataSet ds = new DataSet(); adp.Fill(ds); ...
29 Apr 2020 by aalhussein
Hi, I am using Modal popup extender to show a panel once I click on Button1 control as seen below. The code works fine. However, instead of using Button1 control as a target (TargetControlID="Button1"), I want to use another control inside...
11 Mar 2016 by aarif moh shaikh
Please follow below links.....Simple Insert Select Edit Update and Delete in ASP.Net GridView control[^]http://www.aspdotnet-suresh.com/2011/02/how-to-inserteditupdate-and-delete-data.html[^]Insert Update Edit Delete record in GridView using SqlDataSource in...
9 Aug 2012 by Aarti Meswania
this problem can be raised because save button's click event is firing twise.Refer this link, having same problem like you have,May it be useful to solve topicDouble data when saving[^]Happy Coding!:)
12 Nov 2016 by Aashish68
I need to display the gridview row value in the dropdownlist box and i have used the below code for the textbox but it doesn't work for the dropdownlist box.What I have tried:var row = $(this).closest('tr'); var ID = row.find("td:first").text(); ...
26 Jun 2013 by aasif iqbal
try this, change your field name according to your applicationBoundField colDescriptione = new BoundField();colDescriptione.DataField = "Description";colDescriptione.HeaderText = "Description";colDescriptione.SortExpression = "Description";this.oGrid.Columns.Add(colDescriptione);
14 Oct 2013 by abbaspirmoradi
see this:http://stackoverflow.com/questions/18001632/enable-disable-link-buttons-in-gridview-depending-on-condition[^]and http://go4answers.webhost4life.com/Example/disable-link-button-grid-view-clicked-98536.aspx[^]
1 Dec 2013 by abbaspirmoradi
Look at this article:http://www.aspdotnet-sharepoint.com/2011/12/link-button-in-gridview-in-aspnet.html[^]
19 Jul 2013 by ABCPQR001
try thesehttp://www.aspsnippets.com/articles/print-functionality-in-asp.net-gridview-control.aspx
4 Aug 2016 by abdujalilc
This c# code works fine in wpf framework.Now I need this code in asp.net.I am using GridView instead of DataGrid.What changes do I have to do?Here is my c# code:DataRowView SelectedRowValue = (DataRowView)dataGrid1.SelectedValue;byte[] ImageBytes =...
11 Nov 2010 by Abdul Quader Mamun
C# if (Session["YourSessionName"] !=null) { }VB.NET If Not Session("YourSessionName") Is Nothing Then End IF
23 Oct 2011 by Abdul Quader Mamun
Thank you for your question,You can use DataFormatString property. You can follow the bellow simple:http://msdn.microsoft.com/en-us/library/ms993231.aspx[^]Thanks,Mamun
8 Mar 2012 by abdul samathu
I have a doubt here, and I need your helpI have a aspx page and in that page am collecting the information form the users and am storing the information to the list, and I bind the list to the gridview as its datasource...my question is how can we delete the rows in the gridview, whose...
13 Mar 2012 by abdul samathu
I have a list List persons=new List();in this list I have records for two persons. If I add a new record in that list it shows only the new record, not the existing records.but in the (!postback) section when I bind the list to the gridview it shows that two existing records, but...
17 Apr 2012 by abdul samathu
I've created a Dictionary like Dictionary dict= new Dictionary();here Department is a class and I have `DepartmentId,Name and Code` for the departments. And in the `bool` am sending whether the person is `HOD` or not.Am adding the records to this...
14 Aug 2016 by abdul subhan mohammed
try thisprotected void GridView1_RowEditing(object sender, GridViewEditEventArgs e){ GridView1.EditIndex = e.NewEditIndex; FillGrid();}