Click here to Skip to main content
15,887,862 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one gridview that contains image and name and one textbox. its loading gridview properly. Not able to retrive the value of textbox. Below is my code please help me

C#
foreach (GridViewRow items in OrderItemsGrid.Rows)
            {

                 //int.Parse(items.Cells[0].Text);
                 itemid =     Convert.ToInt32(((Label)items.FindControl("lblItemId")).Text);
                TextBox txt = (TextBox)items.FindControl("TxtQuantity");
                //txt.ID = "txt" + "_" + count.ToString();
                
                int quantity = Convert.ToInt32(txt.Text);
                string sql_insert = string.Format("insert into OrderDetails(OrderId,ItemId,Quantity)values('{0}','{1}','{2}')", orderid, itemid, quantity);
                obj.Do_Transaction(sql_insert);
                ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "alert(' Order done Successfully')", true);
            }
Posted
Updated 19-Jun-13 1:32am
v2
Comments
Mahesh Bailwal 19-Jun-13 7:19am    
did you debug to see what is happening?
Lakshmimsridhar 19-Jun-13 7:20am    
i debug that quantity value is coming null,
but i entered some value in textbox its not coming :(

1 solution

if u r able to access the content of the label, then there could be problem in the name of ur textbox like Instead of "TxtQuantity" , it could be "txtQuantity"
 
Share this answer
 
Comments
Lakshmimsridhar 19-Jun-13 7:22am    
please go through once code. that was not problem
Rish_lp 19-Jun-13 7:59am    
on which event of gridview
u r trying to retrive the value of the textbox ?
Lakshmimsridhar 19-Jun-13 8:02am    
i clearly mentioned my code above. Please have a look on it
Rish_lp 19-Jun-13 8:15am    
Without debugging ur code, it's very difficult to give proper answer.
just cross check that gridview rows are not null.
bt TRY THIS
"Textbox myTextBox = row.FindControl("textboxid") as TextBox;"
Lakshmimsridhar 19-Jun-13 8:49am    
gridview rows are not null. i am not getting texbox value

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900