473,386 Members | 2,129 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,386 software developers and data experts.

How to reset ba gridview content

WT
Hello,
I am trying to reset the content of mainy gridviews when some line is
selected.
All these gridviews have viewstate enabled

Using C# and asp.net, I try changing the datasource to null in the chnaged
even and do a DataBind but it has no effect the content seems to stay in the
viewstate ??
How to reset this display ?
Thanks
CS
Mar 28 '06 #1
3 9789
can I see the code to review?.......you are probably binding the data
again while loading the page i.e. some binding in page load event.

Mar 28 '06 #2
WT
I only bind all when not in postback ?
Here is the code
Thanks for help

/// <summary>

/// WTCRM Portal AddressManager module - Edit page part

/// Insert Cities, streets, street parts, sectors and micro sectors

/// </summary>

public partial class AddressManagerEdit : WTCRM.UI.AddEditImagePage

{
AddressManagerDB AdMan = new AddressManagerDB();
DataSet _Ds = null;

DataSet dsAddress

{

get

{

if (_Ds != null)

return _Ds;

try

{

_Ds = AdMan.GetDsAllAddresses();

}

catch (Exception ex)

{

System.Diagnostics.Trace.WriteLineIf(PageTraceSwit ch.Sw.TraceError,
string.Format("AddressManagerEdit dsAddress : ex : {0}", ex));

throw;

}

return _Ds;

}

}


/// <summary>

/// It then uses the WTCRM.AddressDB() data component

/// to populate the page's edit controls with the CRMImage details.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void Page_Load(object sender, System.EventArgs e)

{

if (!IsPostBack)

BindData();

}

void BindStreet()

{

DataView dv = new DataView();

int cityId = (int)GVCities.SelectedValue;

dv.RowFilter = string.Format("wt_CityId ='{0}'", cityId);

dv.Table = dsAddress.Tables["wt_Street"];

GVStreets.DataSource = dv;

System.Diagnostics.Trace.WriteLineIf(PageTraceSwit ch.Sw.TraceVerbose,
string.Format("AddressManagerEdit BindStreet : cityId : {0}, dv.Count:{1}",
cityId, dv.Count));

GVStreets.DataBind();

}

void BindCityStreet()

{

LBStreets.DataSource = null;

LBStreets.DataBind();

GVStreetParts.DataSource = null;

GVStreetParts.DataBind();

DVStreetPart.DataSource = null;

DVStreetPart.DataBind();

DataView dv = new DataView();

int cityId = int.Parse(string.IsNullOrEmpty(LBStreetCities.Sele ctedValue) ?
"0" : LBStreetCities.SelectedValue);

dv.RowFilter = string.Format("wt_CityId ='{0}'", cityId);

dv.Table = dsAddress.Tables["wt_Street"];

LBStreets.DataTextField = "wt_StreetName";

LBStreets.DataValueField = "wt_StreetId";

LBStreets.DataSource = dv;

System.Diagnostics.Trace.WriteLineIf(PageTraceSwit ch.Sw.TraceVerbose,
string.Format("AddressManagerEdit BindCityStreet : cityId : {0}", cityId));

if (LBStreets.Items.Count != 0)

{

if (LBStreets.SelectedIndex == -1)

{

LBStreets.SelectedIndex = 0;

}

}

LBStreets.DataBind();

}

void BindMicroSectorStreet()

{

GVStreetParts.DataSource = null;

GVStreetParts.DataBind();

DVStreetPart.DataSource = null;

DVStreetPart.DataBind();
DataView dv = new DataView();

LBMicroSector.DataTextField = "wt_MicroSectorName";

LBMicroSector.DataValueField = "wt_MicroSectorId";

dv.Table = dsAddress.Tables["wt_MicroSector"];

LBMicroSector.DataSource = dv;

System.Diagnostics.Trace.WriteLineIf(PageTraceSwit ch.Sw.TraceVerbose,
string.Format("AddressManagerEdit BindMicroSectorStreet : dv.Count : {0}",
dv.Count));

if (LBMicroSector.Items.Count != 0)

{

if (LBMicroSector.SelectedIndex == -1)

{

LBMicroSector.SelectedIndex = 0;

}

}

LBMicroSector.DataBind();

}

void BindStreetPart()

{

GVStreetParts.DataSource = null;

GVStreetParts.DataBind();

DVStreetPart.DataSource = null;

DVStreetPart.DataBind();

if (LBStreets.Items.Count != 0 && LBMicroSector.Items.Count != 0)

{

DataView dv = new DataView();

int streetId = int.Parse(string.IsNullOrEmpty(LBStreets.SelectedV alue) ? "0"
: LBStreets.SelectedValue);

int microSectorId =
int.Parse(string.IsNullOrEmpty(LBMicroSector.Selec tedValue) ? "0" :
LBMicroSector.SelectedValue);

dv.RowFilter = string.Format("wt_StreetId='{0}' AND wt_MicroSectorId='{1}'",
streetId, microSectorId);

dv.Table = dsAddress.Tables["wt_StreetPart"];

System.Diagnostics.Trace.WriteLineIf(PageTraceSwit ch.Sw.TraceVerbose,
string.Format("AddressManagerEdit BindStreetPart : streetId : {0},
microSectorId: {1}", streetId, microSectorId));

GVStreetParts.DataSource = dv;

}

GVStreetParts.DataBind();

}

void BindMicroSectorSector()

{

GVMicroSecteur.DataSource = null;

GVMicroSecteur.DataBind();

DVMicroSecteur.DataSource = null;

DVMicroSecteur.DataBind();

if (LBSector.Items.Count != 0 && LBSector.SelectedIndex != -1 )

{

DataView dv = new DataView();

int sectorId = int.Parse(string.IsNullOrEmpty(LBSector.SelectedVa lue) ? "0"
: LBSector.SelectedValue);

dv.RowFilter = string.Format("wt_SectorId = '{0}'", sectorId);

dv.Table = dsAddress.Tables["wt_MicroSector"];

System.Diagnostics.Trace.WriteLineIf(PageTraceSwit ch.Sw.TraceVerbose,
string.Format("AddressManagerEdit BindMicroSectorSector : sectorId : {0}",
sectorId));

GVMicroSecteur.DataSource = dv;

}

GVMicroSecteur.DataBind();

}

void BindViewStreetPart()

{

if (GVStreetParts.SelectedIndex == -1)

{

DVStreetPart.DataSource = null;

DVStreetPart.DataBind();

return;

}

DataView dv = new DataView();

int streetId = (int)GVStreetParts.SelectedDataKey["wt_StreetId"];

int side = (int)GVStreetParts.SelectedDataKey["wt_SideId"];

int numInf = (int)GVStreetParts.SelectedDataKey["wt_StreetPartNumInf"];

int sufinf = (int)GVStreetParts.SelectedDataKey["wt_SuffixInf"];

int numsup = (int)GVStreetParts.SelectedDataKey["wt_StreetPartNumSup"];

int sufsup = (int)GVStreetParts.SelectedDataKey["wt_SuffixSup"];

dv.RowFilter = string.Format("wt_StreetId = '{0}' AND wt_SideId='{1}' AND
wt_StreetPartNumInf='{2}' AND wt_SuffixInf='{3}' AND
wt_StreetPartNumSup='{4}' AND wt_SuffixSup='{5}'",

new object[] { streetId,side,numInf,sufinf,numsup,sufsup });

dv.Table = dsAddress.Tables["wt_StreetPart"];

DVStreetPart.DataSource = dv;

System.Diagnostics.Trace.WriteLineIf(PageTraceSwit ch.Sw.TraceVerbose,
string.Format("AddressManagerEdit BindViewStreetPart dv.Count: {0},
dv.RowFilter: {1}", dv.Count,dv.RowFilter));

DVStreetPart.DataBind();

}

void BindData()

{

try

{

// Prepare binding for View1

GVCities.DataSource = dsAddress;

GVCities.DataMember = "wt_City";

if (GVCities.Rows.Count > 0)

GVCities.SelectedIndex = 0;

GVCities.DataBind();

// Prepare Binding for View2

LBStreetCities.DataSource = dsAddress;

LBStreetCities.DataMember = "wt_City";

LBStreetCities.DataTextField = "wt_CityName";

LBStreetCities.DataValueField = "wt_CityId";

if (LBStreetCities.Items.Count > 0)

LBStreetCities.SelectedIndex = 0;

LBStreetCities.DataBind();

BindCityStreet();

BindMicroSectorStreet();

BindStreetPart();
// prepare binding for View3

LBSector.DataSource = dsAddress;

LBSector.DataMember = "wt_Sector";

LBSector.DataTextField = "wt_SectorName";

LBSector.DataValueField = "wt_SectorId";

if (LBSector.Items.Count > 0)

LBSector.SelectedIndex = 0;

LBSector.DataBind();

BindMicroSectorSector();

// final bind for all datas

//DataBind();

}

catch(Exception ex)

{

System.Diagnostics.Trace.WriteLineIf(PageTraceSwit ch.Sw.TraceError,
string.Format("AddressManagerEdit BindData : ex : {0}", ex));

return;

}

}

/// <summary>

/// Set the module guids with free access to this page

/// </summary>

protected override ArrayList AllowedModules

{

get

{

ArrayList al = new ArrayList();

al.Add("422546D3-CAFB-4805-B1B5-846634170B88");

return al;

}

}


/// <summary>

/// The UpdateBtn_Click event handler on this Page is used to either

/// create or update a CRMImage. It uses the WTCRM.CRMImageDB()

/// data component to encapsulate all data functionality.

/// </summary>

override protected void OnUpdate(EventArgs e)

{

base.OnUpdate(e);

// Only Update if Entered data is Valid

if (Page.IsValid)

{

// Redirect back to the portal home page

this.RedirectBackToReferringPage();

}

}

/// <summary>

/// The DeleteBtn_Click event handler on this Page is used to delete

/// a CRMImage. It uses the WTCRM.CRMImageDB()

/// data component to encapsulate all data functionality.

/// </summary>

override protected void OnDelete(EventArgs e)

{

base.OnDelete(e);

// Redirect back to the portal home page

this.RedirectBackToReferringPage();

}

public AddressManagerEdit()

{

}



#region Web Form Designer generated code

/// <summary>

/// Raises OnInitEvent

/// </summary>

/// <param name="e"></param>

protected override void OnInit(EventArgs e)

{

InitializeComponent();

base.OnInit(e);

}

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

protected void LBViews_SelectedIndexChanged(object sender, EventArgs e)

{

this.MultiView1.ActiveViewIndex = int.Parse(LBViews.SelectedValue);

}


protected void LBStreetCities_SelectedIndexChanged(object sender, EventArgs
e)

{

try

{

BindCityStreet();

if (LBStreets.SelectedIndex != -1)

BindStreetPart();

}

catch (Exception ex)

{

System.Diagnostics.Trace.WriteLineIf(PageTraceSwit ch.Sw.TraceError,
string.Format("AddressManagerEdit LBStreetCities_SelectedIndexChanged : ex :
{0}", ex));

return;

}

}

protected void LBStreets_SelectedIndexChanged(object sender, EventArgs e)

{

try

{

BindStreetPart();

}

catch (Exception ex)

{

System.Diagnostics.Trace.WriteLineIf(PageTraceSwit ch.Sw.TraceError,
string.Format("AddressManagerEdit LBStreets_SelectedIndexChanged : ex :
{0}", ex));

return;

}

}

protected void LBMicroSector_SelectedIndexChanged(object sender, EventArgs
e)

{

try

{

BindStreetPart();

}

catch (Exception ex)

{

System.Diagnostics.Trace.WriteLineIf(PageTraceSwit ch.Sw.TraceError,
string.Format("AddressManagerEdit LBMicroSector_SelectedIndexChanged : ex :
{0}", ex));

return;

}

}

protected void LBSector_SelectedIndexChanged(object sender, EventArgs e)

{

try

{

BindMicroSectorSector();

}

catch (Exception ex)

{

System.Diagnostics.Trace.WriteLineIf(PageTraceSwit ch.Sw.TraceError,
string.Format("AddressManagerEdit LBSector_SelectedIndexChanged : ex : {0}",
ex));

return;

}

}

protected void GVMicroSecteur_SelectedIndexChanged(object sender, EventArgs
e)

{

try

{

int microsectorId = (int)GVMicroSecteur.SelectedValue;

DataView dv = new DataView();

int sectorId = int.Parse(string.IsNullOrEmpty(LBSector.SelectedVa lue) ? "0"
: LBSector.SelectedValue);

dv.RowFilter = string.Format("wt_MicroSectorId ='{0}'", microsectorId);

dv.Table = dsAddress.Tables["wt_MicroSector"];

DVMicroSecteur.DataSource = dv;

System.Diagnostics.Trace.WriteLineIf(PageTraceSwit ch.Sw.TraceVerbose,
string.Format("AddressManagerEdit GVMicroSecteur_SelectedIndexChanged :
microsectorId : {0}", microsectorId));

DVMicroSecteur.DataBind();

}

catch (Exception ex)

{

System.Diagnostics.Trace.WriteLineIf(PageTraceSwit ch.Sw.TraceError,
string.Format("AddressManagerEdit GVMicroSecteur_SelectedIndexChanged : ex :
{0}", ex));

return;

}

}

protected void GVCities_SelectedIndexChanged(object sender, EventArgs e)

{

try

{

BindStreet();

}

catch (Exception ex)

{

System.Diagnostics.Trace.WriteLineIf(PageTraceSwit ch.Sw.TraceError,
string.Format("AddressManagerEdit GVCities_SelectedIndexChanged : ex : {0}",
ex));

return;

}

}

protected void GVStreetParts_SelectedIndexChanged(object sender, EventArgs
e)

{

try

{

BindViewStreetPart();

}

catch (Exception ex)

{

System.Diagnostics.Trace.WriteLineIf(PageTraceSwit ch.Sw.TraceError,
string.Format("AddressManagerEdit GVStreetParts_SelectedIndexChanged : ex :
{0}", ex));

return;

}

}

protected void GVStreets_RowUpdated(object sender,
System.Web.UI.WebControls.GridViewUpdatedEventArgs e)

{

System.Diagnostics.Trace.WriteLineIf(PageTraceSwit ch.Sw.TraceError,
string.Format("AddressManagerEdit GVStreets_RowUpdated : e : {0}",
e.AffectedRows));

}

protected void GVCities_RowUpdated(object sender,
System.Web.UI.WebControls.GridViewUpdatedEventArgs e)

{

System.Diagnostics.Trace.WriteLineIf(PageTraceSwit ch.Sw.TraceError,
string.Format("AddressManagerEdit GVCities_RowUpdated : e : {0}",
e.AffectedRows));

}

protected void GVStreetParts_RowUpdated(object sender,
System.Web.UI.WebControls.GridViewUpdatedEventArgs e)

{

System.Diagnostics.Trace.WriteLineIf(PageTraceSwit ch.Sw.TraceError,
string.Format("AddressManagerEdit GVStreetParts_RowUpdated : e : {0}",
e.AffectedRows));

}

protected void GVMicroSecteur_RowUpdated(object sender,
System.Web.UI.WebControls.GridViewUpdatedEventArgs e)

{

System.Diagnostics.Trace.WriteLineIf(PageTraceSwit ch.Sw.TraceError,
string.Format("AddressManagerEdit GVMicroSecteur_RowUpdated : e : {0}",
e.AffectedRows));

}

}

"Jiggs" <jd******@gmail.com> a écrit dans le message de news:
11**********************@e56g2000cwe.googlegroups. com...
can I see the code to review?.......you are probably binding the data
again while loading the page i.e. some binding in page load event.

Mar 28 '06 #3
Hi,

Thanks for your post!

For the current stage, my understanding is that you want to set the data
source to null for the GridView control by selecting some rows. If I have
misunderstood anything, please let me know.

From your code snippet, I have confusion about the current issue. The page
is derived from your customer class. I don't understand the logic of the
current page. Could you please give me more detail explanation or just make
a simple demo to describe the current issue. It will help me to understand
the issue clearly. Thanks for your understanding!

Regards,

Yuan Ren
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 29 '06 #4

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

Similar topics

1
by: PerryG | last post by:
We have a .NET 1.1 client which is sending a gzipped soap request using HttpWebRequest to an Apache server. The Apache server is using a the 'mod_deflate' server to decompress the incoming...
8
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my...
3
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
4
by: Jim Katz | last post by:
I have an application that updates a strongly typed data set at run time. I'd like to dynamically create a table that connects to a run time data table. For displaying the data, this works well. ...
5
by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to still be selected afterwards. This happens...
2
by: Jacksm | last post by:
How can I align an asp:table columns with gridview columns (the widths)? I have tried setting table.column(0).width = gridview.column(0).width at page_load but it doesn't work. Thanks in advance
4
by: Don Miller | last post by:
This is a repost of a reproducible problem/bug with GridView with dynamic SQL and binding. Is there a better ASP.NET newsgroup I should post to where MS techs or MVPs take an interest in such...
2
by: Mic | last post by:
Hi, I have a GridView control that gets populated at runtime and I need to print its content. The simplest way I found was to use window.print() but this prints everything on the page. But if...
0
by: =?Utf-8?B?U2hhbQ==?= | last post by:
Hai all, In my application, I need to Export webpage things into hard drive. I am using gridview, and i export all things(with the help of some sites) into excel except images. Please, Can...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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,...

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.