locked
How to select multiple item selection in Dropdown list and retrieve Data from Database? RRS feed

  • Question

  • User-367318540 posted

    I want to select multiple item selection in dropdown list and Display Data  in gridview ,base on selection.

    Below is code ,populating DropDownlist

    con.Open();
               SqlDataAdapter adp2 = new SqlDataAdapter("select * from Containerno where delid is null", con);
               DataSet ds2 = new DataSet();
     
               adp2.Fill(ds2);
               DDLContno.DataSource = ds2.Tables[0];
               DDLContno.DataTextField = "ContNo";
               DDLContno.DataValueField = "CID";
               DDLContno.DataBind();
               DDLContno.Items.Insert(0, new ListItem("Select Number", "0"));
     
               con.Close();
               con.Dispose();

    Below Data which is using to fill gridview ,base on dropdown list value

    SqlCommand cmd = new SqlCommand("[SP_Rags_Consume_bales_Pending]",con);
              
             cmd.Parameters.AddWithValue("@CID", DDLContno.SelectedValue);
              
             cmd.Connection = con;
     
             cmd.CommandType = CommandType.StoredProcedure;
             SqlDataAdapter da = new SqlDataAdapter(cmd);
     
             DataTable dt = new DataTable();
     
             da.Fill(dt);
             GVragsweight.DataSource = dt;
             GVragsweight.DataBind();
             con.Close();
             con.Dispose();

    above code is passing one value,but i want to select multiple value then in dropdown list then display data 

    Thursday, April 1, 2021 5:52 PM

Answers

  • User-939850651 posted

    Hi akhterr,

    Based on the content you provided, I did a simple test.

    First, I need to make sure that the content of your DropDownList binding is correct.

    akhterr

    DDLContno.DataSource = GetData("select * from Containerno where delid is null");
                DDLContno.DataTextField = "ContNo";
                DDLContno.DataValueField = "CID";

    When you can get it (the MasterPage is not yet used), in JavaScript you get the value of CID instead of ContNo. I am not sure if this is one of the causes of the problem.

    Second, when you put a webforms page into a template page, after the page loads, the controls in the page will be rendered and their IDs will also be changed, so your current Javascript may not be working, and you need to modify the selector to adapt to it.

    Something like this: 

    Modify selector like this:

    $('select[id*="DDLContno"]').on('change', function () {
           $('input[id*="hfSelected"]').val($(this).val());
     });

    Please check them, I think it will help you.

    Related documents: Control ID Naming in Content Pages - Step 2: Examining the RenderedIDChanges

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 7, 2021 6:30 AM

All replies

  • User475983607 posted

    I'm not sure I understand the question.  I think you are asking how to generate a ListBox in ASP.NET Web Forms.  A ListBox allow the user to select more than one item in the list.

    <asp:ListBox runat="server" ID="lblMultiSelect" SelectionMode="multiple">
        <asp:ListItem Text="Option 1" Value="1" />
        <asp:ListItem Text="Option 2" Value="2" />
        <asp:ListItem Text="Option 3" Value="3" />
    </asp:ListBox> 

    Thursday, April 1, 2021 7:43 PM
  • User-367318540 posted

    i want to use dropdownlist

    Friday, April 2, 2021 5:09 AM
  • User-939850651 posted

    Hi akhterr,

    i want to use dropdownlist

    There isnt a built in way to do this using DropDownList control.

    If you need to implement similar functions, I think you need to use some related plug-ins, for example: 

    https://www.jqueryscript.net/demo/jQuery-Multiple-Select-Plugin-For-Bootstrap-Bootstrap-Multiselect/

    Judging from your requirements, I think ListBox control is more suitable, of course it depends on you.

    Best regards,

    Xudong Peng

    Friday, April 2, 2021 6:22 AM
  • User-367318540 posted

    OK ,if i use it,but i do not know ,that how to pass multiple time same parameter from Database to Display Record in gridview from dropdownlist.

    as Like Below Code ,which i am using to Display Record in gridview ,from on Parameter 

    SqlCommand cmd = new SqlCommand("[SP_Rags_Consume_bales_Pending]",con);
              
             cmd.Parameters.AddWithValue("@CID", DDLContno.SelectedValue);
              
             cmd.Connection = con;
     
             cmd.CommandType = CommandType.StoredProcedure;
             SqlDataAdapter da = new SqlDataAdapter(cmd);
     
             DataTable dt = new DataTable();
     
             da.Fill(dt);
             GVragsweight.DataSource = dt;
             GVragsweight.DataBind();
             con.Close();
             con.Dispose();

    Friday, April 2, 2021 7:45 AM
  • User-939850651 posted

    Hi akhterr,

    OK ,if i use it,but i do not know ,that how to pass multiple time same parameter from Database to Display Record in gridview from dropdownlist.

    as Like Below Code ,which i am using to Display Record in gridview ,from on Parameter 

    No matter what method you will use to implement it, when you finally submit, what you should receive is a collection of data containing the selected option values.

    I'm not sure what your sql query is. If you need all the relevant data records, you could try to use SQL IN Operator, or traverse this collection and pass in the parameters one by one Stored procedure, and finally merge all results together.

    Best regards,

    Xudong Peng

    Friday, April 2, 2021 9:23 AM
  • User-367318540 posted

    I am using below query ,but data ,is not displaying'

    protected void Button1_Click(object sender, EventArgs e)
    {
        string query = ";with cte as( SELECT C.ContNo,C.entrydate as EntryDate, C.ConWeight as Act_weight,  ";
        query += "C.No_Of_Bales as Act_Qty,iSNULL(Sum(I.R_Weight), 0)Isu_Weight,iSNULL(Sum(i.R_QTY), 0)Isu_QTY,(C.ConWeight - iSNULL(Sum(I.R_Weight), 0)) as Pending_Weight, ";
        query += "(C.No_Of_Bales - iSNULL(Sum(i.R_QTY), 0)) as Pending_Qty ";
        query += "FROM Containerno C ";
        query += "inner   join tbl_ContD CD on CD.CID = C.CID left join tbl_Issuance_Rags I on I.D_ID = CD.D_ID ";
        query += "where C.delid is null and I.Delid is null and C.entrydate > '2020-12-31'   ";
        query += " group by  C.ContNo,C.Contrackno, C.ConWeight,C.No_Of_Bales,C.entrydate ";
        query += ") select ROW_NUMBER() OVER(ORDER BY ContNo) AS S_No, ContNo, Convert(varchar, EntryDate, 103) Date ,Act_weight,Act_Qty,Isu_Weight,Isu_QTY,Pending_Weight,Pending_Qty from cte ";
        query += "  where Pending_Qty > 0 and EntryDate > '2020-12-31' ";
        string condition = string.Empty;
        foreach (string item in hfSelected.Value.Split(','))
        {
            condition += string.Format("'{0}',", item);
        }
     
        if (!string.IsNullOrEmpty(condition))
        {
            query += " AND ContNo IN (" + condition.Substring(0, condition.Length - 1) + ")";
        }
     
        GVragsweight.DataSource = GetData(query);
        GVragsweight.DataBind();
    }
    private DataTable GetData(string query)
    {
        SqlCommand cmd = new SqlCommand(query);
        {
            using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
            {
                cmd.Connection = con;
                using (DataTable dt = new DataTable())
                {
                    sda.Fill(dt);
     
                    return dt;
                }
            }
        }
    }

    Monday, April 5, 2021 1:10 PM
  • User475983607 posted

    You need to understand, the community cannot run your code.  We do not have your table structure or data.  Plus, your problem description, but data ,is not displaying, is too vague to guess what the problem is.  I assume the query returns an empty set.

    I would get the final SQL string that's generated using the debugger or writing the SQL to the display.  Then review the SQL for correctness.  Next, executing the SQL script using SSMS.   Modify the SQL in SSMS until you get a working script or figure out what's wrong with the query.  Perhaps there is a space???

        foreach (string item in hfSelected.Value.Split(','))
        {
            condition += string.Format("'{0}',", item.Trim());
        }

    Monday, April 5, 2021 1:40 PM
  • User-367318540 posted

    I used same query ,where i am getting output, below image

    https://ibb.co/QvtGd27

    But in C# i am not getting result,

    What I want ,that is i am Populating dropdown list with multiple value, separating them with (,) ,here is code for populating Dropdown List

                con.Open();
                DDLContno.DataSource = GetData("select * from Containerno where delid is null");
                DDLContno.DataTextField = "ContNo";
                DDLContno.DataValueField = "CID";
                DDLContno.DataBind();

    Then i am using below Code ,for Fetching Data form Database.

       protected void Button1_Click(object sender, EventArgs e)
            {
                string query = "with cte as( SELECT C.ContNo,C.entrydate as EntryDate, C.ConWeight as Act_weight,  ";
                query += "C.No_Of_Bales as Act_Qty,iSNULL(Sum(I.R_Weight), 0)Isu_Weight,iSNULL(Sum(i.R_QTY), 0)Isu_QTY,(C.ConWeight - iSNULL(Sum(I.R_Weight), 0)) as Pending_Weight, ";
                query += "(C.No_Of_Bales - iSNULL(Sum(i.R_QTY), 0)) as Pending_Qty ";
                query += "FROM Containerno C ";
                query += "inner   join tbl_ContD CD on CD.CID = C.CID left join tbl_Issuance_Rags I on I.D_ID = CD.D_ID ";
                query += "where C.delid is null and I.Delid is null and C.entrydate > '2020-12-31'   ";
                query += " group by  C.ContNo,C.Contrackno, C.ConWeight,C.No_Of_Bales,C.entrydate ";
                query += ") select ROW_NUMBER() OVER(ORDER BY ContNo) AS S_No, ContNo, Convert(varchar, EntryDate, 103) Date ,Act_weight,Act_Qty,Isu_Weight,Isu_QTY,Pending_Weight,Pending_Qty from cte ";
                query += "  where Pending_Qty > 0 and EntryDate > '2020-12-31'  ";
                string condition = string.Empty;
                foreach (string item in hfSelected.Value.Split(','))
                {
                    condition += string.Format("'{0}',", item.Trim());
                }
    
                if (!string.IsNullOrEmpty(condition))
                {
                    query += " AND ContNo IN (" + condition.Substring(0, condition.Length - 1) + ")";
                }
    
                GVragsweight.DataSource = GetData(query);
                GVragsweight.DataBind();
            }
            private DataTable GetData(string query)
            {
                SqlCommand cmd = new SqlCommand(query);
                {
                    using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
                    {
                        cmd.Connection = con;
                        using (DataTable dt = new DataTable())
                        {
                            sda.Fill(dt);
    
                            return dt;
                        }
                    }
                }
            }
        }
    }
    

    Tuesday, April 6, 2021 9:30 AM
  • User475983607 posted

    I used same query ,where i am getting output, below image

    I'm confused by your response.  Did you follow the instructions in my last post?   Did you use the debugger to get the SQL script that is generated by your code then run the generated script in SSMS?  Does the generated SQL script produced a results set?

    If so, then there is a problem with the GridView binding.

    Tuesday, April 6, 2021 10:51 AM
  • User-367318540 posted

    Yes it is producing result in sql,I just figure out issue ,that is 

    I figure out the issue,when i am usingf form with MasterPage ,then it does not working,if i use it without masterpage then it is working fine.

     Master Page

    <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MasterPage.master.cs" Inherits="Appprd.MasterPage" %>
     
    <!DOCTYPE html>
     
    <html xmlns="http://www.w3.org/1999/xhtml">
        <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <style>
    body {
      font-family: Arial, Helvetica, sans-serif;
    }
     
    .navbar {
      overflow: hidden;
      background-color: #0026ff;
    }
     
    .navbar a {
      float: left;
      font-size: 12px;
      color: white;
      text-align: center;
      padding: 12px 14px;
      text-decoration: none;
    }
     
    .dropdown {
      float: left;
      overflow: hidden;
    }
     
    .dropdown .dropbtn {
      font-size: 12px; 
      border: none;
      outline: none;
      color: white;
      padding: 14px 16px;
      background-color: inherit;
      font-family: inherit;
      margin: 0;
    }
     
    .navbar a:hover, .dropdown:hover .dropbtn {
      background-color: orangered;
    }
     
    .dropdown-content {
      display: none;
      ;
      background-color: #fcfafa;
      min-width: 160px;
      box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
      z-index: 1;
    }
     
    .dropdown-content a {
      float: none;
      color: blue;
      padding: 12px 16px;
      text-decoration: none;
      display: block;
      text-align: left;
    }
     
    .dropdown-content a:hover {
      background-color: #ddd;
    }
     
    .dropdown:hover .dropdown-content {
      display: block;
    }
    </style>
    <head runat="server">
        <title></title>
        <asp:ContentPlaceHolder ID="head" runat="server">
        </asp:ContentPlaceHolder>
    </head>
    <body>
       <div class="navbar">
    <%--  <a href="#home">Home</a>
      <a href="#news">News</a>--%>
                <div class="dropdown">
          <button class="dropbtn">MasterFiles
          <i class="fa fa-caret-down"></i>
        </button>
        <div class="dropdown-content">
          <a href="ItemOpenForm.aspx">Item Master File SB</a>
                  <a href="itemBB.aspx">Item Master File BB</a>
               <a href="CusItemopen.aspx">Item Customer File</a>
     
          <a href="CustomerOpen.aspx">Customer</a>
               <a href="Section.aspx">Section</a>
          <a href="ImportOD.aspx">Import</a>
        </div>
      </div>
      <div class="dropdown">
        <button class="dropbtn">SmallBale
          <i class="fa fa-caret-down"></i>
        </button>
        <div class="dropdown-content">
          <a href="SBinputForm.aspx">Small Bale</a>
            <a href="DuplicateSBPR.aspx"> Duplicate Print</a>
        <a href="SalesOrder.aspx">Sales Order</a>
             <a href="SOInputFrm.aspx">New Sales Order</a>
             
          <a href="DailySBProduce.aspx">Daily Production</a>
               <a href="OrderRefSBProduction.aspx">Order Wise Status(QTY)</a>
                       <a href="ordwweigt.aspx">Order Wise Status(Weight)</a>
                         <a href="sbdaywise.aspx">Day Wise Status(QTY)</a>
              <a href="DayWiseProdSB.aspx">Item Day Wise Status</a>
             
          <a href="WorkerProductivity.aspx">Worker Productivity</a>
            <a href="AllItemView.aspx">All Items</a>
            <a href="TransferOrder.aspx">Bale Transfer</a>
            <a href="RepackingForm.aspx">Repacking</a>
            <a href="CustomerWisepb.aspx">CustomerWiseBale</a>
                <a href="MonthwiseSB.aspx">Month Wise Small Bale</a>
             
            <a href="SpiltExcel.aspx"> Spilt Excel</a>
        </div>
          </div>
           <div class="dropdown">
          <button class="dropbtn">BigBale
          <i class="fa fa-caret-down"></i>
        </button>
        <div class="dropdown-content">
          <a href="BBInputForm.aspx">BigBale_Input</a>
             <%--    <a href="BBBck.aspx">Back Entry</a>--%>
          <a href="BigbaleCat.aspx">Daily Production</a>
              <a href="BBSumary.aspx">Daily Production Summary</a>
                  <a href="DispatchBB.aspx">Dispatch</a>
               <a href="BBDisList.aspx">Dispatch List</a>
                       <a href="DispatchDetail.aspx">Stock</a>
              <a href="BBDEl.aspx">Delete Bale</a>
            <a href="BBDisM.aspx">Scan Bale</a>
        </div>
         
       
      </div>
             <div class="dropdown">
          <button class="dropbtn">Belt
          <i class="fa fa-caret-down"></i>
        </button>
        <div class="dropdown-content">
          <a href="ContOpening.aspx">Container Opening Form</a>
          <a href="Issurg.aspx">Daily Issuance Form</a>
               <a href="DlyIsueRpt.aspx">Daily Rags Issuance Detail</a>
             <a href="issuragsum.aspx">Rags Summary</a>
         <a href="RagsCOnsume.aspx">All Rags Status</a>
    <%--             <a href="RagsItemwise.aspx">Container Wise Status</a>
                <a href="Ragsweightdatewise.aspx">Container Date Wise Status</a>--%>
     
        </div>
         
          
      </div>
     
              <div class="dropdown">
          <button class="dropbtn">HR
          <i class="fa fa-caret-down"></i>
        </button>
        <div class="dropdown-content">
          <a href="employee.aspx">Employee File</a>
                 <a href="salgen.aspx">Salary Generate</a>
              <a href="salsum.aspx">Salary Summary</a>
        
        </div>
          </div>
     
                    <a href="DashBoard.aspx">DashBoard</a>
            <a href="LogingForm.aspx">Logout</a>
    </div>
     
        <form id="form1" runat="server">
        <div>
     
            <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
             
            </asp:ContentPlaceHolder>
        </div>
        </form>
    </body>
    </html>

    Page

    <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.Master"   AutoEventWireup="true" CodeBehind="RagsCOnsume.aspx.cs" Inherits="Appprd.RagsCOnsume" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    </asp:Content>
        <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
            <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" />
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $(".js-example-placeholder-single").select2({
                placeholder: "Select",
                allowClear: false
            });
            $('#DDLContno').on('change', function () {
                $('#hfSelected').val($(this).val());
            });           
        });
    </script>
    
      
        
               
    
        Search By Location :
            <asp:HiddenField ID="hfSelected" runat="server" />
        Container Weight :
            <asp:Label ID="lbSBP" Font-Size="Medium" runat="server" Text="."></asp:Label>
        
            <asp:DropDownList ID="DDLContno" runat="server" CssClass="form-control js-example-placeholder-single"           
                Height="117px"  multiple="multiple" data-placeholder="Select Country"  Width="200px">
            </asp:DropDownList>
        
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
        
            <asp:TextBox ID="TextBox1" visible="false" runat="server" TextMode="Date"></asp:TextBox>
            <asp:TextBox ID="TextBox2" visible="false" runat="server" TextMode="Date"></asp:TextBox>
            <asp:Button ID="View" runat="server"  Text="View" OnClick="View_Click" />
        
            <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">ExportExcel</asp:LinkButton>
        
       
            <table class="auto-style1">
                <tr>
                    <td class="auto-style2">
                        <asp:GridView ID="GVragsweight" runat="server" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" Width="596px" OnDataBound="GVragsweight_DataBound" OnSelectedIndexChanged="GVragsweight_SelectedIndexChanged" >
                            <%--<FooterStyle BackColor="White" ForeColor="#000066" />--%>
                            <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
                            <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
                            <RowStyle ForeColor="#000066" />
                            <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
                            <SortedAscendingCellStyle BackColor="#F1F1F1" />
                            <SortedAscendingHeaderStyle BackColor="#007DBB" />
                            <SortedDescendingCellStyle BackColor="#CAC9C9" />
                            <SortedDescendingHeaderStyle BackColor="#00547E" />
                        </asp:GridView>
                        </td></tr>
           </table>
            
    
    </html>
    
        </asp:Content>



    Tuesday, April 6, 2021 10:58 AM
  • User475983607 posted

    Learn how master and content pages work rather than guessing.  

    https://docs.microsoft.com/en-us/previous-versions/aspnet/wtxbf3hh(v=vs.100)

    Tuesday, April 6, 2021 11:07 AM
  • User-367318540 posted

    Why should i read it ,is this provide solution of my query?

    Tuesday, April 6, 2021 11:11 AM
  • User475983607 posted

    Why should i read it ,is this provide solution of my query?

    I'm very confused by your response.  The code you shared clearly shows that you have no idea how master and content pages work.  I thought you would be interested in fixing the invalid markup. 

    <%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="WebFormsDemo.Form._default" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    </asp:Content>
    
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
        Search By Location :
            <asp:HiddenField ID="hfSelected" runat="server" />
        Container Weight :
            <asp:Label ID="lbSBP" Font-Size="Medium" runat="server" Text="."></asp:Label>
    
        <asp:DropDownList ID="DDLContno" runat="server" CssClass="form-control js-example-placeholder-single"
            Height="117px" multiple="multiple" data-placeholder="Select Country" Width="200px">
        </asp:DropDownList>
    
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
    
        <asp:TextBox ID="TextBox1" Visible="false" runat="server" TextMode="Date"></asp:TextBox>
        <asp:TextBox ID="TextBox2" Visible="false" runat="server" TextMode="Date"></asp:TextBox>
        <asp:Button ID="View" runat="server" Text="View" OnClick="View_Click" />
    
        <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">ExportExcel</asp:LinkButton>
    
        <table class="auto-style1">
            <tr>
                <td class="auto-style2">
                    <asp:GridView ID="GVragsweight" runat="server" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" Width="596px" OnDataBound="GVragsweight_DataBound" OnSelectedIndexChanged="GVragsweight_SelectedIndexChanged">
                        <%--<FooterStyle BackColor="White" ForeColor="#000066" />--%>
                        <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
                        <RowStyle ForeColor="#000066" />
                        <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
                        <SortedAscendingCellStyle BackColor="#F1F1F1" />
                        <SortedAscendingHeaderStyle BackColor="#007DBB" />
                        <SortedDescendingCellStyle BackColor="#CAC9C9" />
                        <SortedDescendingHeaderStyle BackColor="#00547E" />
                    </asp:GridView>
                </td>
            </tr>
        </table>
    
    </asp:Content>
    

    I'm not sure why moving to a content page would cause this issue if the code works in a web form page.  I assume there are other issue with your code that we cannot see.  Please use the visual Studio debugger.

    Tuesday, April 6, 2021 11:24 AM
  • User-1477184872 posted

    Hi akhterr,

    You should check this out :

    If you need to implement similar functions, I think you need to use some related plug-ins, for example: 

    https://www.jqueryscript.net/demo/jQuery-Multiple-Select-Plugin-For-Bootstrap-Bootstrap-Multiselect/

    Judging from your requirements, I think ListBox control is more suitable, of course it depends on you.

    This works for me.

    Tuesday, April 6, 2021 8:33 PM
  • User-939850651 posted

    Hi akhterr,

    Based on the content you provided, I did a simple test.

    First, I need to make sure that the content of your DropDownList binding is correct.

    akhterr

    DDLContno.DataSource = GetData("select * from Containerno where delid is null");
                DDLContno.DataTextField = "ContNo";
                DDLContno.DataValueField = "CID";

    When you can get it (the MasterPage is not yet used), in JavaScript you get the value of CID instead of ContNo. I am not sure if this is one of the causes of the problem.

    Second, when you put a webforms page into a template page, after the page loads, the controls in the page will be rendered and their IDs will also be changed, so your current Javascript may not be working, and you need to modify the selector to adapt to it.

    Something like this: 

    Modify selector like this:

    $('select[id*="DDLContno"]').on('change', function () {
           $('input[id*="hfSelected"]').val($(this).val());
     });

    Please check them, I think it will help you.

    Related documents: Control ID Naming in Content Pages - Step 2: Examining the RenderedIDChanges

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 7, 2021 6:30 AM
  • Wednesday, April 7, 2021 2:57 PM