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

Datagrid problem. Creating extra unwanted row some who??

I have 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 (cmdExcAdrContinue) 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
cmdExcAdrContinue_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 cmdExcAdrContinue_Click(object sender, System.EventArgs e)
{
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];

Address newAddress = new Address();
newAddress.Address1 = this.txtAddress1.Text.Trim();
newAddress.Address2 = this.txtAddress2.Text.Trim();
newAddress.Address3 = this.txtAddress3.Text.Trim();
newAddress.Address4 = this.txtAddress4.Text.Trim();
newAddress.Address5 = this.txtAddress5.Text.Trim();
newAddress.Address6 = this.txtAddress6.Text.Trim();

addresses.Add(newAddress);
ViewState["Addresses"] = addresses;

this.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();

//clear down the textboxes
this.txtAddress1.Text = "";
this.txtAddress2.Text = "";
this.txtAddress3.Text = "";
this.txtAddress4.Text = "";
this.txtAddress5.Text = "";
this.txtAddress6.Text = "";

this.pnlExceptionAddress.Visible = false;

LiteralControl li = new LiteralControl("<script
language=JavaScript>document.getElementById('txtHo useNum').focus();</script>");
Page.Controls.Add(li);

checkArrayList();
}

private void Page_Load(object sender, System.EventArgs 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.dgSearchAddresses.DataSource =
addresses; this.dgSearchAddresses.DataBind();
LiteralControl li = new LiteralControl("<script
language=JavaScript>document.getElementById('txtHo useNum').focus();</script>");
Page.Controls.Add(li);
}
}
//Hide this two panels to begin with
this.pnlAddressResults.Visible =false;
this.pnlExceptionAddress.Visible =false;
}

private void checkArrayList()
{
if(dgSearchAddresses.Items.Count == 0)
{
this.pnlSearchAddresses.Visible = false;
}
else
{
this.pnlSearchAddresses.Visible = true;
}
}
Jul 21 '05 #1
1 1682
It was something to do with the aspx page. when I deleted the following:
onclick="cmdExceptionAddress_Click" in the html view. I think its a problem
with VS 2002 im not sure. Just wasted 2 hours today working it out. Thanks
for your help.

"Stephen" wrote:
I have 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 (cmdExcAdrContinue) 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
cmdExcAdrContinue_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 cmdExcAdrContinue_Click(object sender, System.EventArgs e)
{
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];

Address newAddress = new Address();
newAddress.Address1 = this.txtAddress1.Text.Trim();
newAddress.Address2 = this.txtAddress2.Text.Trim();
newAddress.Address3 = this.txtAddress3.Text.Trim();
newAddress.Address4 = this.txtAddress4.Text.Trim();
newAddress.Address5 = this.txtAddress5.Text.Trim();
newAddress.Address6 = this.txtAddress6.Text.Trim();

addresses.Add(newAddress);
ViewState["Addresses"] = addresses;

this.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();

//clear down the textboxes
this.txtAddress1.Text = "";
this.txtAddress2.Text = "";
this.txtAddress3.Text = "";
this.txtAddress4.Text = "";
this.txtAddress5.Text = "";
this.txtAddress6.Text = "";

this.pnlExceptionAddress.Visible = false;

LiteralControl li = new LiteralControl("<script
language=JavaScript>document.getElementById('txtHo useNum').focus();</script>");
Page.Controls.Add(li);

checkArrayList();
}

private void Page_Load(object sender, System.EventArgs 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.dgSearchAddresses.DataSource =
addresses; this.dgSearchAddresses.DataBind();
LiteralControl li = new LiteralControl("<script
language=JavaScript>document.getElementById('txtHo useNum').focus();</script>");
Page.Controls.Add(li);
}
}
//Hide this two panels to begin with
this.pnlAddressResults.Visible =false;
this.pnlExceptionAddress.Visible =false;
}

private void checkArrayList()
{
if(dgSearchAddresses.Items.Count == 0)
{
this.pnlSearchAddresses.Visible = false;
}
else
{
this.pnlSearchAddresses.Visible = true;
}
}

Jul 21 '05 #2

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

Similar topics

7
by: bc9am | last post by:
Hi, I'm having problems with the <form> tag creating some unwanted whitespace. I did a search on this forum and came across this link: http://www.cs.tut.fi/~jkorpela/forms/extraspace.html ...
2
by: John Latten | last post by:
Hi there, I have got a problem when adding extra (= dummy) columns to a datagrid. I have a datagrid that is bound to a datatable. The datatable is filled with data from a SQL Server 2000...
0
by: Stephen | last post by:
This is a real brain-teaser and i'd really appreciate it if someone can try and understand what im trying to do and give me a few pointers or ideas to help me work out my problem. Im basically...
1
by: Falk | last post by:
hello, This is a function in the free magic library from Crownwood. My problem is that I can not move windows to the second monitor. Here is the function where I think with the problem (...
1
by: Udi | last post by:
Hi everyone! I have a major problem with the DataGrid control for the Windows Form! I am using the DataAdapter to get data from Sql Server 2000 DataBase and populating a DataGrid with the Table i...
17
by: A_PK | last post by:
I have problem databinding the DataGrid with DataView/DataSet after the filter... I create the following proceudre in order for user to filter as many as they want, but the following code is only...
1
by: Stephen | last post by:
I have 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. ...
9
by: Sukh | last post by:
Hello anyone, I am printing a pre-printed continue paper on dot-matrix printer using vb.net winform. For printing I am creating custom size paper and selecting the same for printing. Everything...
3
by: kingflux | last post by:
Hello, and thank you in advance for any help you can provide. Each line in our datagrid control contains a product number, description, and a textbox for the user to enter a quantity-to-order. ...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.