473,395 Members | 2,253 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 2257
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(object sender, System.EventArgs e)

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

if (Session["Data"] == null )
GetData();
else
{
ds = (DataSet)Session["Data"];
DataGrid1.DataSource = ds.Tables[0].DefaultView;
DataGrid1.DataBind();
}
}

private void GetData()
{
SqlConnection Conn = new SqlConnection(ConnStr);
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.ToString() ,Conn );
sda.Fill(ds,"First");
Session["Data"] = ds;
DataGrid1.DataSource = ds.Tables[0].DefaultView;
DataGrid1.DataBind();
}

private void Button1_Click(object sender, System.EventArgs e)
{
GetData();
}


"Lee Price" <an*******@discussions.microsoft.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
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
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...
0
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...
1
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...
1
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...
1
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...
1
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...
6
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
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.