Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Dictionary<string,> to Dictionary<int,>

Dictionary<string,> to Dictionary<int,>

Scheduled Pinned Locked Moved ASP.NET
helpquestiontutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Terick
    wrote on last edited by
    #1

    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.

    V 1 Reply Last reply
    0
    • T Terick

      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.

      V Offline
      V Offline
      vaghelabhavesh
      wrote on last edited by
      #2

      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))

      ...
      ...
      ...

      T 1 Reply Last reply
      0
      • V vaghelabhavesh

        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))

        ...
        ...
        ...

        T Offline
        T Offline
        Terick
        wrote on last edited by
        #3

        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?

        V 1 Reply Last reply
        0
        • T Terick

          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?

          V Offline
          V Offline
          vaghelabhavesh
          wrote on last edited by
          #4

          Does it tell you at which line the exception occurred?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups