-3

I'm developing an asp.net web-forms application with entity framework. There are two columns in my database table to add Latitude and Longitude. But I don't want to add two TextBoxes in user interface to add them.

I need to add one TextBox to add those data, separated by comma. (ex: 85.06000,25.01200). when user clicks submit button, I need to split this string up and add the result to Latitude and Longitude columns in database table.

I have created the form to insert data using DetailsView with TemplateField.

I'm new to asp.net and C#. How could I do this ?

Mahdi Tahsildari
  • 13,065
  • 14
  • 55
  • 94
Bishan
  • 15,211
  • 52
  • 164
  • 258
  • 1
    what's your problem? splitting? or working with database? – Mahdi Tahsildari Dec 26 '12 at 05:15
  • 1
    You need to handle the `event - xxxxInserting` of `DetailsView` and call the `FindControl` method to get the reference of `TextBox`. – KV Prajapati Dec 26 '12 at 05:20
  • @AVD i have added `OnItemInserting` event. but it's not working. see my [latest post](http://stackoverflow.com/questions/14037215/asp-net-detailsview-oniteminserting-is-not-working). – Bishan Dec 26 '12 at 07:20

3 Answers3

1

To separate string on two parts you can use string.Split() method.

if you have variable latitudeandlongitude:

var splittedArray = latitudeandlongitude.Split(',');

if(splittedArray.Length!=2)
    throw new ArgumentException();
var latitude = splittedArray[0];
var longitude = splittedArray[1];

But i'm not recommend you to do such things (use one textbox for two different variables). It will be source of user errors and they will hate you.

Kirill Bestemyanov
  • 11,946
  • 2
  • 24
  • 38
1
string[] parts = txtInput.Text.Trim().Split(',');
string Latitude = parts[0];
string Longitude = parts[1];

now you have seperated them and you can send them to your DB.

Mahdi Tahsildari
  • 13,065
  • 14
  • 55
  • 94
0

You can split the value like this :-

string[] arr=TextBox1.Text.Split(',');

and then prepare insert statement like :-

Insert into yourtable("Latitude","Longitude") values(arr[0],arr[1]);
Pranav
  • 8,563
  • 4
  • 26
  • 42