Dictionary<string,> to Dictionary<int,>
-
Hi, I have a Dictionary<string,> object that uses the Item name as the Key (string) and Size as the Item (decimal). However, on some occasions, the Item name repeats itself, but the itemIDs are always unique. So, I want to switch my Dictionary<string,> to be Dictionary<int,decimal>. My problem occurs when I am trying to get items that are checked from the datagrid. Right now this is the code:
public void GetChecked()
{
Dictionary<string,decimal> Checked=(Dictionary<string,decimal> )Session["CheckedItems"];
string itemname;
CheckBox cb;
TextBox tb;if (Checked !=null)
{
foreach (GridViewRow gvRow in gvwItems.Rows)
{
itemname= gvRow.DataKeys[row.RowIndex].Value.ToString();if(Checked.ContainsKey(itemname))
.
.
.
.How do I alter this code to read the item_id which is an integer and not a string? Please help if you can, I am very stuck on this and do not know how to proceed. Thank you.
-
Hi, I have a Dictionary<string,> object that uses the Item name as the Key (string) and Size as the Item (decimal). However, on some occasions, the Item name repeats itself, but the itemIDs are always unique. So, I want to switch my Dictionary<string,> to be Dictionary<int,decimal>. My problem occurs when I am trying to get items that are checked from the datagrid. Right now this is the code:
public void GetChecked()
{
Dictionary<string,decimal> Checked=(Dictionary<string,decimal> )Session["CheckedItems"];
string itemname;
CheckBox cb;
TextBox tb;if (Checked !=null)
{
foreach (GridViewRow gvRow in gvwItems.Rows)
{
itemname= gvRow.DataKeys[row.RowIndex].Value.ToString();if(Checked.ContainsKey(itemname))
.
.
.
.How do I alter this code to read the item_id which is an integer and not a string? Please help if you can, I am very stuck on this and do not know how to proceed. Thank you.
Dictionary<int,decimal> Checked=(Dictionary<int,decimal> )Session["CheckedItems"];
int itemname;
CheckBox cb;
TextBox tb;if (Checked !=null)
{
foreach (GridViewRow gvRow in gvwItems.Rows)
{
itemname= Convert.ToInt32(eRow.DataKeys[row.RowIndex].Value.ToString());if(Checked.ContainsKey(itemname))
...
...
... -
Dictionary<int,decimal> Checked=(Dictionary<int,decimal> )Session["CheckedItems"];
int itemname;
CheckBox cb;
TextBox tb;if (Checked !=null)
{
foreach (GridViewRow gvRow in gvwItems.Rows)
{
itemname= Convert.ToInt32(eRow.DataKeys[row.RowIndex].Value.ToString());if(Checked.ContainsKey(itemname))
...
...
...I made the changes you suggested and am now getting the following error: A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll An exception of type 'System.Threading.ThreadAbortException occurred in mscorlib.dll but was not handled in user code A first chance exception of type 'System.FormatException' occurred in mscorlib.dll How do i fix this?
-
I made the changes you suggested and am now getting the following error: A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll An exception of type 'System.Threading.ThreadAbortException occurred in mscorlib.dll but was not handled in user code A first chance exception of type 'System.FormatException' occurred in mscorlib.dll How do i fix this?
Does it tell you at which line the exception occurred?