Professional Web Applications Themes

When do I assign a SelectedIndexChanged event handler for DropDownLists inside a DataGrid? - ASP.NET Data Grid Control

Hi, Remember my data-bound DropDownList embedded in a TemplateColumn inside a data-bound DataGrid? <asp:DataGrid id="grdProducts" runat="server" DataSource="<%# myPortfolio.Products %>" AutoGenerateColumns="False" DataKeyField="Id"> <Columns> <asp:TemplateColumn HeaderText="Vendor"> <ItemTemplate> <asp:DropDownList id=ddlVendor runat="server" DataValueField="Id" DataTextField="Name" DataSource="<%# BL.Vendor.GetAll() %>" AutoPostBack="True"> </asp:DropDownList> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:DataGrid> Now I need to assign a specific event handler to handle the SelectedIndexChanged event on the DropDownLists in each row of the DataGrid. When should I do this? I've tried doing in in the Page_Load handler, in the DataGrid_ItemBound handler and the DataGrid_ItemCreated handler, but my SelectedIndexChanged event handler is never triggered. Can someone point me in the right direction? Also, ...

  1. #1

    Default When do I assign a SelectedIndexChanged event handler for DropDownLists inside a DataGrid?

    Hi,

    Remember my data-bound DropDownList embedded in a TemplateColumn
    inside a data-bound DataGrid?

    <asp:DataGrid id="grdProducts" runat="server" DataSource="<%#
    myPortfolio.Products %>"
    AutoGenerateColumns="False" DataKeyField="Id">
    <Columns>
    <asp:TemplateColumn HeaderText="Vendor">
    <ItemTemplate>
    <asp:DropDownList id=ddlVendor runat="server"
    DataValueField="Id" DataTextField="Name"
    DataSource="<%# BL.Vendor.GetAll() %>"
    AutoPostBack="True">
    </asp:DropDownList>
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:DataGrid>

    Now I need to assign a specific event handler to handle the
    SelectedIndexChanged
    event on the DropDownLists in each row of the DataGrid.

    When should I do this? I've tried doing in in the Page_Load handler, in the
    DataGrid_ItemBound handler and the DataGrid_ItemCreated handler, but my
    SelectedIndexChanged event handler is
    never triggered.

    Can someone point me in the right direction?

    Also, I guess that if my DataGrid has 3 items (rows) then there will be 3
    different drop down
    lists all with the same name - "ddlVendor". Is this a problem and how can
    I overcome it?


    Thanks in advance!
    Uri from Israel


    Uri Guest

  2. #2

    Default When do I assign a SelectedIndexChanged event handler for DropDownLists inside a DataGrid?

    Hi Uri,

    In order to trigger selectedIndexChanged event you should
    have OnSelectedIndexChanged="MathodName" in DropDownList
    tags.

    HTH

    Elton Wang
    [email]elton_Wanghotmail.com[/email]

    >-----Original Message-----
    >Hi,
    >
    >Remember my data-bound DropDownList embedded in a
    TemplateColumn
    >inside a data-bound DataGrid?
    >
    ><asp:DataGrid id="grdProducts" runat="server"
    DataSource="<%#
    >myPortfolio.Products %>"
    > AutoGenerateColumns="False" DataKeyField="Id">
    > <Columns>
    > <asp:TemplateColumn HeaderText="Vendor">
    > <ItemTemplate>
    > <asp:DropDownList id=ddlVendor
    runat="server"
    > DataValueField="Id"
    DataTextField="Name"
    > DataSource="<%# BL.Vendor.GetAll() %>"
    > AutoPostBack="True">
    > </asp:DropDownList>
    > </ItemTemplate>
    > </asp:TemplateColumn>
    > </Columns>
    ></asp:DataGrid>
    >
    >Now I need to assign a specific event handler to handle
    the
    >SelectedIndexChanged
    >event on the DropDownLists in each row of the DataGrid.
    >
    >When should I do this? I've tried doing in in the
    Page_Load handler, in the
    >DataGrid_ItemBound handler and the DataGrid_ItemCreated
    handler, but my
    >SelectedIndexChanged event handler is
    >never triggered.
    >
    >Can someone point me in the right direction?
    >
    >Also, I guess that if my DataGrid has 3 items (rows) then
    there will be 3
    >different drop down
    >lists all with the same name - "ddlVendor". Is this a
    problem and how can
    >I overcome it?
    >
    >
    >Thanks in advance!
    >Uri from Israel
    >
    >
    >.
    >
    Elton Wang Guest

  3. #3

    Default Re: When do I assign a SelectedIndexChanged event handler for DropDownLists inside a DataGrid?

    Uri,

    Assigning an event handler:

    <asp:DropDownList id=ddlVendor runat="server"
    DataValueField="Id" DataTextField="Name"
    DataSource="<%# BL.Vendor.GetAll() %>"
    AutoPostBack="True"
    SelectedIndexChanged=myHandler>
    </asp:DropDownList>

    If you want to define myHandler in code behind, it should have a signature:

    protected void myHandler (object sender, System.EventArgs e)

    In parameter sender the handler will receive a reference to the ddl
    initiated the event.

    You don't need to overcome the same id problem, it doesn't exist. If you
    view the html source of your page when it is viewed in a browser you will
    find that every ddl is rendered as an html <select> element with it's own
    unique id. You may want to look into help on web control's UniqueId and
    ClientId properties.


    Eliyahu

    "Uri" <uri.removedotkedemtech.co.il> wrote in message
    news:42511fb8$1news.bezeqint.net...
    > Hi,
    >
    > Remember my data-bound DropDownList embedded in a TemplateColumn
    > inside a data-bound DataGrid?
    >
    > <asp:DataGrid id="grdProducts" runat="server" DataSource="<%#
    > myPortfolio.Products %>"
    > AutoGenerateColumns="False" DataKeyField="Id">
    > <Columns>
    > <asp:TemplateColumn HeaderText="Vendor">
    > <ItemTemplate>
    > <asp:DropDownList id=ddlVendor runat="server"
    > DataValueField="Id" DataTextField="Name"
    > DataSource="<%# BL.Vendor.GetAll() %>"
    > AutoPostBack="True">
    > </asp:DropDownList>
    > </ItemTemplate>
    > </asp:TemplateColumn>
    > </Columns>
    > </asp:DataGrid>
    >
    > Now I need to assign a specific event handler to handle the
    > SelectedIndexChanged
    > event on the DropDownLists in each row of the DataGrid.
    >
    > When should I do this? I've tried doing in in the Page_Load handler, in
    the
    > DataGrid_ItemBound handler and the DataGrid_ItemCreated handler, but my
    > SelectedIndexChanged event handler is
    > never triggered.
    >
    > Can someone point me in the right direction?
    >
    > Also, I guess that if my DataGrid has 3 items (rows) then there will be 3
    > different drop down
    > lists all with the same name - "ddlVendor". Is this a problem and how
    can
    > I overcome it?
    >
    >
    > Thanks in advance!
    > Uri from Israel
    >
    >

    Eliyahu Goldin Guest

  4. #4

    Default Re: When do I assign a SelectedIndexChanged event handler for DropDownLists inside a DataGrid?

    Correction:
    Elton is right, it should be
    OnSelectedIndexChanged=myHandler>


    Eliyahu

    "Eliyahu Goldin" <removemeegoldinmonarchmed.com> wrote in message
    news:uaxQ3UROFHA.2520tk2msftngp13.phx.gbl...
    > Uri,
    >
    > Assigning an event handler:
    >
    > <asp:DropDownList id=ddlVendor runat="server"
    > DataValueField="Id" DataTextField="Name"
    > DataSource="<%# BL.Vendor.GetAll() %>"
    > AutoPostBack="True"
    > SelectedIndexChanged=myHandler>
    > </asp:DropDownList>
    >
    > If you want to define myHandler in code behind, it should have a
    signature:
    >
    > protected void myHandler (object sender, System.EventArgs e)
    >
    > In parameter sender the handler will receive a reference to the ddl
    > initiated the event.
    >
    > You don't need to overcome the same id problem, it doesn't exist. If you
    > view the html source of your page when it is viewed in a browser you will
    > find that every ddl is rendered as an html <select> element with it's own
    > unique id. You may want to look into help on web control's UniqueId and
    > ClientId properties.
    >
    >
    > Eliyahu
    >
    > "Uri" <uri.removedotkedemtech.co.il> wrote in message
    > news:42511fb8$1news.bezeqint.net...
    > > Hi,
    > >
    > > Remember my data-bound DropDownList embedded in a TemplateColumn
    > > inside a data-bound DataGrid?
    > >
    > > <asp:DataGrid id="grdProducts" runat="server" DataSource="<%#
    > > myPortfolio.Products %>"
    > > AutoGenerateColumns="False" DataKeyField="Id">
    > > <Columns>
    > > <asp:TemplateColumn HeaderText="Vendor">
    > > <ItemTemplate>
    > > <asp:DropDownList id=ddlVendor runat="server"
    > > DataValueField="Id" DataTextField="Name"
    > > DataSource="<%# BL.Vendor.GetAll() %>"
    > > AutoPostBack="True">
    > > </asp:DropDownList>
    > > </ItemTemplate>
    > > </asp:TemplateColumn>
    > > </Columns>
    > > </asp:DataGrid>
    > >
    > > Now I need to assign a specific event handler to handle the
    > > SelectedIndexChanged
    > > event on the DropDownLists in each row of the DataGrid.
    > >
    > > When should I do this? I've tried doing in in the Page_Load handler, in
    > the
    > > DataGrid_ItemBound handler and the DataGrid_ItemCreated handler, but my
    > > SelectedIndexChanged event handler is
    > > never triggered.
    > >
    > > Can someone point me in the right direction?
    > >
    > > Also, I guess that if my DataGrid has 3 items (rows) then there will be
    3
    > > different drop down
    > > lists all with the same name - "ddlVendor". Is this a problem and how
    > can
    > > I overcome it?
    > >
    > >
    > > Thanks in advance!
    > > Uri from Israel
    > >
    > >
    >
    >

    Eliyahu Goldin Guest

Similar Threads

  1. Replies: 1
    Last Post: December 14th, 11:53 AM
  2. SelectedIndexChanged is not working for my comdobox inside of a datagrid
    By Jason Tepe in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: August 26th, 05:25 PM
  3. DataGrid's UpdateCommand event handler and CancelCommand handler problem
    By David Mans in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: July 29th, 05:52 AM
  4. Replies: 0
    Last Post: July 28th, 11:40 PM
  5. Replies: 5
    Last Post: July 4th, 04:43 AM

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