469,919 Members | 2,140 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,919 developers. It's quick & easy.

Problem with getting the value on GridView

I'm working with GridView. But it seems rough.
When I add a Command Field (Edit, Update image button type) handly. The OnRowUpdating doesn't fire when I click on Update button.

Then I change by delete the Command Fiel I've created and use AutoGenerateEditButton property of the GridView and it does work. The function OnRowUpdating does fire.

But I've got another trouble with this way.
I can't get the changed value of the textbox in editting mode.

Here is my code:
Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="grvDsMatHang" runat="server" 
  2.                 AutoGenerateColumns="true" AllowPaging="True" 
  3.                 PageSize="5" Width="98%" 
  4.                 OnRowCancelingEdit="grvDsMatHang_RowCancelingEdit" 
  5.                 OnRowEditing="grvDsMatHang_RowEditing" 
  6.                 OnRowUpdating="grvDsMatHang_RowUpdating"
  7.                  AutoGenerateEditButton="true" 
  8. AutoGenerateDeleteButton="true" >
...<some definittions here>

Expand|Select|Wrap|Line Numbers
  1. <EditItemTemplate>
  2. //my TextBox in editting mode
  3.        <asp:TextBox ID="txtTenMH" runat="server" Text='' idth="50px"></asp:TextBox>
  4.  
  5.        <asp:HiddenField ID="hdnMoTa" runat="server" Value='<%# DataBinder.Eval(Container,"DataItem.MOTA") %>' />
  6.  
  7. </EditItemTemplate>
My code in .cs file to get the changed value of the TextBox

Expand|Select|Wrap|Line Numbers
  1. String n_Ten_MH = (row.FindControl("txtTenMH") as TextBox).Text;
The the value of n_Ten_MH still equals "" even I did type something in that textbox

Thanks in advance for noting my problems
Oct 9 '08 #1
2 1114
kenobewan
4,871 Expert 4TB
Here is a quickstart article that may help:
Gridview
Oct 9 '08 #2
Frinavale
9,735 Expert Mod 8TB
Are you doing a DataBind on your GridView in your PageLoad?
If you do a DataBind on your GridView before the Edit occurs, you will lose the data that was entered while editing.

-Frinny
Oct 9 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by WebBuilder451 | last post: by
3 posts views Thread by shapper | last post: by
6 posts views Thread by Greg | last post: by
3 posts views Thread by David C | last post: by
reply views Thread by db007 | last post: by
11 posts views Thread by Ed Dror | last post: by
1 post views Thread by siri11 | last post: by
reply views Thread by Jeff | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.