I've got a really annoying problem with a datagrid. I have an application
which populates a datagrid on the onclick event of a button. The datagrid is
bound to an ArrayList which holds the values. Everything worked perfectly
for me in my test application however when I copied and pasted the code
accross to my main project something strange started to happen. On the
on-click event of the button (cmdExcAdrConti nue) the datagrid is populated
and shown in the panel however an extra blank row is created in the datagrid
containing extra values. I stepped through the code and it seems to go
through the cmdExcAdrContin ue_Click event twice. It doesn't do this in my
test application so I can't seem to figure it out. its probably something
simple. Has anyone got any ideas????
protected void cmdExcAdrContin ue_Click(object sender, System.EventArg s e)
{
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];
Address newAddress = new Address();
newAddress.Addr ess1 = this.txtAddress 1.Text.Trim();
newAddress.Addr ess2 = this.txtAddress 2.Text.Trim();
newAddress.Addr ess3 = this.txtAddress 3.Text.Trim();
newAddress.Addr ess4 = this.txtAddress 4.Text.Trim();
newAddress.Addr ess5 = this.txtAddress 5.Text.Trim();
newAddress.Addr ess6 = this.txtAddress 6.Text.Trim();
addresses.Add(n ewAddress);
ViewState["Addresses"] = addresses;
this.dgSearchAd dresses.DataSou rce = addresses;
this.dgSearchAd dresses.DataBin d();
//clear down the textboxes
this.txtAddress 1.Text = "";
this.txtAddress 2.Text = "";
this.txtAddress 3.Text = "";
this.txtAddress 4.Text = "";
this.txtAddress 5.Text = "";
this.txtAddress 6.Text = "";
this.pnlExcepti onAddress.Visib le = false;
LiteralControl li = new LiteralControl( "<script
language=JavaSc ript>document.g etElementById(' txtHouseNum').f ocus();</script>");
Page.Controls.A dd(li);
checkArrayList( );
}
private void Page_Load(objec t sender, System.EventArg s e)
{
checkArrayList( );
ArrayList addresses;
// when the page is first loaded only
if( !IsPostBack )
{
addresses = new ArrayList();
ViewState["Addresses"] = addresses;
}
// on subsequent PostBacks:
else
{
addresses = (ArrayList) ViewState["Addresses"];
if( addresses != null )
{
this.dgSearchAd dresses.DataSou rce =
addresses; this.dgSearchAd dresses.DataBin d();
LiteralControl li = new LiteralControl( "<script
language=JavaSc ript>document.g etElementById(' txtHouseNum').f ocus();</script>");
Page.Controls.A dd(li);
}
}
//Hide this two panels to begin with
this.pnlAddress Results.Visible =false;
this.pnlExcepti onAddress.Visib le =false;
}
private void checkArrayList( )
{
if(dgSearchAddr esses.Items.Cou nt == 0)
{
this.pnlSearchA ddresses.Visibl e = false;
}
else
{
this.pnlSearchA ddresses.Visibl e = true;
}
}
Thanks for any help anyone can give me
which populates a datagrid on the onclick event of a button. The datagrid is
bound to an ArrayList which holds the values. Everything worked perfectly
for me in my test application however when I copied and pasted the code
accross to my main project something strange started to happen. On the
on-click event of the button (cmdExcAdrConti nue) the datagrid is populated
and shown in the panel however an extra blank row is created in the datagrid
containing extra values. I stepped through the code and it seems to go
through the cmdExcAdrContin ue_Click event twice. It doesn't do this in my
test application so I can't seem to figure it out. its probably something
simple. Has anyone got any ideas????
protected void cmdExcAdrContin ue_Click(object sender, System.EventArg s e)
{
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];
Address newAddress = new Address();
newAddress.Addr ess1 = this.txtAddress 1.Text.Trim();
newAddress.Addr ess2 = this.txtAddress 2.Text.Trim();
newAddress.Addr ess3 = this.txtAddress 3.Text.Trim();
newAddress.Addr ess4 = this.txtAddress 4.Text.Trim();
newAddress.Addr ess5 = this.txtAddress 5.Text.Trim();
newAddress.Addr ess6 = this.txtAddress 6.Text.Trim();
addresses.Add(n ewAddress);
ViewState["Addresses"] = addresses;
this.dgSearchAd dresses.DataSou rce = addresses;
this.dgSearchAd dresses.DataBin d();
//clear down the textboxes
this.txtAddress 1.Text = "";
this.txtAddress 2.Text = "";
this.txtAddress 3.Text = "";
this.txtAddress 4.Text = "";
this.txtAddress 5.Text = "";
this.txtAddress 6.Text = "";
this.pnlExcepti onAddress.Visib le = false;
LiteralControl li = new LiteralControl( "<script
language=JavaSc ript>document.g etElementById(' txtHouseNum').f ocus();</script>");
Page.Controls.A dd(li);
checkArrayList( );
}
private void Page_Load(objec t sender, System.EventArg s e)
{
checkArrayList( );
ArrayList addresses;
// when the page is first loaded only
if( !IsPostBack )
{
addresses = new ArrayList();
ViewState["Addresses"] = addresses;
}
// on subsequent PostBacks:
else
{
addresses = (ArrayList) ViewState["Addresses"];
if( addresses != null )
{
this.dgSearchAd dresses.DataSou rce =
addresses; this.dgSearchAd dresses.DataBin d();
LiteralControl li = new LiteralControl( "<script
language=JavaSc ript>document.g etElementById(' txtHouseNum').f ocus();</script>");
Page.Controls.A dd(li);
}
}
//Hide this two panels to begin with
this.pnlAddress Results.Visible =false;
this.pnlExcepti onAddress.Visib le =false;
}
private void checkArrayList( )
{
if(dgSearchAddr esses.Items.Cou nt == 0)
{
this.pnlSearchA ddresses.Visibl e = false;
}
else
{
this.pnlSearchA ddresses.Visibl e = true;
}
}
Thanks for any help anyone can give me
Comment