this below code is for converting Datatable to Dictionary .change the logic as per your requirement...
Dictionary<string, string> de = new Dictionary<string, string>();
foreach (Datarow dr in test.rows)
{
de.Add(dr[0].toString(),dr[1].toString());
}
genericsdictionarydatasetasp.net
Read my blog | Twitter Please click "mark as answer" if this post helped you.
You can refer to the below link about bind Repeater with dicitonary. You can use button instead of lable and you can get the dictionary in the button click event.
praveen.khad...
Member
235 Points
116 Posts
passing data from dataset to dictionary
Feb 23, 2012 06:41 AM|LINK
Hi
I am getting value from the dataset. I want to pass it as dictionary. how can i achive it?
if (ds.Tables[3] != null) ----> Values are here
{
string scid= result.SampleCentralID;
//foreach (DataRow dr in dt.Rows)
//{
// if ((dr["shipped_qty"].ToString() == null) || (dr["shipped_qty"].ToString() == string.Empty))
// {
// shipDetails.ShipAddress = "Bangalore";
// }
// else
// {
// shipDetails.ShipAddress = dr["shipped_qty"].ToString();
// }
// if ((dr["product_desc"].ToString() == null) || (dr["product_desc"].ToString() == string.Empty))
// {
// shipDetails.DeliveryAddress = "Karnataka";
// }
// else
// {
// shipDetails.DeliveryAddress = dr["product_desc"].ToString();
// }
// if ((dr["ndc_prod_id"].ToString() == null) || (dr["ndc_prod_id"].ToString() == string.Empty))
// {
// shipDetails.NDCProdID = 12354;
// }
// else
// {
// shipDetails.NDCProdID = Convert.ToInt32(dr["ndc_prod_id"]);
// }
//
//
//result.ShipmentDetails.Add(scid,shipDetails); --------> I need to return In Dictionary as shown below
//}
ShipmentDetails
private Dictionary<string, IList<ShipmentDetails>> _propShipmentDetails;
public Dictionary<string, IList<ShipmentDetails>> ShipmentDetails
{
get
{
if (_propShipmentDetails == null)
_propShipmentDetails = new Dictionary<string, IList<ShipmentDetails>>();
return _propShipmentDetails;
}
set { _propShipmentDetails = value; }
}
generics dictionary dataset asp.net
Praveen.khade
gsudhesh
Member
271 Points
117 Posts
Re: passing data from dataset to dictionary
Feb 23, 2012 07:34 AM|LINK
this below code is for converting Datatable to Dictionary .change the logic as per your requirement... Dictionary<string, string> de = new Dictionary<string, string>(); foreach (Datarow dr in test.rows) { de.Add(dr[0].toString(),dr[1].toString()); }generics dictionary dataset asp.net
Please click "mark as answer" if this post helped you.
ramiramilu
All-Star
95503 Points
14106 Posts
Re: passing data from dataset to dictionary
Feb 23, 2012 09:58 AM|LINK
extract some values in datatable to dictionary - http://www.robertwray.co.uk/blog/2009/11/datatable-keyvalue-columns-to.html
Thanks,
generics dictionary dataset asp.net
JumpStart
praveen.khad...
Member
235 Points
116 Posts
Re: passing data from dataset to dictionary
Feb 23, 2012 10:45 AM|LINK
Can you breif me about it..
I need to return it..
Praveen.khade
gsudhesh
Member
271 Points
117 Posts
Re: passing data from dataset to dictionary
Feb 23, 2012 10:50 AM|LINK
sure can u make a function with return type dictionary
Please click "mark as answer" if this post helped you.
praveen.khad...
Member
235 Points
116 Posts
Re: passing data from dataset to dictionary
Feb 27, 2012 03:56 AM|LINK
I did it..
Now prob is i wnt to bind the object to the repeater.In the object i am getting all the values.
I have key and values..
senario is , when i click on any key related values should display.
How to achieve it,In ItemCommand i am getting key, i need to display related value.
Praveen.khade
Richey
Contributor
3816 Points
431 Posts
Re: passing data from dataset to dictionary
Feb 29, 2012 12:22 PM|LINK
Hi,
You can refer to the below link about bind Repeater with dicitonary. You can use button instead of lable and you can get the dictionary in the button click event.
http://forums.asp.net/t/1429142.aspx
http://forums.asp.net/p/1184360/2020322.aspx
Furthermore, you question is different from the original one. YOu can put it in a new thread.