我在Gridview中有动态文本框,但是当我单击“保存”按钮时,我没有从文本框中获取值 [英] I Have Dynamic Textboxes Inside Gridview But Iam Not Getting Values From Textboxes When I Click On Save Button

查看:62
本文介绍了我在Gridview中有动态文本框,但是当我单击“保存”按钮时,我没有从文本框中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void btnOrder_Click(object sender, EventArgs e)
        {          
            try                 
            {              
            

                    foreach (GridViewRow IgvRow in MomuGridView.Rows)
                     {                        
                            DataRow drI = dtGridView.NewRow();
                            string h = IgvRow.Cells[0].Text;
                            string k = IgvRow.Cells[1].Text;
                            string y = IgvRow.Cells[2].Text;
                            string hTT = IgvRow.Cells[3].Text;
                            string RR = IgvRow.Cells[4].Text;
                            string yTT = IgvRow.Cells[5].Text;
                            string hEE = IgvRow.Cells[6].Text;
                         //   TextBox txt = (TextBox)MomuGridView.Rows[intCnt].FindControl("myTextBox6");
                            string kWW = IgvRow.Cells[7].Text;
                            string yWW = IgvRow.Cells[8].Text;
                        
                    }

推荐答案

这种问题通常发生在动态创建的控件上,但实际上并不是问题,相反,它是根据asp.net页面生命周期的预期结果。动态创建的控件的控件状态不会保存在视图状态中。所以在下一篇文章中它会丢失所有动态创建的控件的状态。



解决问题的最简单方法是在页面上重新创建具有相同Id的控件返回。



此外,您需要编写类似于您评论的行以查找文本框。



如果需要更多信息,请告知我们。



希望,它有帮助:)
This kind of issues generally happens with dynamically created controls but it's not an issue actually, rather it's the expected result according to asp.net page life cycle. The control state of dynamically created controls are not saved in view state. So on next post back it loses the state of all dynamically created controls.

The simplest solution to resolve the problem is to re create the controls with same Id on page post back.

Also, you need to write code something like the line you have commented to find the text boxes.

If anything more is required please let me know.

Hope, it helps :)


这篇关于我在Gridview中有动态文本框,但是当我单击“保存”按钮时,我没有从文本框中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆