Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Need Solution for a so simple XML Data binding!though can figure out [modified]

Need Solution for a so simple XML Data binding!though can figure out [modified]

Scheduled Pinned Locked Moved ASP.NET
csharpjavascriptphpasp-netwpf
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    highjo
    wrote on last edited by
    #1

    hi! guys this is terrible since a while now i've trying to do a very basic data binding, but i'm failing somewhere.let say in my webpage i have a dropdownlist and a textbox(textArea).so the logic is when a user select a text on the dropdownlist(ddCustom by id) its value should be displayed in the textbox.that it.what i've achieved so far is having the dropdownlist text bound but the value is not loading into the textbox field. here are my codes protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { string result = this.validateAll(txtEmail.Text, txtNumbers.Text, txtMessage.Text, txtName.Text, 100); int resultlen = result.Length; lblError.Text = resultlen.ToString(); } else { DataSet DsTemplate = new DataSet(); DsTemplate.ReadXml(MapPath(@"~\misc\MessageTemplate.xml")); ddCustom.DataSource = DsTemplate; ddCustom.DataTextField = "name"; ddCustom.DataValueField = "text"; ddCustom.DataBind(); } } protected void ddCustom_SelectedIndexChanged(object sender, EventArgs e) { //txtMessage is the id of the textbox txtMessage.Text = ddCustom.SelectedItem.value; } sample of the xml file simple isn't it? but don't know. I'm from php backgroung.i would do that by an ajax stuff or with jquery.But here i'm surely forgetting something or thinking that asp.net would do everything for me.i search on google, w3school and my codes seems to be ok.need help on this.please let me know as soon as you have time to check this.Thank you! PS:i'm so frustrated i can't do anything else eager to learn

    modified on Friday, July 11, 2008 7:39 AM

    H L A 3 Replies Last reply
    0
    • H highjo

      hi! guys this is terrible since a while now i've trying to do a very basic data binding, but i'm failing somewhere.let say in my webpage i have a dropdownlist and a textbox(textArea).so the logic is when a user select a text on the dropdownlist(ddCustom by id) its value should be displayed in the textbox.that it.what i've achieved so far is having the dropdownlist text bound but the value is not loading into the textbox field. here are my codes protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { string result = this.validateAll(txtEmail.Text, txtNumbers.Text, txtMessage.Text, txtName.Text, 100); int resultlen = result.Length; lblError.Text = resultlen.ToString(); } else { DataSet DsTemplate = new DataSet(); DsTemplate.ReadXml(MapPath(@"~\misc\MessageTemplate.xml")); ddCustom.DataSource = DsTemplate; ddCustom.DataTextField = "name"; ddCustom.DataValueField = "text"; ddCustom.DataBind(); } } protected void ddCustom_SelectedIndexChanged(object sender, EventArgs e) { //txtMessage is the id of the textbox txtMessage.Text = ddCustom.SelectedItem.value; } sample of the xml file simple isn't it? but don't know. I'm from php backgroung.i would do that by an ajax stuff or with jquery.But here i'm surely forgetting something or thinking that asp.net would do everything for me.i search on google, w3school and my codes seems to be ok.need help on this.please let me know as soon as you have time to check this.Thank you! PS:i'm so frustrated i can't do anything else eager to learn

      modified on Friday, July 11, 2008 7:39 AM

      H Offline
      H Offline
      highjo
      wrote on last edited by
      #2

      common guys a little help to put me on track please.still waiting

      eager to learn

      1 Reply Last reply
      0
      • H highjo

        hi! guys this is terrible since a while now i've trying to do a very basic data binding, but i'm failing somewhere.let say in my webpage i have a dropdownlist and a textbox(textArea).so the logic is when a user select a text on the dropdownlist(ddCustom by id) its value should be displayed in the textbox.that it.what i've achieved so far is having the dropdownlist text bound but the value is not loading into the textbox field. here are my codes protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { string result = this.validateAll(txtEmail.Text, txtNumbers.Text, txtMessage.Text, txtName.Text, 100); int resultlen = result.Length; lblError.Text = resultlen.ToString(); } else { DataSet DsTemplate = new DataSet(); DsTemplate.ReadXml(MapPath(@"~\misc\MessageTemplate.xml")); ddCustom.DataSource = DsTemplate; ddCustom.DataTextField = "name"; ddCustom.DataValueField = "text"; ddCustom.DataBind(); } } protected void ddCustom_SelectedIndexChanged(object sender, EventArgs e) { //txtMessage is the id of the textbox txtMessage.Text = ddCustom.SelectedItem.value; } sample of the xml file simple isn't it? but don't know. I'm from php backgroung.i would do that by an ajax stuff or with jquery.But here i'm surely forgetting something or thinking that asp.net would do everything for me.i search on google, w3school and my codes seems to be ok.need help on this.please let me know as soon as you have time to check this.Thank you! PS:i'm so frustrated i can't do anything else eager to learn

        modified on Friday, July 11, 2008 7:39 AM

        L Offline
        L Offline
        leoinfo
        wrote on last edited by
        #3

        Add this at the end of Page_Load

        ddCustom.Attributes.Add(
        "onchange",
        "var txtMessage = getElementById('" + txtMessage.ClientID + "');"+
        "if(txtMessage)txtMessage.value = this.options[this.selectedIndex].value"
        );

        This will run on client side. Your code should also work, but you didn't give us the html from the ASP.NET page. So... I suppose you did not assign the OnSelectedIndexChanged="ddCustom_SelectedIndexChanged" for your ddCustom control.

        H 1 Reply Last reply
        0
        • L leoinfo

          Add this at the end of Page_Load

          ddCustom.Attributes.Add(
          "onchange",
          "var txtMessage = getElementById('" + txtMessage.ClientID + "');"+
          "if(txtMessage)txtMessage.value = this.options[this.selectedIndex].value"
          );

          This will run on client side. Your code should also work, but you didn't give us the html from the ASP.NET page. So... I suppose you did not assign the OnSelectedIndexChanged="ddCustom_SelectedIndexChanged" for your ddCustom control.

          H Offline
          H Offline
          highjo
          wrote on last edited by
          #4

          Pretty pretty cool man it's working without any modification.just copy and paste.You are the man! thanks. disturbingly simple.By the way why do you select txtMessage.ClientID instead of txtMessage what i would be tempted to do?

          eager to learn

          L 1 Reply Last reply
          0
          • H highjo

            Pretty pretty cool man it's working without any modification.just copy and paste.You are the man! thanks. disturbingly simple.By the way why do you select txtMessage.ClientID instead of txtMessage what i would be tempted to do?

            eager to learn

            L Offline
            L Offline
            leoinfo
            wrote on last edited by
            #5

            Because you didn't tell me enough about your application and I wanted to make the code working with just a copy/paste. :) Seriously now, if your dropdownlist control is placed inside a repeater or it's a part of a user control (or whatever...) , then the ClientID and ID are different.

            H 1 Reply Last reply
            0
            • H highjo

              hi! guys this is terrible since a while now i've trying to do a very basic data binding, but i'm failing somewhere.let say in my webpage i have a dropdownlist and a textbox(textArea).so the logic is when a user select a text on the dropdownlist(ddCustom by id) its value should be displayed in the textbox.that it.what i've achieved so far is having the dropdownlist text bound but the value is not loading into the textbox field. here are my codes protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { string result = this.validateAll(txtEmail.Text, txtNumbers.Text, txtMessage.Text, txtName.Text, 100); int resultlen = result.Length; lblError.Text = resultlen.ToString(); } else { DataSet DsTemplate = new DataSet(); DsTemplate.ReadXml(MapPath(@"~\misc\MessageTemplate.xml")); ddCustom.DataSource = DsTemplate; ddCustom.DataTextField = "name"; ddCustom.DataValueField = "text"; ddCustom.DataBind(); } } protected void ddCustom_SelectedIndexChanged(object sender, EventArgs e) { //txtMessage is the id of the textbox txtMessage.Text = ddCustom.SelectedItem.value; } sample of the xml file simple isn't it? but don't know. I'm from php backgroung.i would do that by an ajax stuff or with jquery.But here i'm surely forgetting something or thinking that asp.net would do everything for me.i search on google, w3school and my codes seems to be ok.need help on this.please let me know as soon as you have time to check this.Thank you! PS:i'm so frustrated i can't do anything else eager to learn

              modified on Friday, July 11, 2008 7:39 AM

              A Offline
              A Offline
              Arindam Tewary
              wrote on last edited by
              #6

              Make sure that for the drop down list "AutoPostback=True is" ther.;

              ;

              Thanks, Arindam D Tewary

              H 1 Reply Last reply
              0
              • L leoinfo

                Because you didn't tell me enough about your application and I wanted to make the code working with just a copy/paste. :) Seriously now, if your dropdownlist control is placed inside a repeater or it's a part of a user control (or whatever...) , then the ClientID and ID are different.

                H Offline
                H Offline
                highjo
                wrote on last edited by
                #7

                got ya! thanks bro! :-\

                eager to learn

                1 Reply Last reply
                0
                • A Arindam Tewary

                  Make sure that for the drop down list "AutoPostback=True is" ther.;

                  ;

                  Thanks, Arindam D Tewary

                  H Offline
                  H Offline
                  highjo
                  wrote on last edited by
                  #8

                  ok bro it's already there. thanks for helping

                  eager to learn

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups