我想从代码隐藏中检索并保存动态创建的控件中的数据。通过下拉选择生成动态控件 [英] I want to retrieve and save the data from dynamically created controls from code behind. and dynamic controls are generated through dropdown selection

查看:43
本文介绍了我想从代码隐藏中检索并保存动态创建的控件中的数据。通过下拉选择生成动态控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<asp:HiddenField ID="hdnCount" Value="1" runat="server" />










Dim rowCount As Integer = Integer.Parse(hdnCount.Value)
       

      For rowNumber As Integer = 1 To rowCount 

            Dim name As TextBox = DirectCast(tblMain.Rows(rowNumber).Cells(0).FindControl("txtName" & rowNumber.ToString()), TextBox)
            
            Dim age As DropDownList = DirectCast(tblMain.Rows(rowNumber).Cells(0).FindControl("drdAge" & rowNumber.ToString()), DropDownList)
            Dim sex As DropDownList = DirectCast(tblMain.Rows(rowNumber).Cells(0).FindControl("drdSex" & rowNumber.ToString()), DropDownList)
            Dim mobileno As TextBox = DirectCast(tblMain.Rows(rowNumber).Cells(0).FindControl("txtmobileno" & rowNumber.ToString()), TextBox)
           
            lblDisplay.Text = name
           lblDisplay1.Text = age
lblDisplay2.Text = sex
lblDisplay3.Text = mobileno

        Next

















此代码的错误是 对象引用未设置为对象的实例

此处textbox不检索ID并提供空值(无)。



请帮助解决此问题。它的非常紧急 ......!

提前谢谢...!









the error for this code is "Object Reference is not set to an instance of an object"
here textbox does not retrieve the ID and gives the null value (nothing).

Please help for this query. Its very Urgent...!
Thank you in advance...!

推荐答案

非常感谢....! Mahesh :-)

这个解决方案很有用......!
Thanks a lot....! Mahesh :-)
this solution was helpful...!


我想你忘了使用文本框的文本属性

例子

名称是文本框,然后在分配值给lblDisplay时你必须使用

I think u forgot to use text property of textbox
example
name is textbox then at time of assigning value to lblDisplay u have to use
lblDisplay.Text = name.Text


很久以前我遇到过同样的问题。以下是我最熟悉的方法



首先你需要在PostBack上重新创建动态控件,因为它们不再存在。



然后要获得用户提交的值,您需要使用以下语法



I have faced the same problem long ago. Below is the approach I have used best to my knowledge

First you need to recreate your dynamic control on PostBack as they no longer exist.

Then to get value submitted by user you need to use following syntax

Dim name As TextBox = DirectCast(tblMain.Rows(rowNumber).Cells(0).FindControl("txtName" & rowNumber.ToString()), TextBox)

name.Text = Request(name.UniqueID)





希望得到这个帮助,如果您需要澄清,也请告诉我



Hope this help and also let me know if you need some clarification


这篇关于我想从代码隐藏中检索并保存动态创建的控件中的数据。通过下拉选择生成动态控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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