Now what I need change to in the above code to get the combination of both..otherwise i need have textbox for description which syncs with ddl..which is bit complex for my level of programming...thanks..
What is that ListCollection based on? DataSet or a List with two properties ColorCode and Description. You can handle this in many ways. One simple way is creating a temp list with new property like this. I am assuming that listCollection is obtained from
a DataTable.
Its a data set...came from Dataacess layer and I am converting it to list<colorclass> in business....
your solution makes some hope for me...and will u please provie me other way..because I am converting datset to list then again i need to store it to datatable....I don't know is it a good practice...can I do the same operation on the list???
and please show some piece of code how to capture that value on code behind...do i need to any trimming kind of things..I don't know...Thnks again...
It is difficult to visualize how you are retrieving the values from DataTable/DataSet.
sunny43
I am converting datset to list then again i need to store it to datatable....
You do not need to convert dataset to list and list to datatable etc., using LINQ, you can just build a List with an ADDITIONAL PROPERTY for DISPLAYTEXT. Add a new Property DISPLAYTEXT or some other name. You can just use a DataReader and return a List of
ColorClass Objects. That's it. Avoiding DataTables is a different approach altogether. You can use your existing code to add display Text like this
This is my code..please check this...u can get an idea...Thank You Very Much..
BLL Method:
public List<IColor> GetColorCode()
{
dataset = DAL.GetColorCode();
List<IColor> collection = new List<IColor>();
if (dataset != null)
{
if (dataset.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < dataset.Tables[0].Rows.Count; i++)
{
collection.Add(new Color
{
ColorCode = dataset.Tables[0].Rows[i]["ColorCode"].ToString(),
Description = dataset.Tables[0].Rows[i]["Description"].ToString()
});
}
}
}
return collection;
}
DAL returns dataset which is ADO.Net method with connection strings and calling stored procs...etc...I think U can Imagine how this looks like...
sunny43
Member
126 Points
170 Posts
Concatinate two Values in a dropdown list with a datasource of ListCollection
Nov 07, 2010 06:39 PM|LINK
Anyone please tell me in detail how to setup a multi value dropdownlist from a list collection...
Datasource: Listcollection which contains ColorCode and Description...
how setup a dropdown with Colorcode-Description like BLK-Black...
then how to capture these selected value as colorcode only by removing description for update purpose...
Now I am doin like this...
ddl.datesource=list<datasetvalues> ...contains (colorcode, description)
ddl.DataTextField = "ColorCode";
ddl.DataValueField = "ColorCode";
ddl.databind();
then selected value should be like this...
ddlcolor.Items.FindByValue((DataBinder.Eval(formView1.DataItem, "colorCode").ToString())).Selected = true;
for update:
ClassA.Color= ddl.selectedvalue();
Now what I need change to in the above code to get the combination of both..otherwise i need have textbox for description which syncs with ddl..which is bit complex for my level of programming...thanks..
sansan
All-Star
53942 Points
8147 Posts
Re: Concatinate two Values in a dropdown list with a datasource of ListCollection
Nov 07, 2010 07:41 PM|LINK
What is that ListCollection based on? DataSet or a List with two properties ColorCode and Description. You can handle this in many ways. One simple way is creating a temp list with new property like this. I am assuming that listCollection is obtained from a DataTable.
Add these import statements
DataTable DataTable1 = new DataTable(); DropDownList1.DataSource = DataTable1.AsEnumerable().Select(a => new { ColorCode = Convert.ToString(a["ColorCode"]), ColorDescription = Convert.ToString(a["ColorDescription"]), DisplayText = String.Format("{0}-{1}", Convert.ToString(a["ColorCode"]), Convert.ToString(a["ColorDescription"])) }).ToList(); DropDownList1.DataTextField = "DisplayText"; DropDownList1.DataValueField = "ColorCode"; DropDownList1.DataBind();You can find the ListItem by Value which is ColorCode and update DB. New Column DisplayText is solely for just showing the description. That's it.
sunny43
Member
126 Points
170 Posts
Re: Concatinate two Values in a dropdown list with a datasource of ListCollection
Nov 07, 2010 08:16 PM|LINK
hello Santhosh,
Thanks for your reply...
Its a data set...came from Dataacess layer and I am converting it to list<colorclass> in business....
your solution makes some hope for me...and will u please provie me other way..because I am converting datset to list then again i need to store it to datatable....I don't know is it a good practice...can I do the same operation on the list???
and please show some piece of code how to capture that value on code behind...do i need to any trimming kind of things..I don't know...Thnks again...
sansan
All-Star
53942 Points
8147 Posts
Re: Concatinate two Values in a dropdown list with a datasource of ListCollection
Nov 07, 2010 08:26 PM|LINK
It is difficult to visualize how you are retrieving the values from DataTable/DataSet.
You do not need to convert dataset to list and list to datatable etc., using LINQ, you can just build a List with an ADDITIONAL PROPERTY for DISPLAYTEXT. Add a new Property DISPLAYTEXT or some other name. You can just use a DataReader and return a List of ColorClass Objects. That's it. Avoiding DataTables is a different approach altogether. You can use your existing code to add display Text like this
DropDownList1.SelectedValue gives color Code. You do not need any trimming or string manipulation.
sunny43
Member
126 Points
170 Posts
Re: Concatinate two Values in a dropdown list with a datasource of ListCollection
Nov 07, 2010 08:54 PM|LINK
This is my code..please check this...u can get an idea...Thank You Very Much..
BLL Method:
public List<IColor> GetColorCode()
{
dataset = DAL.GetColorCode();
List<IColor> collection = new List<IColor>();
if (dataset != null)
{
if (dataset.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < dataset.Tables[0].Rows.Count; i++)
{
collection.Add(new Color
{
ColorCode = dataset.Tables[0].Rows[i]["ColorCode"].ToString(),
Description = dataset.Tables[0].Rows[i]["Description"].ToString()
});
}
}
}
return collection;
}
DAL returns dataset which is ADO.Net method with connection strings and calling stored procs...etc...I think U can Imagine how this looks like...
In page codebehind:
DropDownList ddlColorCode= ((DropDownList)formViewJewelryEditItems.FindControl("ddlColorCode"));
ddlColorCode.DataSource = BAL.GetColorCode();
ddlColorCode.DataTextField = "ColorCode";
ddlColorCode.DataValueField = "ColorCode";
ddlColorCode.DataBind();
sansan
All-Star
53942 Points
8147 Posts
Re: Concatinate two Values in a dropdown list with a datasource of ListCollection
Nov 07, 2010 09:04 PM|LINK
Add a new property for Color Class with property name Display Text
and modify the BL method like this
And Set DropDownList DataTextField to ColorDisplayText and DataValueField to ColorCode.
That's it.
sunny43
Member
126 Points
170 Posts
Re: Concatinate two Values in a dropdown list with a datasource of ListCollection
Nov 07, 2010 09:07 PM|LINK
ohhh..got it...great santhosh...excellent...this thing killing me from yesterday....thanks for n times...
-Sunny
shydev
Member
19 Points
20 Posts
Re: Concatinate two Values in a dropdown list with a datasource of ListCollection
Nov 22, 2010 11:20 AM|LINK
how is this done in MVC?