Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Gridview inside dropdownlist selected index change load the other control values

Gridview inside dropdownlist selected index change load the other control values

Scheduled Pinned Locked Moved ASP.NET
databasesysadmin
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 8390102
    wrote on last edited by
    #1

    <asp:DataList ID="dlCoordinates" runat="server" RepeatColumns="2" Width="730px" OnItemDataBound="dlCoordinates_ItemDataBound"
    OnItemCommand="dlCoordinates_ItemCommand">
    <ItemTemplate>
    <div class="left-block">
    <div class="pro-title pink">
    Co -ordinate
    <%--<%# Eval("ProductName")%>--%>
    </div>
    <div class="left">
    <asp:Image ID="imgCoordinates" runat="server" ImageUrl='<%# "~/Uploads/ThumbImage/"+Eval("BigImage") %>' />
    <asp:HiddenField ID="hdnIdProduct" runat="server" Value='<%# Eval("IdProduct") %>' />
    </div>
    <div class="right">
    <div class="block1">
    <p>
    <span id="spanCoProductDesc" runat="server">
    <%# Eval("ProductDesc") %></span></p>
    </div>
    <div class="block1">
    <h3 class="pink">
    Click swatch to view colours</h3>
    <div id="divCoSwatch" runat="server" class="color-box">
    </div>
    </div>
    <div class="block1">
    <h3>
    Price: <span id="spanCoProductPrice" runat="server" class=&qu

    R 1 Reply Last reply
    0
    • U User 8390102

      <asp:DataList ID="dlCoordinates" runat="server" RepeatColumns="2" Width="730px" OnItemDataBound="dlCoordinates_ItemDataBound"
      OnItemCommand="dlCoordinates_ItemCommand">
      <ItemTemplate>
      <div class="left-block">
      <div class="pro-title pink">
      Co -ordinate
      <%--<%# Eval("ProductName")%>--%>
      </div>
      <div class="left">
      <asp:Image ID="imgCoordinates" runat="server" ImageUrl='<%# "~/Uploads/ThumbImage/"+Eval("BigImage") %>' />
      <asp:HiddenField ID="hdnIdProduct" runat="server" Value='<%# Eval("IdProduct") %>' />
      </div>
      <div class="right">
      <div class="block1">
      <p>
      <span id="spanCoProductDesc" runat="server">
      <%# Eval("ProductDesc") %></span></p>
      </div>
      <div class="block1">
      <h3 class="pink">
      Click swatch to view colours</h3>
      <div id="divCoSwatch" runat="server" class="color-box">
      </div>
      </div>
      <div class="block1">
      <h3>
      Price: <span id="spanCoProductPrice" runat="server" class=&qu

      R Offline
      R Offline
      Reza Ahmadi
      wrote on last edited by
      #2

      Hi, I did it using a trick: 1- I used a HiddenField as one of my Bound fields in the DataList 2- I bound my key column to the HiddenField and to the ToolTip of your first DropDownList 3- I used drp_SelectedIndexChanged handler which is event handler of the first DropDownList to fill the second DropDown. Here is my sample(the most important parts):

      <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1"
      onselectedindexchanged="DataList1_SelectedIndexChanged" RepeatColumns="5">
      <ItemTemplate>
      <asp:HiddenField runat="server" ID="hiddenField" Value='<%# Eval("TableSeq") %>' />
      <asp:DropDownList runat="server" ID="drp" AutoPostBack="true" ToolTip='<%# Eval("TableSeq") %>'
      onselectedindexchanged="drp_SelectedIndexChanged">
      <asp:ListItem Value="1">1</asp:ListItem>
      <asp:ListItem Value="2">2</asp:ListItem>
      </asp:DropDownList>
      <br />
      <asp:DropDownList ID="drp2" runat="server" Height="16px">
      <asp:ListItem Value="5"></asp:ListItem>
      <asp:ListItem Value="4">4</asp:ListItem>
      </asp:DropDownList>
      <br />
      </ItemTemplate>
      </asp:DataList>

      and here is code behind:

      protected void drp_SelectedIndexChanged(object sender, EventArgs e)
      {
      DropDownList drop2 ;
      DropDownList drp = (DropDownList)sender;
      string key = drp.ToolTip;
      foreach (DataListItem item in DataList1.Items)
      {
      if (((HiddenField)item.FindControl("hiddenField")).Value == key)
      { //found
      drop2 = (DropDownList)item.FindControl("drp2");
      drop2.Items.Add(new ListItem("X", "X"));
      return;
      }
      }
      }

      I hope it will help, Cheers.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups