Up vote 0 down vote favorite share g+ share fb share tw.
I am trying to implement a gridview field with data from another table, one of the fields in the table called "LocationID" is a foreign key to the Locations table. I don't want to display the number on the gridview I want to see only the address field from the Locations table and edit the value using a dropdownlist control. This is the main table in use with the gridview and sqldatasource Net-Items ID,Name ,Model ,SerialNumber ,Company ,PurchaseDate ,PurchasePrice ,MonthPrice ,CommitmentPrice ,Status ,CommitmentDate ,Free ,TillDate ,LocationID and this is the secondary table Net-Locations ID ,ContactName ,Address ,City thanks asp.net gridview sqldatasource link|improve this question edited Jul 1 '11 at 9:26Kirill72418 asked Jul 1 '11 at 8:20Moran Monovich535 73% accept rate.
Please try the below code. Items Details " ProviderName="" SelectCommand="select * from Items"> " ProviderName=""> '> ' Width="98%" MaxLength="6"> ' Width="98%" MaxLength="6"> '> ' Width="98%"> ' Width="95%"> using System; using System.Collections. Generic; using System.
Web; using System.Web. UI; using System.Web.UI. WebControls; using System.
Collections; using System. Data; public partial class _Default : System.Web.UI. Page { protected void Page_Load(object sender, EventArgs e) { } protected string LookupLocation(object idObj) { if (string.
IsNullOrEmpty(idObj.ToString())) return null; // store the permissionID passed as an input parameter string LocationId = idObj.ToString(); // find the corresponding name IEnumerator enumos = sds_Location. Select(new DataSourceSelectArguments()).GetEnumerator(); while (enumos.MoveNext()) { DataRowView row = enumos. Current as DataRowView; if ((string)row"ID".ToString() == LocationId) return string.
Concat(row"Address".ToString()); } return LocationId; } }.
Thank you very much! That solve my problem. – Moran Monovich Jul 1 '11 at 13:46.
Please consider the following tutorial on how to configure the SqlDatasource control. Especially the Step 4: Using a Custom SQL Statement or Stored Procedure.
Create a separate SQL Datasource and query the Location table details what ever you want in that table. ' DataTextField="Address" DataValueField="Address"> Put the above code in the gridview columns.
Thanks but I have tried that already. For some reason when I choose the value it won't update the table. Please notice that I need only the ID field from the data base and not the Address field, since I am using a foreign key to location table and I am trying to update the "LocationID" field in the DB – Moran Monovich Jul 1 '11 at 9:22 Why don't you try to update the value from the backend.
May be you can you RowCommand and get the value from the Location table and update it. – gvLearner Jul 1 '11 at 9:45 that's a good idea but how can I implement it? Can you please give me a start point?
Maybe I can proceed from there – Moran Monovich Jul 1 '11 at 10:22.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.