3 Replies - 605 Views - Last Post: 10 October 2012 - 05:58 AM Rate Topic: -----

#1 sabi27  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-October 12

Getting values to a textbox from 2dropdownlists

Posted 09 October 2012 - 07:18 AM

hi,

i am having a difficulty in writing the code for this. I have 2dropdownlists such as start location and destination. if the user selects a start and a destination a the distance should be shown in a text box. a reply is appreciated. im using C# with asp.net 3.5
Is This A Good Question/Topic? 0
  • +

Replies To: Getting values to a textbox from 2dropdownlists

#2 h4nnib4l  Icon User is offline

  • The Noid
  • member icon

Reputation: 1181
  • View blog
  • Posts: 1,675
  • Joined: 24-August 11

Re: Getting values to a textbox from 2dropdownlists

Posted 09 October 2012 - 08:03 AM

What have you tried so far? Let's see the code...
Was This Post Helpful? 0
  • +
  • -

#3 sabi27  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-October 12

Re: Getting values to a textbox from 2dropdownlists

Posted 09 October 2012 - 08:12 PM

Hi , this is what i wrote in the button click event:
protected void btndistance_Click(object sender, EventArgs e)
{

BLDistance bl = new BLDistance();
bl.MyProperty_startlocation = Dpstart.SelectedItem.Text;
bl.MyProperty_destination = Dpdes.SelectedItem.Text;
string res = bl.checkdistance();

if (res == "1")
{
TextBox4.Text = bl.MyProperty_dsdistance.Tables[0].Rows["Distance"].ToString();

}
else
{
}
}

public string checkdistance()
{
try
{
cmd.CommandText = "select Distance from TblDistanceChart where start_location= ' " + this.MyProperty_startlocation + " '+destination_location =' " + this.MyProperty_destination + " '";

ada.Fill(this.MyProperty_dsdistance, "distance");
return "1";
}

catch (Exception ex)
{
return ex.Message;
}



}
Was This Post Helpful? 0
  • +
  • -

#4 h4nnib4l  Icon User is offline

  • The Noid
  • member icon

Reputation: 1181
  • View blog
  • Posts: 1,675
  • Joined: 24-August 11

Re: Getting values to a textbox from 2dropdownlists

Posted 10 October 2012 - 05:58 AM

You need to look into parameterizing your query here. I really wish schools and books would teach that... You should also pull that code out of the event handler and put it into a separate method (that you then call from the event handler).

Will you post the BLDistance class code?

EDIT: I'm getting ahead of myself. What is your problem? What error are you receiving, and what is the result of your attempt to calculate and display the distance?

This post has been edited by h4nnib4l: 10 October 2012 - 05:59 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1