How to avoid accessing row values with hard coded index

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default How to avoid accessing row values with hard coded index

    Hi there ,

    My code look like this,

    string var1,var2,var3,var4;

    foreach (DataGridItem item in MyDataGrid.Items)

    {

    var1 = item.Cells[0].Text;

    var2 = item.Cells[1].Text;

    var3 = item.Cells[2].Text;

    var4 = item.Cells[3].Text;

    }

    How can access the row data with column header text instead of hard coded
    index's. Like



    var1 = item.Cells["ID"].Text;

    var2 = item.Cells["FromDate"].Text;

    var3 = item.Cells["ToDate"].Text;

    var4 = item.Cells["TransferDate"].Text;



    Thanks

    Baski


    Microsoft Guest

  2. Similar Questions and Discussions

    1. hard-coded path?
      I'm a complete newb to swf. I haven't got a clue yet what's going on. I've built a simple little swf that implements a visualization algorithm...
    2. Displaying multiple values - Hard to explain here...
      Hi All! Ok. I've got a query that's pulling data from multiple child tables based on the primary key from the parent table and displaying it in...
    3. duplicate values in the index, primary key, or relationship
      I have a MSA2K db. Table: customers Columns: fileNumber: (primary) Indexed(No Duplicates) fileName Client ClientType fileYear boxNumber:...
    4. must all global list be hard-coded in?
      As customary, I use parameter dialogue boxes for most of the settings that I would change frequently; however, it seems that you can not use a...
    5. DISABLE The hard coded IE5+ security risk file types
      I understand according to this article: http://support.microsoft.com/?id=232077 That there are hardcoded file types in IE that demands the...
  3. #2

    Default Re: How to avoid accessing row values with hard coded index

    this is an oversight on the part of MS. You can only access via an index. If
    you really need this you will need to do a typed dataset
    "Microsoft" <baski@aldensys.com> wrote in message
    news:enWWnMqgDHA.2916@tk2msftngp13.phx.gbl...
    > Hi there ,
    >
    > My code look like this,
    >
    > string var1,var2,var3,var4;
    >
    > foreach (DataGridItem item in MyDataGrid.Items)
    >
    > {
    >
    > var1 = item.Cells[0].Text;
    >
    > var2 = item.Cells[1].Text;
    >
    > var3 = item.Cells[2].Text;
    >
    > var4 = item.Cells[3].Text;
    >
    > }
    >
    > How can access the row data with column header text instead of hard coded
    > index's. Like
    >
    >
    >
    > var1 = item.Cells["ID"].Text;
    >
    > var2 = item.Cells["FromDate"].Text;
    >
    > var3 = item.Cells["ToDate"].Text;
    >
    > var4 = item.Cells["TransferDate"].Text;
    >
    >
    >
    > Thanks
    >
    > Baski
    >
    >

    Alvin Bruney Guest

  4. #3

    Default Re: How to avoid accessing row values with hard coded index

    What I did is created an enumeration with one member for each column with a
    value assigned to that of the coresponding index.

    Private Enum EnumName
    Column1 = 0
    Column2 = 1
    ...
    ...
    End Enum

    Then whenever you need to access the cell do like so:
    item.Cells[EnumName.Column1 ].Text

    The benefit with this is that when you add or remove a column all you have
    to do is adjust the enumeration. You won't have to go through every line of
    code and change the indexes.

    Perry


    "Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote in
    message news:O%23EOdEThDHA.2212@TK2MSFTNGP09.phx.gbl...
    > this is an oversight on the part of MS. You can only access via an index.
    If
    > you really need this you will need to do a typed dataset
    > "Microsoft" <baski@aldensys.com> wrote in message
    > news:enWWnMqgDHA.2916@tk2msftngp13.phx.gbl...
    > > Hi there ,
    > >
    > > My code look like this,
    > >
    > > string var1,var2,var3,var4;
    > >
    > > foreach (DataGridItem item in MyDataGrid.Items)
    > >
    > > {
    > >
    > > var1 = RegisterHiddenField> >
    > > var2 = item.Cells[1].Text;
    > >
    > > var3 = item.Cells[2].Text;
    > >
    > > var4 = item.Cells[3].Text;
    > >
    > > }
    > >
    > > How can access the row data with column header text instead of hard
    coded
    > > index's. Like
    > >
    > >
    > >
    > > var1 = item.Cells["ID"].Text;
    > >
    > > var2 = item.Cells["FromDate"].Text;
    > >
    > > var3 = item.Cells["ToDate"].Text;
    > >
    > > var4 = item.Cells["TransferDate"].Text;
    > >
    > >
    > >
    > > Thanks
    > >
    > > Baski
    > >
    > >
    >
    >

    Perecli Manole Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139