Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
protected void GVVAC_RowUpdating(object sender, GridViewUpdateEventArgs e)
   {
       DataTable dt = new DataTable();
       int st = Convert.ToInt32(GVVAC.DataKeys[e.RowIndex].Values[0].ToString());
       TextBox txtage1 = (TextBox)GVVAC.Rows[e.RowIndex].FindControl("txtage");
       TextBox txtvaccinename1 = (TextBox)GVVAC.Rows[e.RowIndex].Cells[3].Controls[1];
       TextBox txtadmin1 = (TextBox)GVVAC.Rows[e.RowIndex].Cells[4].Controls[1];
       TextBox txtdose1 = (TextBox)GVVAC.Rows[e.RowIndex].Cells[5].Controls[1];

       breederdailypl.Age = Convert.ToInt32(txtage1.Text.ToString());
       breederdailypl.vaccine = txtvaccinename1.Text.ToString();
       breederdailypl.admin = txtadmin1.Text.ToString();
       breederdailypl.dose = txtdose1.Text.ToString();



       breederdailypl.Snum = st;
       dt = breederdailybal.updatevaccine(breederdailypl);
       //chkHatchdetails = objhatcheryBAL.updateHatchMasterdet(objhatcheryPL);
       ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "UpdateDetails", "alert('Update Successful');", true);
       GVVAC.EditIndex = -1;

       grid();





   }



when i edit the textbox and enter the new value ,but new value is not come to the textbox... .please help me
Posted
Updated 7-Nov-13 18:37pm
v2
Comments
Raajkumar.b 7-Nov-13 23:43pm    
Try like This
GridViewRow R = GridView1.Rows[e.RowIndex];
TextBox txtword = (TextBox)R.FindControl("txtage");
string word = txtage.Text;
JoCodes 7-Nov-13 23:55pm    
Which textbox?all the textboxs? Use Findcontrol to access the controls which is inside the templatefield of Gridview as Raajkumar commented.Can you post your gridview markup code too on how you have used the edititemtemplatefield
Siva Hyderabad 8-Nov-13 0:10am    
<asp:GridView ID="GVVAC" runat="server" DataKeyNames="sno,age,VaccineName,hoconfby,farconfby" AutoGenerateColumns="false"
OnRowDataBound="GVVAC_RowDataBound" OnRowCommand="GVVAC_RowCommand" EmptyDataText="No Records Found"
Width="100%" BorderColor="#BDBDBD" AllowPaging="false" HeaderStyle-BackColor="#04B431"
HeaderStyle-ForeColor="White" onrowupdating="GVVAC_RowUpdating"
onrowcancelingedit="GVVAC_RowCancelingEdit" onrowediting="GVVAC_RowEditing">
<rowstyle backcolor="White" forecolor="#333333">
<HeaderStyle BackColor="#5CB3FF" Font-Bold="True" ForeColor="White" />
<columns>

<asp:TemplateField HeaderText="Age">
<itemtemplate>
<asp:Label ID="lbl_age" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"age") %>'>

<edititemtemplate>
<asp:TextBox runat="server" ID="txtage" Width="70px" MaxLength="8" Text='<%#DataBinder.Eval(Container.DataItem,"age") %>'>

JoCodes 8-Nov-13 1:48am    
R u able to get the previous value in the textbox or no value at all?
Siva Hyderabad 8-Nov-13 1:51am    
previous value only..

I Think On Page Load You Bind Grid..


And Forgot to Check IsPostBack.


Please Check....
 
Share this answer
 
Comments
Siva Hyderabad 7-Nov-13 23:52pm    
thanks your reply,i tried with debuging point..but firstly value is not come to the textbox
I would suggest you to use Bind instead of using Eval binding in your template field .

MSDN reference for this .

http://msdn.microsoft.com/en-us/library/ms178366.aspx[^]

Also , try to check the Ispostback condition as Anudeep suggested.


Hope this helps...
 
Share this answer
 
May be you are filling grid somewhere on page_load.
The problem arises from here, when you click on update button page gets postback and before your update_eventhandler page_load executes it refreshes your grid to previous values. Now when your
update event executes it gets same values which grid is getting from database.
what you can do just put following code in your page load

if(!Page.Ispostback)
{
//call fill grid method from here
}

hope this helps!!!
 
Share this answer
 
v2

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