datagrid editcommand

Discussion in 'ASP .Net' started by Richard Roche, Jul 31, 2003.

  1. Is it possible to use a drop combo instead of a text box
    when using the EditCommand in the Datagrid? Many table
    columns are bound to 'lookup' tables, user's don't care
    about the foreign keys, they want the text value. Any
    advice, samples or places to read are appreciated.

    Thanks.
     
    Richard Roche, Jul 31, 2003
    #1
    1. Advertisements

  2. Richard Roche

    Eric Wise Guest

    Read up on datagrid template fields.

    "Richard Roche" <> wrote in message
    news:024501c3578c$ee23afe0$...
    > Is it possible to use a drop combo instead of a text box
    > when using the EditCommand in the Datagrid? Many table
    > columns are bound to 'lookup' tables, user's don't care
    > about the foreign keys, they want the text value. Any
    > advice, samples or places to read are appreciated.
    >
    > Thanks.
     
    Eric Wise, Jul 31, 2003
    #2
    1. Advertisements

  3. Hi Richard,

    We can change a Textbox to a DropDownList in Datagrid edit mode. Please see
    the following steps:

    1. Change the bound column to a template column. You can easily do this in
    the properties builder of the Datagrid. Select the columns tab, and then
    click the column in the "Select columns"listbox, and you will find a link
    "convert this column to a template column" upon "OK" button. Click the link
    then click OK.

    2. Right click the Datagrid and move to "Edit Template", then select the
    template column in the pop up menu, delete the textbox in the
    EditItemTemplate cell and add a DropDownList.

    3. In the code behind, initialize the DropDownList in the
    DataGrid1_ItemDataBound event:

    Here is a snippet:

    private void DataGrid1_ItemDataBound(object sender,
    System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemType == ListItemType.EditItem)
    {
    Control ctrl=e.Item.FindControl("DropDownList1");
    if(ctrl!=null)
    {
    DropDownList dropdown=(DropDownList)ctrl;
    dropdown.DataSource =DataGrid1.DataSource ;
    dropdown.DataTextField = "id";
    dropdown.DataValueField = "value";
    dropdown.DataBind ();
    }
    }
    }

    You can check these links for more information:

    Top Questions about the DataGrid Web Server Control
    <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstecha
    rt/html/vbtchtopquestionsaboutaspnetdatagridservercontrol.asp>

    Datagrid ... Combo instead of Textbox
    <http://www.dotnet247.com/247reference/msgs/5/28740.aspx>

    DataGrid.EditCommand Event
    <http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWebUIWebContr
    olsDataGridClassEditCommandTopic.asp>

    Please let me know if you need more information, thanks.

    Best Regards,
    Lewis

    Get Secure! - www.microsoft.com/security
    This posting is provided "AS IS" with no warranties, and confers no rights.

    --------------------
    | From: "Eric Wise" <>
    | References: <024501c3578c$ee23afe0$>
    | Subject: Re: datagrid editcommand
    | Date: Thu, 31 Jul 2003 15:41:30 -0400
    | Lines: 13
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2720.3000
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
    | Message-ID: <uS#>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | NNTP-Posting-Host: wva-guard-cn1.wva.army.mil 155.218.88.2
    | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
    | Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:163902
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    |
    | Read up on datagrid template fields.
    |
    | "Richard Roche" <> wrote in message
    | news:024501c3578c$ee23afe0$...
    | > Is it possible to use a drop combo instead of a text box
    | > when using the EditCommand in the Datagrid? Many table
    | > columns are bound to 'lookup' tables, user's don't care
    | > about the foreign keys, they want the text value. Any
    | > advice, samples or places to read are appreciated.
    | >
    | > Thanks.
    |
    |
    |
     
    Lewis Wang [MSFT], Aug 1, 2003
    #3
  4. Thanks, I have it working :>
     
    Richard Roche, Aug 1, 2003
    #4
  5. I am glad to hear it. Thanks very much for participating the community.

    Regards,
    Lewis

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

    --------------------
    | Content-Class: urn:content-classes:message
    | From: "Richard Roche" <>
    | Sender: "Richard Roche" <>
    | References: <024501c3578c$ee23afe0$>
    <uS#>
    <>
    | Subject: Re: datagrid editcommand
    | Date: Fri, 1 Aug 2003 15:37:15 -0700
    | Lines: 1
    | Message-ID: <04a401c3587d$74f47540$>
    | MIME-Version: 1.0
    | Content-Type: text/plain;
    | charset="iso-8859-1"
    | Content-Transfer-Encoding: 7bit
    | X-Newsreader: Microsoft CDO for Windows 2000
    | Thread-Index: AcNYfXT0stH/1Y/KSiKm5zsyX5piWw==
    | X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
    | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | Path: cpmsftngxa06.phx.gbl
    | Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:164278
    | NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    |
    | Thanks, I have it working :>
    |
     
    Lewis Wang [MSFT], Aug 4, 2003
    #5
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike
    Replies:
    0
    Views:
    454
  2. Linus
    Replies:
    0
    Views:
    617
    Linus
    Oct 8, 2004
  3. bill yeager

    datagrid editcommand question

    bill yeager, Nov 27, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,296
    bill yeager
    Nov 28, 2004
  4. =?Utf-8?B?amFjb2JyeWNl?=

    datagrid not visible when databind() on editcommand

    =?Utf-8?B?amFjb2JyeWNl?=, Feb 15, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    555
    Elton Wang
    Feb 15, 2005
  5. Stelios Skiathitis

    datagrid editcommand

    Stelios Skiathitis, Feb 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    504
    Stelios Skiathitis
    Feb 17, 2005
  6. js
    Replies:
    1
    Views:
    630
    Brock Allen
    May 17, 2005
  7. =?Utf-8?B?YmVub2l0?=

    Dynamic datagrid EditCommand problem

    =?Utf-8?B?YmVub2l0?=, Aug 19, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,864
    Teemu Keiski
    Aug 19, 2005
  8. =?Utf-8?B?Sm9l?=

    ItemCommand, EditCommand, etc in datagrid

    =?Utf-8?B?Sm9l?=, Oct 27, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    2,066
    =?Utf-8?B?RWx0b24gVw==?=
    Oct 27, 2005
Loading...