By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,333 Members | 1,381 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,333 IT Pros & Developers. It's quick & easy.

How to reset ba gridview content

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.