Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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
<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 23-Nov-12 1:29am
Edited 23-Nov-12 2:58am
__TR__29K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Fire the TextChanged event in the TextBox1.
More information here[^].
  Permalink  
Comments
ChrisBoshoff.Net at 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.
digimanus at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

the following solution may helpful for you....
 
don't set the Text Property of your inner Testbox .
 
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;
          }
      }
  Permalink  
Comments
mahesh_chs at 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)

  Print Answers RSS
0 DamithSL 320
1 OriginalGriff 195
2 Afzaal Ahmad Zeeshan 154
3 Zoltán Zörgő 149
4 Peter Leow 115
0 OriginalGriff 7,510
1 DamithSL 5,519
2 Sergey Alexandrovich Kryukov 4,994
3 Maciej Los 4,936
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100