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

Top 5 Contributors of the Month
david stephan
Gaurav Pal

Home >> Interview Question >> .NET Framework >> Post New Question Subscribe to Interview Questions

How to clear a datagrid on a button click?

Posted By :Shashi Ray     Posted Date :July 30, 2009    Points :10   Category :.NET Framework 
You need to Clear the DataSource of the dadaGrid.
So try this: dataSet1.Clear();
dataGrid1.DataSource = dataSet1.TableNameHere.DefaultView;
C#: dataGrid1.DataSource = null;
VB: dataGrid1.DataSource = nothing

You can also find related Interview Question to How to clear a datagrid on a button click?  below: 

In the page load event I assigned DropDownList's DataSource property to a valid list. On the submit button click.. the same DataSource property is coming as null. Why?

As ViewState is not storing the DataSource property.

We have to use Items property of DropDownList to get the items back. (More...)

How To Close Browser Window With Button Click?

btnClose.Attributes.Add("OnClick", "window.close();");


How To Allow Only One Button Click In Long Time Operations?

page load event .......
btnOnlyOnce.OnClientClick = @"if(this.value == 'Please wait...')
return false;
this.value = 'Please wait...';";

button click event
btnOnlyOnce.Text = "Long operation is finished";

Which method is used to generate the click event of the Control class for the Button control in C#?

The PerformClick() method of the Button class is used to generate the Click event of the System.Windows.Forms.Control class. (More...)

Difference between DataGrid, DataLsit and Repeater?

Difference between DataGrid, DataLsit and Repeater?


1) DataGird has a in-built Support for Sort, Filter, and Paging the Data.

2) Each Row in DataGrid is displayed as a row in the table.

3) It has an AutoGenarateColumn Property, which can be set to either True or False.
Default property is true.

4) DataGrid has predefined Editing Controls.

5)Following are the DataGrid Data Control Styles:

i. AlternatingItemStyle
ii. EditItemStyle
iii. FooterStyle
iv. HeaderStyle
v. ItemStyle
vi. SelectedItemStyle
vii. PagerStyle

6) Following are the DataGrid Data Control Templates(only supported by the TemplateColumna) :

i. HeaderTemplate
ii. ItemTemplate
iii. EditItemTemplate
iv. FooterTemplate (More...)

How to clear all rows of the GridView?

make DataSource as null.

GridView1.DataSource = null; (More...)

What's difference between Datagrid, Datalist and repeater ?

A Datagrid, Datalist and Repeater are all ASP.NET data Web controls.

They have many things in common like DataSource Property, DataBind Method ItemDataBound and ItemCreated.

When you assign the DataSource Property of a Datagrid to a DataSet then each DataRow present in the DataRow Collection of DataTable is assigned to a corresponding DataGridItem and this is same for the rest of the two controls also. But The HTML code generated for a Datagrid has an HTML TABLE element created for the particular DataRow and its a Table form representation with Columns and Rows.

For a Datalist it''''s an Array of Rows and based on the Template Selected and the RepeatColumn Property value We can specify how many DataSource records should appear per HTML row. In hort in datagrid we have one record per row, but in datalist we can have five or six rows per row.

For a Repeater Control, the Datarecords to be displayed depends upon the Templates specified and the only HTML generated is the due to the Templates.

In addition to these, Datagrid has a in-built support for Sort, Filter and paging the Data, which is not possible when using a DataList and for a Repeater Control we would require to write an explicit code to do paging. (More...)

How to decide on the design consideration to take a Datagrid, datalist or repeater ?

Many make a blind choice of choosing datagrid directly, but that's not the right way.

Datagrid provides ability to allow the end-user to sort, page, and edit its data. But it comes at a cost of speed. Second the display format is simple that is in row and columns. Real life scenarios can be more demanding that

With its templates, the DataList provides more control over the look and feel of the displayed data than the DataGrid.

It offers better performance than datagrid Repeater control allows for complete and total control. With the Repeater, the only HTML emitted are the values of the databinding statements in the templates along with the HTML markup specified in the templates-no "extra" HTML is emitted, as with the DataGrid and DataList. By requiring the developer to specify the complete generated HTML markup, the Repeater often requires the longest development time. But repeater does not provide editing features like datagrid so everything has to be coded by programmer. However, the Repeater does boast the best performance of the three data Web controls. Repeater is fastest followed by Datalist and finally datagrid. (More...)

What is the difference between Session.Abandon() and Session.Clear()?

The major practical difference is that if you call Session.Abandon(), Session_End will be fired (for InProc mode), and in the next request, Session_Start will be fired. Session.Clear( ) just clears the session data without killing it.

http://santoshdotnetarena.blogspot.com/ (More...)

What is the difference between Session.Clear() and Session.RemoveAll() method?

Well, actually there is no difference. Session.RemoveAll() methods internally makes a call to Clear() method only.

Thanks. (More...)

Suppose you want a certain ASP.NET function executed on MouseOver for a certain button. Where do you add an event handler?

Add an OnMouseOver attribute to the button. Example: btnSubmit.Attributes.Add("onmouseover","someClientCodeHere();"); (More...)

What is the difference between Session.Abandon() and Session.Clear()?

Session.Abandon() will end current session by firing Session_End and in the next request, Session_Start will be fire.

Session.Clear( ) just clears the session data without killing it. With session.clear variable is not removed from memory it just like giving value null to this session.

Session ID will remain same in both cases, as long as the browser is not closed. (More...)

what are the differences between Datalist DataGrid and datarepeater ?

*Has table appearence by default
*Has no autoformat option
*has no default paging & sorting options
*can define separators between elements using template
*Has a grid appearence by default
*has a autoformat option
*has default paging and sorting
*has no separator between elements
simple,read-only output, has no built in support for selecting or editing items, has no DEFAULT APPEARENCE,
has no default paging. (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.

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