Hi Vincenzo67,
Please refer below sample.
HTML
<form id="form1" runat="server">
<asp:Label ID="lblDetails" runat="server"></asp:Label>
<asp:GridView ID="gvCustomers" runat="server" EmptyDataText="No data" EnableViewState="true" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Country" HeaderText="Country" />
<asp:TemplateField HeaderText="ddl1">
<ItemTemplate>
<asp:DropDownList ID="ddl1" runat="server"
AutoPostBack="true"
OnSelectedIndexChanged="OnSelectedIndexChanged">
<asp:ListItem Text="[ === === === ]" Value=""></asp:ListItem>
<asp:ListItem Text="OK" Value="OK"></asp:ListItem>
<asp:ListItem Text="KO" Value="KO"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField
HeaderText="ddl2">
<ItemTemplate>
<asp:DropDownList ID="ddl2" runat="server"
AutoPostBack="true"
OnSelectedIndexChanged="OnSelectedIndexChanged">
<asp:ListItem Text="[ === === === ]" Value=""></asp:ListItem>
<asp:ListItem Text="OK" Value="OK"></asp:ListItem>
<asp:ListItem Text="KO" Value="KO"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</form>
Namespaces
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[2] { new DataColumn("Name"), new DataColumn("Country") });
dt.Rows.Add("Robert", "USA");
dt.Rows.Add("Mudassar", "India");
gvCustomers.DataSource = dt;
gvCustomers.DataBind();
}
}
protected void OnSelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddl = (DropDownList)sender;
GridViewRow row = (GridViewRow)ddl.NamingContainer;
string ddl1 = row.Cells[0].Text;
string ddl2 = row.Cells[1].Text;
lblDetails.Text = ddl1 + "<br />" + ddl2;
}
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(1) {New DataColumn("Name"), New DataColumn("Country")})
dt.Rows.Add("Robert", "USA")
dt.Rows.Add("Mudassar", "India")
gvCustomers.DataSource = dt
gvCustomers.DataBind()
End If
End Sub
Protected Sub OnSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim ddl As DropDownList = CType(sender, DropDownList)
Dim row As GridViewRow = CType(ddl.NamingContainer, GridViewRow)
Dim ddl1 As String = row.Cells(0).Text
Dim ddl2 As String = row.Cells(1).Text
lblDetails.text = ddl1 & "<br />" & ddl2
End Sub
Screenshot