Hi Amitabha,
Check this example. Now please take its reference and correct your code.
HTML
<asp:DropDownList ID="ddlFormCountry" runat="server">
<asp:ListItem Text="Select" Value="" />
<asp:ListItem Text="India" Value="India" />
<asp:ListItem Text="China" Value="China" />
<asp:ListItem Text="USA" Value="USA" />
<asp:ListItem Text="UK" Value="UK" />
<asp:ListItem Text="Canada" Value="Canada" />
<asp:ListItem Text="Pakistan" Value="Pakistan" />
</asp:DropDownList>
<hr />
<asp:DataGrid ID="dataGridView1" runat="server"
AutoGenerateColumns="false" CellPadding="3" Width="100%" HeaderStyle-BackColor="SlateGray"
HeaderStyle-Font-Size="X-Small" HeaderStyle-Font-Names="Calisto MT" ItemStyle-Font-Size="Small"
ItemStyle-Font-Names="Calisto MT" HeaderStyle-ForeColor="White">
<Columns>
<asp:TemplateColumn HeaderText="Name">
<ItemTemplate>
<asp:DropDownList ID="ddlName" runat="server">
<asp:ListItem Text="Select" Value="" />
<asp:ListItem Text="John Hammond" Value="1" />
<asp:ListItem Text="Mudassar Khan" Value="2" />
<asp:ListItem Text="Suzanne Mathews" Value="3" />
<asp:ListItem Text="Robert Schidner" Value="4" />
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Country">
<ItemTemplate>
<asp:DropDownList ID="ddlCountry" runat="server"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Id" HeaderText="Id" Visible="False"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=ddlName]").change(function () {
var row = $(this).closest("tr");
var ddlCountry = row.find("[id*=ddlCountry]");
$(ddlCountry).empty().append($('#ddlFormCountry').html());
$(ddlCountry).val($('#ddlFormCountry').find('option:selected').val());
});
});
</script>
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3]
{
new DataColumn("Id"),
new DataColumn("Name"),
new DataColumn("Country")
});
dt.Rows.Add(1, "John Hammond", "United States");
dt.Rows.Add(2, "Mudassar Khan", "India");
dt.Rows.Add(3, "Suzanne Mathews", "France");
dt.Rows.Add(4, "Robert Schidner", "Russia");
dataGridView1.DataSource = dt;
dataGridView1.DataBind();
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn(2) {
New DataColumn("Id"),
New DataColumn("Name"),
New DataColumn("Country")})
dt.Rows.Add(1, "John Hammond", "United States")
dt.Rows.Add(2, "Mudassar Khan", "India")
dt.Rows.Add(3, "Suzanne Mathews", "France")
dt.Rows.Add(4, "Robert Schidner", "Russia")
dataGridView1.DataSource = dt
dataGridView1.DataBind()
End If
End Sub
Screenshot