Click here to Skip to main content
15,940,271 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)

My question posted in given below link, kindly send me a suggestion ASAP. Awaiting for good response.[^]
VC.J 9-Oct-14 0:59am    
you can use ViewState or Session to save the rows
Gopinath C 9-Oct-14 1:34am    
Hi, am using view state to capture last entered values but problem where i found is in Textbox change event. Textbox event in row affect other rows. How to effect textbox event only for particular textbox.
VC.J 9-Oct-14 1:46am    
why you need text change event inside grid view it fire an event and refreshing the grid that is the reason its affecting other textbox you may handle it in client end by using javascript
or try this
may be this help
Gopinath C 9-Oct-14 2:03am    
Yes VC.J, i need textbox text change event in grid view textboxes. since when i item enter item number, its description and its cost has to come automatically.

And i saw the link that you shared. there they use code in ispostback function. here how can i use my addnewrow function in ispostback?
How can i use this in Javascript. kindly suggest.
VC.J 9-Oct-14 2:53am    
@Gopinath ,I have just update the code below use the clue from that code to call javascript function

1 solution

I have updated my solution here by adding OnRowDataBound event in grid:

<asp:GridView ID="GridView1" runat="server"  AutoGenerateColumns="false" OnRowDataBound="GridView_RowDataBound">
        <asp:BoundField DataField="Name" HeaderText="Name" />
        <asp:BoundField DataField="Country" HeaderText="Country" />
                <asp:TextBox ID="TextBox1" runat="server"  /> 
                <asp:TextBox ID="TextBox2" runat="server"  /> 

to add javascript use this:

<script type="text/javascript">
         function Handlejavascript(text1, text2) {
             document.getElementById(text1).value = document.getElementById(text2).value;

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;
                //TextBox TextBox3 = 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;

hope this might help you : if you want to show value pass that value as parameter in java script function
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900