Hi makumbi,
You need to use both the TextBoxes inside the UpdatePanel.
Please refer below sample,
HTML
<asp:ScriptManager runat="server" />
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtDiagnosisdata" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="txtTreatmentdata" runat="server"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
<hr />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="gvPatients" runat="server" AutoGenerateColumns="false"
OnRowCommand="OnRowCommand">
<Columns>
<asp:BoundField HeaderText="Diagnosis" DataField="Diagnosis" />
<asp:BoundField HeaderText="Treatment" DataField="Treatment" />
<asp:ButtonField CommandName="Select" HeaderText="Select" Text="Select" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
Namespace
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("Diagnosis"),
new DataColumn("Treatment")});
dt.Rows.Add("Fever", "Injection");
dt.Rows.Add("Cancer", "Tablet");
dt.Rows.Add("Caugh", "Syrup");
gvPatients.DataSource = dt;
gvPatients.DataBind();
}
}
protected void OnRowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Select")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = gvPatients.Rows[index];
txtDiagnosisdata.Text = row.Cells[1].Text;
txtTreatmentdata.Text = row.Cells[0].Text;
}
}
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("Diagnosis"), New DataColumn("Treatment")})
dt.Rows.Add("Fever", "Injection")
dt.Rows.Add("Cancer", "Tablet")
dt.Rows.Add("Caugh", "Syrup")
gvPatients.DataSource = dt
gvPatients.DataBind()
End If
End Sub
Protected Sub OnRowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
If e.CommandName = "Select" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = gvPatients.Rows(index)
txtDiagnosisdata.Text = row.Cells(1).Text
txtTreatmentdata.Text = row.Cells(0).Text
End If
End Sub
Screenshot