how do i access a dropdownlists selected value in a datagrid edititemtemplate column from the selectedindexchanged event of another dropdownlist in a datagrid edititemtemplate column

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

  1. #1

    Default how do i access a dropdownlists selected value in a datagrid edititemtemplate column from the selectedindexchanged event of another dropdownlist in a datagrid edititemtemplate column

    i am trying to trap the value of one dropdownlist (in a datagrid
    edititemtemplate column) at the time its selectedindexchanged event
    fires and use its value to query a db and rebind a second dropdownlist
    (in a second datagrid edititemtemplate column).

    here's my code:

    <td width="9"><asp:datagrid id="dgManageVehicles" runat="server"
    Width="472px" AutoGenerateColumns="False" CellSpacing="1"
    CellPadding="3" BackColor="White" BorderWidth="2px"
    BorderStyle="Ridge" BorderColor="White" AllowSorting="True"
    DataKeyField="VehicleID" Height="216px">
    <SelectedItemStyle Font-Bold="True" ForeColor="White"
    BackColor="#9471DE"></SelectedItemStyle>
    <EditItemStyle Font-Size="Smaller" Font-Names="Arial"
    BorderWidth="2px" ForeColor="Lime" BorderStyle="Double"
    BorderColor="Black" BackColor="Aqua"></EditItemStyle>
    <ItemStyle Font-Size="9px" Font-Names="Verdana"
    ForeColor="White" BackColor="Black"></ItemStyle>
    <HeaderStyle Font-Size="10px" Font-Names="Verdana"
    Font-Bold="True" ForeColor="#E7E7FF" BorderStyle="None"
    BackColor="Black"></HeaderStyle>
    <FooterStyle ForeColor="Black"
    BackColor="#C6C3C6"></FooterStyle>
    <Columns>
    <asp:BoundColumn Visible="False" DataField="DealerID"
    HeaderText="DealerID"></asp:BoundColumn>
    <asp:BoundColumn Visible="False" DataField="VehicleID"
    HeaderText="VehicleID"></asp:BoundColumn>
    <asp:TemplateColumn HeaderText="Make">
    <ItemTemplate>
    <asp:label id="Label1" runat="server"
    ForeColor="White" Font-Names="Verdana">
    <%# DataBinder.Eval(Container.DataItem,
    "VehicleMake") %>
    </asp:label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:dropdownlist id=ddlEditMakes runat="server"
    Font-Names="Verdana" BackColor="White" Font-Size="10px"
    AutoPostBack="True" DataSource="<%# GetMakes %>"
    DataTextField="MakeDesc" DataValueField="MakeID"
    OnSelectedIndexChanged="MakeIndexChange_Command" SelectedIndex='<%#
    GetMakeSelIndex(DataBinder.Eval(Container.DataItem , "VehicleMake")) %>'
    >
    </asp:dropdownlist>
    </EditItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn HeaderText="Model">
    <ItemTemplate>
    <asp:label id="Label2" runat="server"
    ForeColor="White" Font-Names="Verdana">
    <%# DataBinder.Eval(Container.DataItem,
    "VehicleModel") %>
    </asp:label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:dropdownlist id="ddlEditMakeModel"
    runat="server" Font-Names="Verdana" BackColor="White"
    DataTextField="MODEL_DESCRIPTION" DataSource='<%#
    GetMakeModels(DataBinder.Eval(Container.DataItem, "VehicleMake")) %>'
    AutoPostBack="False" Font-Size="10px">
    </asp:dropdownlist>
    </EditItemTemplate>
    </asp:TemplateColumn>
    <asp:BoundColumn DataField="RegYear"
    HeaderText="Registration Year"></asp:BoundColumn>
    <asp:BoundColumn DataField="Engine_CC"
    HeaderText="Engine Size (cc)"></asp:BoundColumn>
    <asp:BoundColumn DataField="Body_desc"
    HeaderText="Body Type"></asp:BoundColumn>
    <asp:BoundColumn DataField="Colour"
    HeaderText="Colour"></asp:BoundColumn>
    <asp:BoundColumn DataField="Mileage"
    HeaderText="Mileage"></asp:BoundColumn>
    <asp:TemplateColumn HeaderText="New">
    <ItemTemplate>
    <asp:Checkbox id=chkIsNew runat="server"
    Checked='<%# DataBinder.Eval(Container.DataItem, "IsNew") %>'
    enabled="false">
    </asp:Checkbox>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:Checkbox id=ChkUPDIsNew runat="server"
    Checked='<%# DataBinder.Eval(Container.DataItem, "IsNew") %>'>
    </asp:Checkbox>
    </EditItemTemplate>
    </asp:TemplateColumn>
    <asp:BoundColumn DataField="Carfinderprice"
    HeaderText="Car Finder Price"></asp:BoundColumn>
    <asp:BoundColumn DataField="standardprice"
    HeaderText="Price"></asp:BoundColumn>
    <asp:BoundColumn DataField="lastupdated"
    ReadOnly="True" HeaderText="Last Updated"></asp:BoundColumn>
    <asp:ButtonColumn Text="Delete"
    ButtonType="PushButton" CommandName="Delete"></asp:ButtonColumn>
    <asp:EditCommandColumn ButtonType="PushButton"
    UpdateText="Update" CancelText="Cancel"
    EditText="Edit"></asp:EditCommandColumn>
    </Columns>
    <PagerStyle HorizontalAlign="Right" ForeColor="Black"
    BackColor="#C6C3C6"></PagerStyle>
    </asp:datagrid></td>

    Ive Got a custom event call :-

    OnSelectedIndexChanged="MakeIndexChange_Command"

    Q, what 'eventargs' do i need to pass to trap the selected value of the
    first dropdown from the datagrid and use it to rebind the second
    dropdown?

    Dave M Guest

  2. Similar Questions and Discussions

    1. Dropdownlist in template column to fire a SelectedIndexChanged event?
      I have a ddl in a template column of a data grid. The ddl displays fine. I'm having no luck though getting an event to fire when the user selects...
    2. 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"...
    3. How can i trap the SelectedIndexChanged event on a dropdown within a Datagrids EditItemTemplate column
      I have a datagrid with two edititemtemplate columns that contain dropdownlists, these are 1)lists manufacturers of cars, 2)lists car models for a...
    4. DropDownList in DataGrid EditItemTemplate Return Error
      I have a dropdown list in the edititem template of a data grid. I have no problems populating the dropdown box when I click edit. However, if I...
    5. Catching an SelectedIndexChanged event from a DropDownList inside a DataGrid
      Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate,...
  3. #2

    Default how do i access a dropdownlists selected value in a datagrid edititemtemplate column from the selectedindexchanged event of another dropdownlist in a datagrid edititemtemplate column

    i am trying to trap the value of one dropdownlist (in a datagrid
    edititemtemplate column) at the time its selectedindexchanged event
    fires and use its value to query a db and rebind a second dropdownlist
    (in a second datagrid edititemtemplate column).

    here's my code:

    <td width="9"><asp:datagrid id="dgManageVehicles" runat="server"
    Width="472px" AutoGenerateColumns="False" CellSpacing="1"
    CellPadding="3" BackColor="White" BorderWidth="2px"
    BorderStyle="Ridge" BorderColor="White" AllowSorting="True"
    DataKeyField="VehicleID" Height="216px">
    <SelectedItemStyle Font-Bold="True" ForeColor="White"
    BackColor="#9471DE"></SelectedItemStyle>
    <EditItemStyle Font-Size="Smaller" Font-Names="Arial"
    BorderWidth="2px" ForeColor="Lime" BorderStyle="Double"
    BorderColor="Black" BackColor="Aqua"></EditItemStyle>
    <ItemStyle Font-Size="9px" Font-Names="Verdana"
    ForeColor="White" BackColor="Black"></ItemStyle>
    <HeaderStyle Font-Size="10px" Font-Names="Verdana"
    Font-Bold="True" ForeColor="#E7E7FF" BorderStyle="None"
    BackColor="Black"></HeaderStyle>
    <FooterStyle ForeColor="Black"
    BackColor="#C6C3C6"></FooterStyle>
    <Columns>
    <asp:BoundColumn Visible="False" DataField="DealerID"
    HeaderText="DealerID"></asp:BoundColumn>
    <asp:BoundColumn Visible="False" DataField="VehicleID"
    HeaderText="VehicleID"></asp:BoundColumn>
    <asp:TemplateColumn HeaderText="Make">
    <ItemTemplate>
    <asp:label id="Label1" runat="server"
    ForeColor="White" Font-Names="Verdana">
    <%# DataBinder.Eval(Container.DataItem,
    "VehicleMake") %>
    </asp:label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:dropdownlist id=ddlEditMakes runat="server"
    Font-Names="Verdana" BackColor="White" Font-Size="10px"
    AutoPostBack="True" DataSource="<%# GetMakes %>"
    DataTextField="MakeDesc" DataValueField="MakeID"
    OnSelectedIndexChanged="MakeIndexChange_Command" SelectedIndex='<%#
    GetMakeSelIndex(DataBinder.Eval(Container.DataItem , "VehicleMake")) %>'
    >
    </asp:dropdownlist>
    </EditItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn HeaderText="Model">
    <ItemTemplate>
    <asp:label id="Label2" runat="server"
    ForeColor="White" Font-Names="Verdana">
    <%# DataBinder.Eval(Container.DataItem,
    "VehicleModel") %>
    </asp:label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:dropdownlist id="ddlEditMakeModel"
    runat="server" Font-Names="Verdana" BackColor="White"
    DataTextField="MODEL_DESCRIPTION" DataSource='<%#
    GetMakeModels(DataBinder.Eval(Container.DataItem, "VehicleMake")) %>'
    AutoPostBack="False" Font-Size="10px">
    </asp:dropdownlist>
    </EditItemTemplate>
    </asp:TemplateColumn>
    <asp:BoundColumn DataField="RegYear"
    HeaderText="Registration Year"></asp:BoundColumn>
    <asp:BoundColumn DataField="Engine_CC"
    HeaderText="Engine Size (cc)"></asp:BoundColumn>
    <asp:BoundColumn DataField="Body_desc"
    HeaderText="Body Type"></asp:BoundColumn>
    <asp:BoundColumn DataField="Colour"
    HeaderText="Colour"></asp:BoundColumn>
    <asp:BoundColumn DataField="Mileage"
    HeaderText="Mileage"></asp:BoundColumn>
    <asp:TemplateColumn HeaderText="New">
    <ItemTemplate>
    <asp:Checkbox id=chkIsNew runat="server"
    Checked='<%# DataBinder.Eval(Container.DataItem, "IsNew") %>'
    enabled="false">
    </asp:Checkbox>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:Checkbox id=ChkUPDIsNew runat="server"
    Checked='<%# DataBinder.Eval(Container.DataItem, "IsNew") %>'>
    </asp:Checkbox>
    </EditItemTemplate>
    </asp:TemplateColumn>
    <asp:BoundColumn DataField="Carfinderprice"
    HeaderText="Car Finder Price"></asp:BoundColumn>
    <asp:BoundColumn DataField="standardprice"
    HeaderText="Price"></asp:BoundColumn>
    <asp:BoundColumn DataField="lastupdated"
    ReadOnly="True" HeaderText="Last Updated"></asp:BoundColumn>
    <asp:ButtonColumn Text="Delete"
    ButtonType="PushButton" CommandName="Delete"></asp:ButtonColumn>
    <asp:EditCommandColumn ButtonType="PushButton"
    UpdateText="Update" CancelText="Cancel"
    EditText="Edit"></asp:EditCommandColumn>
    </Columns>
    <PagerStyle HorizontalAlign="Right" ForeColor="Black"
    BackColor="#C6C3C6"></PagerStyle>
    </asp:datagrid></td>

    Ive Got a custom event call :-

    OnSelectedIndexChanged="MakeIndexChange_Command"

    Q, what 'eventargs' do i need to pass to trap the selected value of the
    first dropdown from the datagrid and use it to rebind the second
    dropdown?

    Dave M 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