Professional Web Applications Themes

Edit Datagrid - show textbox and dropdown - ASP.NET Data Grid Control

Hi All, I have a problem trying to edit the data in a datagrid control. I have 2 bound columns in the datagrid. I have added the following code inorder to edit the data. I want it such that certain rows of data when edited will bring the textbox control while certain other rows will bring a dropdownlist from where i can select a value. is it possible to do that in the SAME template column? Any help will be much appreciated. Thanks, Anamika ---- <Columns> <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit" ItemStyle-HorizontalAlign="Center" HeaderText="Edit"> </asp:EditCommandColumn> <asp:BoundColumn DataField="Header" HeaderText="Application Field"></asp:BoundColumn> <asp:BoundColumn DataField="Value" ...

  1. #1

    Default Edit Datagrid - show textbox and dropdown

    Hi All,
    I have a problem trying to edit the data in a datagrid control.
    I have 2 bound columns in the datagrid. I have added the following
    code inorder to edit the data. I want it such that certain rows of
    data when edited will bring the textbox control while certain other
    rows will bring a dropdownlist from where i can select a value.

    is it possible to do that in the SAME template column?
    Any help will be much appreciated.

    Thanks,
    Anamika

    ----
    <Columns>
    <asp:EditCommandColumn
    ButtonType="LinkButton"
    UpdateText="Update"
    CancelText="Cancel"
    EditText="Edit"
    ItemStyle-HorizontalAlign="Center"
    HeaderText="Edit">
    </asp:EditCommandColumn>
    <asp:BoundColumn DataField="Header" HeaderText="Application
    Field"></asp:BoundColumn>
    <asp:BoundColumn DataField="Value" HeaderText="Field
    Value"></asp:BoundColumn>
    </Columns>
    Anamika Guest

  2. #2

    Default Re: Edit Datagrid - show textbox and dropdown

    Anamika wrote:
    > Hi All,
    > I have a problem trying to edit the data in a datagrid control.
    > I have 2 bound columns in the datagrid. I have added the following
    > code inorder to edit the data. I want it such that certain rows of
    > data when edited will bring the textbox control while certain other
    > rows will bring a dropdownlist from where i can select a value.
    >
    > is it possible to do that in the SAME template column?
    > Any help will be much appreciated.
    It is possible, yes. First, you'd have to use a TemplateColumn instead
    of a BoundColumn. To customize the editing interface, you need to use a
    TemplateColumn, as discussed in this article:
    [url]http://aspnet.4guysfromrolla.com/articles/080702-1.aspx[/url]

    Now, I assume you have some databound field that determines whether or
    not a TextBox should be shown or a DropDownList. In the simplest case,
    you could just toggle the Visible property based on this value.
    Something like (untested):

    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:TextBox ... Visible='<%#
    Convert.ToBoolean(DataBinder.Eval(Container.DataIt em, "ShowTextBox"))
    %>' ... />

    <asp:DropDownList ... Visible='<%# Not
    Convert.ToBoolean(DataBinder.Eval(Container.DataIt em, "ShowTextBox"))
    %>' ... />
    </ItemTemplate>
    </asp:TemplateColumn>

    This assumes that the ShowTextBox database field is a Boolean and
    indicates whether a TextBox should be shown (True) or a DropDownList
    (False).

    hth

    --

    Scott Mitchell
    [email]mitchell4guysfromrolla.com[/email]
    [url]http://www.4GuysFromRolla.com[/url]
    [url]http://www.ASPFAQs.com[/url]
    [url]http://www.ASPMessageboard.com[/url]

    * When you think ASP, think 4GuysFromRolla.com!
    Scott Mitchell [MVP] Guest

  3. #3

    Default Re: Edit Datagrid - show textbox and dropdown

    Hi Scott,
    Thanks for the response. I went through your site before posting here.
    I'll try toggling the controls during runtime like you suggested.

    Thanks,
    Anamika
    Anamika Guest

Similar Threads

  1. DataGrid Edit TextBox
    By Aidal in forum ASP.NET Data Grid Control
    Replies: 3
    Last Post: November 9th, 09:41 AM
  2. Replies: 0
    Last Post: April 5th, 03:58 AM
  3. Set the width of the edit textbox after clicking on Edit link in datagrid...
    By Sharon McCarty in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: November 24th, 06:41 PM
  4. TextBox and DropDown in a Datagrid ItemTemplate
    By mudasir.ahmed@gmail.com in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: November 12th, 08:12 PM
  5. Replies: 2
    Last Post: November 20th, 01:09 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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