Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / General / October 2004

Tip: Looking for answers? Try searching our database.

Datagrid problem. Creating extra unwanted row some who??

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Stephen - 28 Oct 2004 15:13 GMT
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('txtHouseNum').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('txtHouseNum').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;
    }
}
Stephen - 28 Oct 2004 16:23 GMT
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.

> 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
[quoted text clipped - 84 lines]
>     }
> }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.