473,611 Members | 2,236 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reset datagrid

Hi all,

I have a bound datagrid which is filled with data and
displayed.Now on the click of a button I need to refill
the datagrid with new data but the problem is the
datagrid mixes up the new data with the old data.

I have stored the data in a session variable which seems
to get updated although I am not altering the value of
the session variable

does binding a datagrid to a session variable update the
session variable also.

how do i reset my datagrid to take fresh values


Nov 18 '05 #1
1 2269
SMG
Dear Lee....
Please find the code attached with below, this might solve ur problem.
Steps to check: Once you load the page with data, refresh it (F5), then
change the data at the back end and again refresh you will see the changes
are not reflected, then click the button on the page it will get the fresh
data from the server.

Regards,
Shailesh MG

Code =============== =====
/* you should have a datagrid1 and button1 on the aspx page and the proper
connection string.
=============== ============
private void Page_Load(objec t sender, System.EventArg s e)

{
ConnStr = "server=ILDC1\\ SQLRND;initial catalog=Northwi nd;uid=sa;pwd=" ;
// Change this as per your need

if (Session["Data"] == null )
GetData();
else
{
ds = (DataSet)Sessio n["Data"];
DataGrid1.DataS ource = ds.Tables[0].DefaultView;
DataGrid1.DataB ind();
}
}

private void GetData()
{
SqlConnection Conn = new SqlConnection(C onnStr);
CommStr = new StringBuilder(" ");
ds = new DataSet();
CommStr.Append( " select P.ProductID, P.ProductName, C.CategoryName,
UnitPrice from products P, Categories C where ");
CommStr.Append( " C.categoryid = P.categoryid order by productName ");
SqlDataAdapter sda = new SqlDataAdapter( CommStr.ToStrin g() ,Conn );
sda.Fill(ds,"Fi rst");
Session["Data"] = ds;
DataGrid1.DataS ource = ds.Tables[0].DefaultView;
DataGrid1.DataB ind();
}

private void Button1_Click(o bject sender, System.EventArg s e)
{
GetData();
}


"Lee Price" <an*******@disc ussions.microso ft.com> wrote in message
news:4d******** *************** *****@phx.gbl.. .
Hi all,

I have a bound datagrid which is filled with data and
displayed.Now on the click of a button I need to refill
the datagrid with new data but the problem is the
datagrid mixes up the new data with the old data.

I have stored the data in a session variable which seems
to get updated although I am not altering the value of
the session variable

does binding a datagrid to a session variable update the
session variable also.

how do i reset my datagrid to take fresh values

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1168
by: Bill S. | last post by:
I have a DataGrid that I have populated. But I want to clear that Grid and Populate with another dataset. But I have not figured out how to clear the first set of data shown. Please help
1
2333
by: Schlauberger | last post by:
I have a form that has a Datagrid, there is a menu option that I use to toggle the Datagrid between two different data sources (x and y). As I continue to toggle the datagrid is duplication each data set x + x .. and y + y ... Is there a way to reset the datagrid? Current config: Private ds As DataSet = New DataSet
0
1009
by: Dave Bailey | last post by:
I have a DataGrid control on a WebForm called mrGrid. In this grid is a column named PRNUM. In addition there is another DataGrid on this WebForm named prGrid. It alson contains a column named PRNUM. When a user double clicks on a PRNUM in the mrGrid I want to be able to set the focus on the same number in the PRNUM column in the prGrid. Is this possible and how is it accomplished? Thanks,
1
8181
by: Joe Bloggs | last post by:
I have a form which includes a checkbox field. I need to add a reset, I add a HTML reset it works fine before I submit the form but not after. I know I must add some code to reset the checkbox on the onclick event of the reset button but I don't know what the code should be. Below is the HTML for the Data grid that has the check box and the code from the C# behind code for the reset button. If someone could point me in the right direction...
1
1984
by: ppn | last post by:
BlankHi, I have two datagrids on the form. When I click on the row in the first DataGrids, I want to reset the second datagrid before binding the dataset with new sql statement. I tried with dataset.clear(). It doesn't work. The columns are getting added to the existing columns for the second datagrid. Any help is appreciated. Thanks
1
1949
by: Simone | last post by:
After a call to the Reset() method of a DataTable and a call to the method Datasource of the datagrid for display data of the DataTable i cannot see the rows on the Grid. Help me please. By Simon.
1
1894
by: Simone | last post by:
After a call to the Reset() method of a DataTable and a call to the method Datasource of the datagrid for display data of the DataTable i cannot see the rows on the Grid. Help me please. By Simon.
6
2183
by: HB | last post by:
Guys, PLS tell me How to reset DataGrid to view DB updates? if I refill the dataset it double the records. Thanks HB
2
5220
by: Roger Withnell | last post by:
I need to reset a form to its original value using onclick rather than the Reset button. So, I have: <input type="button" name="reset" id="reset" value="Reset" onclick="form1.reset();"> where the id of my form is "form1". This gives the error "Object doesn't support this property or method". Please advise.
0
8149
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8097
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8561
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8240
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
4042
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4108
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2546
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1692
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.