|
-
May 13th, 2004, 02:44 AM
#1
Thread Starter
Frenzied Member
Clearing the data from a datagrid.[Really Resolved]
I have multi data grids on the same page/user control and I swap them out. One is a normal view and one is a search results view. I want to empty them when ever they are not displayed because they are rebound on every display anyway.
What I am going to try right now is setting the data source to null and DataBinding the grid again. I am thinking this will cause an error though. Does anyone know of a way to do this?
Thanks in advanced.
Last edited by Magiaus; May 18th, 2004 at 03:29 PM.
Magiaus
If I helped give me some points.
-
May 13th, 2004, 02:56 AM
#2
Thread Starter
Frenzied Member
well, no error but my grid won't rebind even when I set a new data source...... setting the view state to false and back to true is out too. It got faster too. A good bit. If only I could rebind still.
Magiaus
If I helped give me some points.
-
May 13th, 2004, 03:28 AM
#3
Thread Starter
Frenzied Member
nevermind I jusr forgot to rebind it after I cleared it. Thats what the flu and not resting enough do for you 
I set the data source to null and rebound.
Magiaus
If I helped give me some points.
-
May 18th, 2004, 11:53 AM
#4
Thread Starter
Frenzied Member
Not so Resolved after all. Made some changes to my UserControl. I added three functions LoadeData(int mode), ClearData(int mode), and Mode(int mode). Mode calls Clear and Load. The work fine except now if I set my Grid DataSource to null and then bind SQL Server gets lost somewhere and I can't rebind to anything.
I checked my code. All my connections get closed properly and nothing should be miss fireing. This isn't critical or anything but I wanted to try to get this site as lite as possible because most of the people using it are in China on dial-up. So it needs to be lite. The User Control has two grids I need to keep clean. I'm going to post my code since it doesn't show a ConnectionString.
Magiaus
If I helped give me some points.
-
May 18th, 2004, 11:59 AM
#5
Thread Starter
Frenzied Member
code
It is way to much code to post it all. So here is the key to everything. It's kind of like a console app. Well a little.
Code:
private void ClearViewState(int mode)
{
switch(mode)
{
case 0: // main grid
// txt_productSearchKey.Text = "";
// dg_products.DataSource = null;
// dg_products.DataBind();
break;
case 1: //edit
txt_productName.Text = "";
txt_productDescription.Text = "";
break;
case 2: //delete
break;
case 3: //add production
break;
case 4: //add source
break;
case 5: // search results grid
// dg_productSearchRes.DataSource = null;
// dg_productSearchRes.DataBind();
break;
default:
break;
}
}
private void LoadData()
{
_countFrom = 0;
_currentPage = 0;
_mainGrid = true;
_mode = 0;
_pageCount = 0;
_searchKey = "";
_selectedGUID = "";
//bind the grid
_pageCount = ((int)Data.Helpers.SqlSequel.ExecuteScalar("SELECT COUNT(*) FROM Products", Data._.ConnectionString()))/10;
dg_products.VirtualItemCount = ((int)Data.Helpers.SqlSequel.ExecuteScalar("SELECT COUNT(*) FROM Products", Data._.ConnectionString()));
_countFrom = ((_currentPage) * 10);
Mode(0);
}
private void LoadData(int mode)
{
//get data from SQL Server
Data.Products.Product p;
switch(mode)
{
case 0:
dg_products.DataSource = new Data.Products.ProductCollection(10, _currentPage);
dg_products.DataBind();
break;
case 1:
p = new Data.Products.Product(_selectedGUID);
//load data to controls (not bind)
txt_productName.Text = p.Name;
txt_productDescription.Text = p.Description;
chk_production.Checked = p.IsProduction;
chk_source.Checked = p.IsSource;
chk_sold.Checked = p.IsSales;
//configure production link to view/add
if(p.IsProduction)
{
lnk_productionAddView.Text = "View Production Information";
}
else
{
lnk_productionAddView.Text = "Add Production Information";
}
//configure source link to view/add
if(p.IsSource)
{
lnk_sourceAddView.Text = "View Source Information";
}
else
{
lnk_sourceAddView.Text = "Add Source Information";
}
p = null;
break;
case 2:
p = new Data.Products.Product(_selectedGUID);
lbl_deleteProductName.Text = p.Name;
lbl_deleteProductDescription.Text = p.Description;
//fill in source info or say no info
if(p.IsSource)
{
//get data
//display the correct panel and data
pnl_deleteProductSourceInfoNoData.Visible = false;
pnl_deleteProductSourceInfoData.Visible = true;
}
else
{
//display the correct panel and data
pnl_deleteProductSourceInfoData.Visible = false;
pnl_deleteProductSourceInfoNoData.Visible = true;
}
//fill in production info or say no info
if(p.IsProduction)
{
//get data
//display the correct panel and data
pnl_deleteProductProductionInfoNoData.Visible = false;
pnl_deleteProductProductionInfoData.Visible = true;
}
else
{
//display the correct panel and data
pnl_deleteProductProductionInfoData.Visible = false;
pnl_deleteProductProductionInfoNoData.Visible = true;
}
p = null;
break;
case 3:
break;
case 4:
break;
case 5:
_searchKey = txt_productSearchKey.Text;
this.dg_productSearchRes.DataSource = new Data.Products.ProductCollection(_searchKey);
dg_productSearchRes.DataBind();
break;
default:
break;
}
}
private void Mode(int mode)
{
//track the mode we are in and keep viewstate as lite as we can
ClearViewState(_mode); //clear last mode
_mode = mode; //and set the new one
//hide everything except the back to nav links
pnl_productSearchResults.Visible = false;
pnl_addProduction.Visible=false;
pnl_addSource.Visible=false;
pnl_deleteProduct.Visible=false;
pnl_editProduct.Visible=false;
pnl_backToMainGrid.Visible = false;
pnl_backToSearchResults.Visible = false;
pnl_products.Visible = false;
//make sure buttons stay locked
btn_deleteProduct.Enabled = false;
btn_saveProduct.Enabled = false;
//set the correct back nav link
if(_mainGrid && mode != 0)
{
pnl_backToMainGrid.Visible = true;
pnl_backToSearchResults.Visible = false;
}
else if(!_mainGrid && mode != 5)
{
pnl_backToMainGrid.Visible = false;
pnl_backToSearchResults.Visible = true;
}
else
{
pnl_backToMainGrid.Visible = false;
pnl_backToSearchResults.Visible = false;
}
//display the wanted area/mode/view
switch(mode)
{ //move to the correct mode
case 0: //grid data
_mainGrid = true;
dg_products.CurrentPageIndex = _currentPage;
_countFrom = ((_currentPage) * 10);
this.pnl_products.Visible = true;
break;
case 1: //edit data
this.pnl_editProduct.Visible = true;
break;
case 2: //delete data
this.pnl_deleteProduct.Visible = true;
break;
case 3: //add production
this.pnl_addProduction.Visible = true;
break;
case 4: //add source
this.pnl_addSource.Visible = true;
break;
case 5: // search results
//dg_productSearchRes.EnableViewState = true;
_mainGrid = false;
this.pnl_productSearchResults.Visible = true;
break;
default: //some weird call
break;
}
//fill in the modes data
LoadData(mode);
}
Magiaus
If I helped give me some points.
-
May 18th, 2004, 03:29 PM
#6
Thread Starter
Frenzied Member
I found the problem. I had changed my healper method ToDataReader and my connection wasn't being closed when I closed my Reader. Binding to null does clear the grid just fine.
Magiaus
If I helped give me some points.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|