Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
I am trying to edit my detailed gridview based on master gridview click.I am adding a textbox dynamically and editing it.when i click on the update button it gives me the old value whereas i require the new.This is what i have done so far.Please suggest.
 
  protected void btnedit_Click(object sender, EventArgs e)
    {
      
 
        int index = GridView1.EditIndex;
 
        Button btn = (Button)sender;
 
        
        GridViewRow gvr = (GridViewRow)btn.NamingContainer;
 
        int getindex = gvr.RowIndex;
 
        //string headertext = this.GridView1.Columns[1].HeaderText;
        string id = GridView1.Rows[getindex].Cells[4].Text;
 
        DataTable dtfrweekend = new DataTable();
        connfordata.Open();
        SqlCommand cmdfrgetweekend = new SqlCommand("select s001_Weekending as Weekend from dbo.s001_Timesheets where s001_TimesheetsID ='" +id+ "' ", connfordata);
        SqlDataAdapter dafrweekend = new SqlDataAdapter(cmdfrgetweekend);
        dafrweekend.Fill(dtfrweekend);
        connfordata.Close();
        
            BoundField bf = new BoundField();
            bf.DataField = "Monday";
            txtmonday.Text = GridView1.Rows[getindex].Cells[3].Text;
            GridView1.Rows[getindex].Cells[3].Controls.Add(txtmonday);
       
    }
 

 

    protected void btnupdate_Click(object sender, EventArgs e)
    {
 
        //string get = txtmonday.Text;
        //String sValue = Request.Form["txtmonday"];

 
        Button btn = (Button)sender;
        GridViewRow gvr = (GridViewRow)btn.NamingContainer;
        int getindex = gvr.RowIndex;
 
        TextBox tb = GridView1.FindControl("txtmonday") as TextBox;
 
        
 
    }
 
Is it possible to get the changed value from dynamically created textbox in another function?
Posted 13-Jul-13 13:53pm
Comments
senthil kumar - 2185 at 15-Jul-13 23:04pm
   
convert gridview value to String
Manikandan Sekar at 16-Jul-13 9:27am
   
yes it is possible but you need to give the row index that is the row number correctly during the operation
sumit_kapadia at 19-Jul-13 12:26pm
   
If any answer had helped you please "Accept Answer" which marked question as Solved and can help others
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Dynamic Controls not avaialbe after postback reason is simple. As web is disconnect in nature it create one object of your page then create required HTML using that and send back to browser that renders it. So ViewState comes into picture to take care after post back and mange control on page despite multiple postbacks. Means dynamic controls not added to ViewState? Yes.
 
However any thing on HTML page that has type of input has ability to sent data to server. Means your text box is input type and does post data So how to get that value . Look below
 
if I add some control to page on page load like
if (!IsPostBack)
            {
                TextBox t = new TextBox();
                t.ID = "txt1";
                pnl1.Controls.Add(t);
 
            }
 
then I can get values after postback as
if (Request["txt1"] != null)
            {
                value = Request["txt1"];
 
            }
 
This is just concept not exact solution to your problem .. I guess you get the logic.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hello ,
 

put your textBox in Item template and write hard coded "AutoPostBack="True" ontextchanged="txtBox_TextChanged" " on that textBox on aspx page after that
 
in code behind create event of that text box Like -
 

protected void txtBox_TextChanged(object sender, EventArgs e)
    {  }

 

It will work in gridview for textchange event.
 

<asp:TemplateField HeaderText ="Sch.End Date" >
                    <ItemTemplate >
                        <asp:TextBox ID="txtBox" runat="server" ontextchanged="txtBox_TextChanged"></asp:TextBox>
                    </ItemTemplate>
              </asp:TemplateField>
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 200
1 George Jonsson 175
2 Kornfeld Eliyahu Peter 169
3 PIEBALDconsult 110
4 Richard MacCutchan 85
0 OriginalGriff 6,080
1 DamithSL 4,648
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,624
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 17 Jul 2013
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