Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to display the gridview row value in the dropdownlist box and i have used the below code for the textbox but it doesn't work for the dropdownlist box.

What I have tried:

var row = $(this).closest('tr');
var ID = row.find("td:first").text();
$("#<%=TextBox12.ClientID%>").val(ID);
Posted
Updated 12-Nov-16 4:01am
Comments
Karthik_Mahalingam 8-Nov-16 4:51am    
during on load or on row button click?
Aashish68 8-Nov-16 8:06am    
During on Load
Karthik_Mahalingam 8-Nov-16 23:21pm    
what is the structure of the grid

1 solution

Here is one example with simple gridview, on button click, one column values are loaded into dropdownlist, hope this helps

ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeBehind="gridvJq.aspx.cs" Inherits="WebApplication1.gridvJq" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script src="Scripts/jquery-1.7.min.js"></script>
    <script src="Scripts/jquery-1.7.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#Button1").click(function () {
                $("#<%=GridView1.ClientID %> tr").each(function () {
                    if (!this.rowIndex) return;
                    var cellval = $(this).find("td:nth-last-child(2)").html();
                    $('#DropDownList1').append($("<option></option>").val(cellval).html(cellval));

                });
                return false;
            });
        });

    </script>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:GridView ID="GridView1" runat="server"></asp:GridView>
            <br />
            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
            <br />
            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"></asp:DropDownList>
        </div>
    </form>
</body>
</html>
 
Share this answer
 
Comments
Aashish68 14-Nov-16 0:38am    
Like this how to get from Database?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900