Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 23rd, 2005, 09:03 AM
Authorized User
 
Join Date: May 2005
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default for loop error..

Dear All,
i am getting error in for loop as-->

1) "The best overloaded method match for 'System.Web.UI.WebControls.ListItemCollection.Add( string)' has some invalid arguments"

2)cannot convert from "int" to "string"

the code is :
                int x=1;
        if(! this.IsPostBack)
        {
            for(x=1; x>=12; x++)
            {
                ddlid.Items.Add(x);
            } //for
        }

Plz help me out.

Thanks & Regards,
Muskaan.

 
Old May 23rd, 2005, 09:44 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

You have to add a listitmeto the drop down:
Here is a code snipped fromt he VS Help

public void Button1_Click (object sender, System.EventArgs e)
{
   this.ListBox1.Items.Add(new ListItem("Carbon", "C"));
   this.ListBox1.Items.Add(new ListItem("Oxygen", "O"));
}


 
Old May 23rd, 2005, 05:57 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Jim, not entirely correct.

You can add a listitem with the overloaded .Add() method of the ListItemCollection class, but you have to provide it a string that will serve as text and value for the item:

ddlid.Items.Add(x.ToString());


Muskaan, please not that your loop will never be entered into. The testlogic is backwards:
   for(x=1; x>=12; x++)
should be
   for(x=1; x<=12; x++)


-Peter
 
Old May 24th, 2005, 01:26 AM
Authorized User
 
Join Date: May 2005
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks both of you.
Now its working.

But it is not showing the datagrid.

private void btnchoose_Click(object sender, System.EventArgs e)
{
    string strconn="Data Source=sapnew; Initial Catalog=master; Integrated Security=SSPI";
    SqlConnection myconn=new SqlConnection(strconn);
    string mysql="select * from feedback where id=" + ddlid.SelectedItem.Text;
    SqlDataAdapter Adfd=new SqlDataAdapter(mysql, myconn);
    DataSet Ds=new DataSet();
    Adfd.Fill(Ds, "Feedback");
    dgfeedback.DataSource =Ds.Tables["Feedback"].DefaultView ;
    //dgfeedback.DataBind();

    if(Ds.Tables["Feedback"].Rows.Count > 0)
    {
        dgfeedback.DataBind();
        dgfeedback.Visible =true;
        lblexec.Text =mysql ;
    }
    else
    {
        lblexec.Text =mysql + "<br><i>Sorry - no items exist with that ID</i>" ;
        dgfeedback.Visible =false;

    }


}

Regards,
Muskaan.

 
Old May 24th, 2005, 02:33 AM
Authorized User
 
Join Date: May 2005
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am now able to run my program.
The step where i was lacking was that i havent set "auto generated columns" to true.
simple mistake!!!
but can be dangerous.....

anyways, thanx....

regards,
muskaan.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Error type: Loop without Do cannielynn0312 Classic ASP Basics 1 February 21st, 2008 09:15 AM
last occurance omitted - LOOP error? crmpicco Excel VBA 3 May 5th, 2005 01:45 PM
loop error crmpicco Classic ASP Databases 7 March 4th, 2005 10:59 AM
'loop' without 'do' error! tjh205 Classic ASP Basics 3 January 22nd, 2004 07:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.