Hi @RAVI,
Is your girdivew data obtained from the database? If so, you can refer to the code below.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script>
$(function () {
$("#DropDownList1").change(function () {
document.getElementById('Label1').innerHTML = this.value;
})
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
<asp:Label ID="Label1" runat="server"></asp:Label>
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
</div>
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string constr = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT Field1, Field2, Field3 FROM Table_1"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
DropDownList1.DataSource = dt;
DropDownList1.DataBind();
DropDownList1.DataValueField = "Field2";
DropDownList1.DataTextField = "Field1";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, "Select");
}
}
}
}
}
}
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.