Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hi,

i have a gridview control in that i have all the textboxes and out side the gridview i have one more textbox, what ever the value that i enter in the textbox i want to display that value in gridview textboxes

this is my code
XML
<asp:TextBox ID="TextBox1" runat="server">

<asp:GridView ID="GridView1" runat="server">
<columns>
<asp:TemplateField HeaderText="Maxmarks">
                               <ItemTemplate>
                                   <asp:TextBox ID="TextBox2" runat="server" Text='<%=(TextBox1.Text) %>'></asp:TextBox>
                               </ItemTemplate>
                           </asp:TemplateField>

</columns>


this is what i have written

thank you in advance
Posted
Updated 23-Nov-12 1:58am
v2

Fire the TextChanged event in the TextBox1.
More information here[^].
 
Share this answer
 
Comments
ChrisBoshoff.Net 23-Nov-12 6:55am    
Wouldnt this rebind the grid in order to get the desired effect...i may be mistaken? I would prefer to make a javascript method that fires on a client side OnKeyPress event on the text box (Add the attribute on first load). This method would then itterate through the grid view children controls and alter the text of the matching _TextBox2 controls.
Herman<T>.Instance 23-Nov-12 7:41am    
Yes it rebinds but when using caching (for example) it won't be that bad. Client side is an option too.
the following solution may helpful for you....

don't set the Text Property of your inner Testbox .

C#
protected void btnEnter_Click(object sender, EventArgs e)
      {
          //comment-use this commented code if you have to set value of textbax  for perticullar row
          //rowNumber = 0
          //GridViewRow row = (GridViewRow)grvTest.Rows[rowNumber];
          //TextBox txt = (TextBox)row.FindControl("txtTextBoxInGrid");
          //txt.Text = txtTextBoxOutsideGrid.Text;
          

          // use this code to set value of all text boxes in gridview
          foreach (GridViewRow row in grvTest.Rows)
          {
              TextBox txt = (TextBox)row.FindControl("txtTextBoxInGrid");
              txt.Text = txtTextBoxOutsideGrid.Text;
          }
      }
 
Share this answer
 
Comments
mahesh_chs 23-Nov-12 7:17am    
Thank you so much

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