Click here to Skip to main content
15,907,497 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created gridview which has textboxes attached in specific cells for that i used following code
C#
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.RowIndex >= 5)
            {
                for (int i = 0; i < e.Row.Cells.Count; i++)
                {
                    if (i > 1)
                    {
                        TextBox txt = new TextBox();
                        txt.Text = e.Row.Cells[i].Text;
                        txt.Width = System.Web.UI.WebControls.Unit.Pixel(25);
                        e.Row.Cells[i].Controls.Add(txt);
                    }
                }
            }
        }
    }



Now When I enter values in textbox I want to access values on that respective textboxes
for that i tried
TextBox txt = (TextBox)grwUploadManual.Rows[y].Cells[y - 3].Controls[0];
But it looks that error is getting
threw an exception of type 'System.ArgumentOutOfRangeException' System.Web.UI.Control {System.ArgumentOutOfRangeException
I debug code and check value on that cell 'grwUploadManual.Rows[y].Cells[y - 3].Text' I got values but i cant find control how should i find controls dynamically
thanks in advance....
Posted

just try the code below
string s = datagridview1.CurrentCell.EdittedFormattedValue.ToString();

This will give you current cell value.
 
Share this answer
 
v2
In order to get the value of textbox which is embedded within a gridview, You need to find row index in which the textbox is present and you need to know the command arguement which fires the event and the rowcommand_event.

We derive the row index using the following code:

C#
int rowIndex = ((GridViewRow((LinkButton)e.CommandSource).NamingContainer).
RowIndex;


After getting the row index we need to know the id of the textbox whose text we want to get let us assume that our textbox has an id "txtTitle" and we derive the text it contains as follows:

string title = ((TextBox)GridView1.Rows[rowIndex].FindControl("txtTitle")).Text;
 
Share this answer
 
 
Share this answer
 
v2
chick this

C#
var getText = ((TextBox)YourGrid.Rows[e.RowIndex].FindControl("txtBoxID")).Text;


getText will get the value of the spicific text inside your gridView
 
Share this answer
 
You wont be able to get the dynamically generated controls after post back in GridView.
 
Share this answer
 
Comments
sp_suresh 21-Feb-14 2:56am    
then how to solve this problem
thanks ...
sp_suresh 22-Feb-14 19:48pm    
I think this has no solution.....

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