Preselecting in DataGrid

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default RE: Preselecting in DataGrid

    Hi Ingeborg,

    You can use the primary key to locate the row. Please check the code
    snippet below:

    //"ds" is the dataset which will be binded to the datagrid.
    ds.Tables[0].DefaultView.Sort = "id";//Sort by key
    int nn=ds.Tables[0].DefaultView.Find(3);//eg: 3 is a key value of a row.
    Then you can get the index of the row.
    DataGrid1.EditItemIndex =nn;
    DataGrid1.DataSource= dw;
    DataGrid1.DataBind();

    You can check the link for more information:
    <[url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html[/url]
    /frlrfsystemdatadataviewclassfindtopic.asp>

    Hope this helps.

    Best Regards,
    Lewis Wang

    This posting is provided "AS IS" with no warranties, and confers no rights.

    --------------------
    | Content-Class: urn:content-classes:message
    | From: "Ingeborg" <nobody@nowhere.net>
    | Sender: "Ingeborg" <nobody@nowhere.net>
    | Subject: Preselecting in DataGrid
    | Date: Tue, 22 Jul 2003 09:22:16 -0700
    | Lines: 10
    | Message-ID: <011201c3506d$6a3f3350$a301280a@phx.gbl>
    | MIME-Version: 1.0
    | Content-Type: text/plain;
    | charset="iso-8859-1"
    | Content-Transfer-Encoding: 7bit
    | X-Newsreader: Microsoft CDO for Windows 2000
    | X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
    | Thread-Index: AcNQbWo/z9kciKMYRiOlbqLmzkYWvg==
    | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | Path: cpmsftngxa06.phx.gbl
    | Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:161058
    | NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    |
    | Hi.
    |
    | Is it somehow possible to preselect an item in a DataGrid?
    | How can you select an item in the datagrid when you only
    | know what datarow you want to be selected, but need to get
    | the ItemIndex for setting the DataGrid.SelectedIndex?
    |
    | Thanks in advance.
    |
    | Ingeborg
    |

    Lewis Wang [MSFT] Guest

  2. Similar Questions and Discussions

    1. How to add a Dropdown list to a datagrid at runtime (dynamic) without using template columns in ASP.NET and still have the ability to us the datagrid Update event.
      How to add a Dropdown list to a datagrid at runtime (dynamic) without using template columns in ASP.NET and still have the ability to us the...
    2. UserControl inside of datagrid - loses its viewstate when datagrid is re-bound on postback
      I have a simple usercontrol, a datepicker which contains 3 dropdownlist , it resides inside a datagrid column and i set the selecteddate property of...
    3. custom usercontrol inside of datagrid - loses its state/viewstate on re-bind/postback of the datagrid
      I have a simple usercontrol, a datepicker which contains 3 dropdownlist , it resides inside a datagrid column and i set the selecteddate property of...
    4. How can I save the style of a datagrid so that it appears on the automatic format to use iin another datagrid?
      How can I save the style of a datagrid so that it appears on the automatic format to use iin another datagrid?
    5. To all Gurus: How can I edit/update a DataGrid in a DataGrid (nested DataGrid)? Possible?
      Hello, I am searching the whole Internet for a good example how to edit/update a DataGrid in a DataGrid (nested DataGrid). I know how to...
  3. #2

    Default RE: Preselecting in DataGrid


    I am glad to hear it. Thanks very much for participating the community. ^_^

    Lewis Wang
    Support Professional

    This posting is provided "AS IS" with no warranties, and confers no rights.



    --------------------
    | Content-Class: urn:content-classes:message
    | From: "Ingeborg" <nobody@nowhere.net>
    | Sender: "Ingeborg" <nobody@nowhere.net>
    | References: <011201c3506d$6a3f3350$a301280a@phx.gbl>
    <Vz$mRgMUDHA.2364@cpmsftngxa06.phx.gbl>
    | Subject: RE: Preselecting in DataGrid
    | Date: Wed, 23 Jul 2003 11:08:34 -0700
    | Lines: 74
    | Message-ID: <02d901c35145$6e4f7440$a001280a@phx.gbl>
    | MIME-Version: 1.0
    | Content-Type: text/plain;
    | charset="iso-8859-1"
    | Content-Transfer-Encoding: 7bit
    | X-Newsreader: Microsoft CDO for Windows 2000
    | X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
    | Thread-Index: AcNRRW5PE+KhL4TGQYWiCbcJdYN2kQ==
    | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | Path: cpmsftngxa06.phx.gbl
    | Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:161466
    | NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    |
    | Thanks a lot, it makes my user interface a lot nicer!
    |
    | Ingeborg
    |
    |
    | >-----Original Message-----
    | >Hi Ingeborg,
    | >
    | >You can use the primary key to locate the row. Please
    | check the code
    | >snippet below:
    | >
    | >//"ds" is the dataset which will be binded to the
    | datagrid.
    | >ds.Tables[0].DefaultView.Sort = "id";//Sort by key
    | >int nn=ds.Tables[0].DefaultView.Find(3);//eg: 3 is a key
    | value of a row.
    | >Then you can get the index of the row.
    | >DataGrid1.EditItemIndex =nn;
    | >DataGrid1.DataSource= dw;
    | >DataGrid1.DataBind();
    | >
    | >You can check the link for more information:
    | ><[url]http://msdn.microsoft.com/library/default.asp?[/url]
    | url=/library/en-us/cpref/html
    | >/frlrfsystemdatadataviewclassfindtopic.asp>
    | >
    | >Hope this helps.
    | >
    | >Best Regards,
    | >Lewis Wang
    | >
    | >This posting is provided "AS IS" with no warranties, and
    | confers no rights.
    | >
    | >--------------------
    | >| Content-Class: urn:content-classes:message
    | >| From: "Ingeborg" <nobody@nowhere.net>
    | >| Sender: "Ingeborg" <nobody@nowhere.net>
    | >| Subject: Preselecting in DataGrid
    | >| Date: Tue, 22 Jul 2003 09:22:16 -0700
    | >| Lines: 10
    | >| Message-ID: <011201c3506d$6a3f3350$a301280a@phx.gbl>
    | >| MIME-Version: 1.0
    | >| Content-Type: text/plain;
    | >| charset="iso-8859-1"
    | >| Content-Transfer-Encoding: 7bit
    | >| X-Newsreader: Microsoft CDO for Windows 2000
    | >| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
    | >| Thread-Index: AcNQbWo/z9kciKMYRiOlbqLmzkYWvg==
    | >| Newsgroups: microsoft.public.dotnet.framework.aspnet
    | >| Path: cpmsftngxa06.phx.gbl
    | >| Xref: cpmsftngxa06.phx.gbl
    | microsoft.public.dotnet.framework.aspnet:161058
    | >| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
    | >| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    | >|
    | >| Hi.
    | >|
    | >| Is it somehow possible to preselect an item in a
    | DataGrid?
    | >| How can you select an item in the datagrid when you
    | only
    | >| know what datarow you want to be selected, but need to
    | get
    | >| the ItemIndex for setting the DataGrid.SelectedIndex?
    | >|
    | >| Thanks in advance.
    | >|
    | >| Ingeborg
    | >|
    | >
    | >.
    | >
    |

    Lewis Wang [MSFT] 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