Need Solution for a so simple XML Data binding!though can figure out [modified]
-
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 learnmodified on Friday, July 11, 2008 7:39 AM
-
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 learnmodified on Friday, July 11, 2008 7:39 AM
-
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 learnmodified on Friday, July 11, 2008 7:39 AM
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.
-
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.
-
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
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.
-
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 learnmodified on Friday, July 11, 2008 7:39 AM
Make sure that for the drop down list "AutoPostback=True is" ther.;
;
Thanks, Arindam D Tewary
-
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.
-
Make sure that for the drop down list "AutoPostback=True is" ther.;
;
Thanks, Arindam D Tewary