bind dropdownlist

Last post 07-07-2009 1:20 AM by CoolBond. 3 replies.

Sort Posts:

  • bind dropdownlist

    07-06-2009, 4:27 PM
    • Member
      3 point Member
    • mavericky
    • Member since 03-27-2009, 9:13 PM
    • Posts 66

    Hi all,

    i have a dropdownlist, and i bind it with two digit numbers. I want if the user enters 2 in the textbox, it should be stored as 02.

     

    It would be great if somebody could help me!

     

  • Re: bind dropdownlist

    07-07-2009, 12:53 AM
    Answer
    • Member
      80 point Member
    • Chintan Dave
    • Member since 07-06-2009, 4:27 AM
    • Mumbai,India
    • Posts 22

    Hi if I understand your prlm rightly than do like this :

    u can use this code for adding data in to DDL

    dropdownlist.item.add(item) 

    u can pass here the Text of your Textbox. so it will add your value and u can also attached 0 before ur txt.text with + operator with the if condition that if value is less than 10.

    u can also use this [dropdownlist].Items.Insert(index, new ListItem("",""));

    And u can Get more Idea about this on this Link as Below:

    http://msdn.microsoft.com/en-us/library/0dzka5sf(VS.71).aspx

    if u get ur ans  than "Mark as Answer" to this Post

     


    Chintan Dave.

    please Mark Your Post as Anwserd, If u Got Right Answer
  • Re: bind dropdownlist

    07-07-2009, 1:09 AM
    • Member
      80 point Member
    • Chintan Dave
    • Member since 07-06-2009, 4:27 AM
    • Mumbai,India
    • Posts 22

    Other u can so like this for Databainding

    ddlAuthor.DataTextField = "FullName";
    ddlAuthor.DataValueField = "AuthorID";
    ddlAuthor.DataSource = authorDB.GetAuthors();
    ddlAuthor.DataBind();
    ddlAuthor.Items.Insert(0, "-- Select Author --");

    Here u can pass like : Textbob1.text

    Also Refer this link for more information 

    http://digitalcolony.com/2007/03/add-item-to-dropdownlist-after-databind.aspx

     Thanks.


    Chintan Dave.

    please Mark Your Post as Anwserd, If u Got Right Answer
  • Re: bind dropdownlist

    07-07-2009, 1:20 AM
    • Contributor
      2,730 point Contributor
    • CoolBond
    • Member since 10-25-2007, 9:34 AM
    • Country
    • Posts 535

     Hi,

         Its not clear me , where you want to store only in dropdown or in database also. As per my understanding I created a sample applcaition which accepts only 2 digit numbers after padded a 0 before the text.

    protected void btnAdd_Click(object sender, EventArgs e)

        {

            string sItemAdded = "0" + TextBox1.Text.Trim();

            DropDownList1.Items.Insert(DropDownList1.Items.Count, sItemAdded.Substring(sItemAdded.Length - 2, 2));

        }

    Hope this will help you....

    " If people criticize you, hurt you, or shout at you,Don't be bothered. Just remember, In every game, audience make the noise, not the players "
Page 1 of 1 (4 items)