I have updated my solution here by adding OnRowDataBound event in grid:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound="GridView_RowDataBound">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Country" HeaderText="Country" />
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
to add javascript use this:
<script type="text/javascript">
function Handlejavascript(text1, text2) {
document.getElementById(text2).value
document.getElementById(text1).value = document.getElementById(text2).value;
}
</script>
to call this use code in .cs file
protected void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TextBox TextBox1 = e.Row.FindControl("TextBox1") as TextBox;
TextBox TextBox2 = e.Row.FindControl("TextBox2") as TextBox;
TextBox2.Attributes.Add("onchange", "Handlejavascript('" + TextBox1.ClientID + "', '" + TextBox2.ClientID + "');");
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Country",typeof(string)) });
dt.Rows.Add(1, "VCJ", "United States");
dt.Rows.Add(2, "Your name", "India");
dt.Rows.Add(3, "My Name", "France");
dt.Rows.Add(4, "Gopinath", "India");
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
hope this might help you : if you want to show value pass that value as parameter in java script function