Hi Psure@423,
I have created sample that full-fill your requirement.
HTML
<div align="center">
<table>
<tr>
<td>
Name
</td>
<td>
<asp:TextBox runat="server" ID="txtName" />
</td>
</tr>
<tr>
<td>
Designation
</td>
<td>
<asp:DropDownList runat="server" ID="ddlDesignation">
<asp:ListItem Value="0" Text="Select" Selected="True" />
<asp:ListItem Value="0" Text="Software Engineer" />
<asp:ListItem Value="1" Text="Software Developer" />
<asp:ListItem Value="2" Text="Trainee" />
<asp:ListItem Value="3" Text="Manager" />
<asp:ListItem Value="4" Text="CEO" />
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
Qualification
</td>
<td>
<asp:DropDownList ID="ddlQualification" runat="server">
<asp:ListItem Value="0" Text="Select" Selected="True" />
<asp:ListItem Value="1" Text="10th" />
<asp:ListItem Value="2" Text="12th" />
<asp:ListItem Value="3" Text="BE/B.Tech" />
<asp:ListItem Value="4" Text="BSc" />
<asp:ListItem Value="5" Text="M.Tech" />
<asp:ListItem Value="6" Text="MSc" />
</asp:DropDownList>
</td>
</tr>
</table>
<br />
<br />
<asp:GridView runat="server" ID="gvRegistration" OnRowCommand="gvRegistration_RowCommand"
AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Designation" HeaderText="Designation" />
<asp:BoundField DataField="Qualification" HeaderText="Qualification" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnEdit" Text="Edit" runat="server" CommandName="EditRow" CommandArgument='<%# Container.DataItemIndex %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
BindGrid();
}
}
private void BindGrid()
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[4] {
new DataColumn("Id"),
new DataColumn("Name"),
new DataColumn("Designation"),
new DataColumn("Qualification") });
dt.Rows.Add("1", "Test 1", "Software Engineer", "BE/B.Tech");
dt.Rows.Add("2", "Test 2", "Trainee", "BSc");
dt.Rows.Add("3", "Test 3", "Software Developer", "BE/B.Tech");
dt.Rows.Add("4", "Test 4", "Null", "M.Tech");
dt.Rows.Add("5", "Test 5", "Manager", "");
dt.Rows.Add("6", "Test 6", "", "Null");
gvRegistration.DataSource = dt;
gvRegistration.DataBind();
}
protected void gvRegistration_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "EditRow")
{
int rowIndex = Convert.ToInt32(e.CommandArgument);
GridViewRow row = gvRegistration.Rows[rowIndex];
txtName.Text = row.Cells[1].Text.Trim();
ddlDesignation.ClearSelection();
if (!string.IsNullOrEmpty(row.Cells[2].Text.Trim()) && row.Cells[2].Text.Trim().ToUpper() != "NULL" && row.Cells[2].Text.Trim() != " ")
{
ddlDesignation.Items.FindByText(row.Cells[2].Text.Trim()).Selected = true;
}
else
{
ddlDesignation.SelectedIndex = -1;
}
ddlQualification.ClearSelection();
if (!string.IsNullOrEmpty(row.Cells[3].Text.Trim()) && row.Cells[3].Text.Trim().ToUpper() != "NULL" && row.Cells[3].Text.Trim() != " ")
{
ddlQualification.Items.FindByText(row.Cells[3].Text.Trim()).Selected = true;
}
else
{
ddlQualification.SelectedIndex = -1;
}
}
}
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
BindGrid()
End If
End Sub
Private Sub BindGrid()
Dim dt As New DataTable()
dt.Columns.AddRange(New DataColumn(3) {New DataColumn("Id"), New DataColumn("Name"), New DataColumn("Designation"), New DataColumn("Qualification")})
dt.Rows.Add("1", "Test 1", "Software Engineer", "BE/B.Tech")
dt.Rows.Add("2", "Test 2", "Trainee", "BSc")
dt.Rows.Add("3", "Test 3", "Software Developer", "BE/B.Tech")
dt.Rows.Add("4", "Test 4", "Null", "M.Tech")
dt.Rows.Add("5", "Test 5", "Manager", "")
dt.Rows.Add("6", "Test 6", "", "Null")
gvRegistration.DataSource = dt
gvRegistration.DataBind()
End Sub
Protected Sub gvRegistration_RowCommand(sender As Object, e As GridViewCommandEventArgs)
If e.CommandName = "EditRow" Then
Dim rowIndex As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = gvRegistration.Rows(rowIndex)
txtName.Text = row.Cells(1).Text.Trim()
ddlDesignation.ClearSelection()
If Not String.IsNullOrEmpty(row.Cells(2).Text.Trim()) AndAlso row.Cells(2).Text.Trim().ToUpper() <> "NULL" AndAlso row.Cells(2).Text.Trim() <> " " Then
ddlDesignation.Items.FindByText(row.Cells(2).Text.Trim()).Selected = True
Else
ddlDesignation.SelectedIndex = -1
End If
ddlQualification.ClearSelection()
If Not String.IsNullOrEmpty(row.Cells(3).Text.Trim()) AndAlso row.Cells(3).Text.Trim().ToUpper() <> "NULL" AndAlso row.Cells(3).Text.Trim() <> " " Then
ddlQualification.Items.FindByText(row.Cells(3).Text.Trim()).Selected = True
Else
ddlQualification.SelectedIndex = -1
End If
End If
End Sub
Screenshot