asp.net中的动态行生成 [英] dynamic row generation in asp.net

查看:63
本文介绍了asp.net中的动态行生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SQL SERVER 2008中使用ASP.NET(C#)
在申请人签约期间,他/她必须填写她的学历,总共5个学历,

1.ssc

2.hssc

3. BS

4. MS

5. Phd

现在让我们说申请人仅通过了BS,那么这意味着他/她将没有填写4和5选项,现在我希望注册页面中应该有一个选项可以动态添加行,仅表示3个教育水平添加并填充3行文本框,怎么办?

或如果您有其他选择,请分享

这是我希望从asp.net(c#)网站添加数据的数据库表结构.

学术记录

educationLvl

examName

机构

通过年份

获得的标记

部门

百分比

majorSub

USING ASP.NET(C#) WITH SQL SERVER 2008
during signup by applicant he/she must fill her educational details , total 5 educational levels,

1.ssc

2.hssc

3. BS

4. MS

5. Phd

now lets say that an applicant has only BS passed then it mean that he/she would not have fill 4 and 5 option, now i want that there should be an option in signup page to add rows dynamically , say for 3 levels of education only to add and fill 3 rows of text boxes, so how ?

or if u ppl have any other alternative then share please

Here is my Database table structure to which i want ot add data from asp.net(c#) website.

ACADEMIC RECORD

educationLvl

examName

institution

passingYear

marksObtained

division

percentage

majorSub

推荐答案

1.创建一个用户控件,并放置一行文本框/下拉列表(例如教育",专业",百分比"等)和一个按钮(添加").
2.在页面中添加一个占位符,然后将此用户控件动态添加到页面中.
类似于placeHolder.Controls.Add("/.... usercontrol.ascx");
3.单击该按钮后,将另一个控件附加到占位符.

由于这些是动态控件,因此需要在每个回发中创建它们.

让我知道您是否可以使用这种方法..如果可以,我可以提供更多输入.
1. Create a user control and place one row of textbox/dropdowns (say Education, Major, percentage etc) + a button ("Add").
2. Add a placeholder in your page add this usercontrol dynamically to the page.
something like placeHolder.Controls.Add("/....usercontrol.ascx");
3. On click of the button, append one more control to the placeholder.

Since these are Dynamic controls, need to create them on each postback.

Let me know if you are fine with this approach.. if so I can provide more inputs.


1.使用所需的控件创建一个用户控件.
2.在用户控件中公开属性,以获取每个控制值.
例如:public string Education
{
得到{您的控制值}
}
3.在页面上为用户控件指定一个asp.net占位符.
4.添加服务器端隐藏控件以捕获usercontrolcount或使用viewstate并分配usercontrol计数.
例如,您必须默认显示一行,因此最初将控件计数设置为1.
viewstate ["controlcount"] = 1;
5.每次在page_load上检查触发回发的控件(如果有).这是检查添加"按钮单击事件.
如果postbACK控件名称为"btnAdd",则将viewstate ["controlcount"]值加1;
6.在页面加载时,您需要基于viewstate ["controlcount"]值创建用户控件

for(int i = 0; i< viewstate ["controlcount"]; ....)
{
usercontrol ctl =负载控制(./....../myusercontrol.ascx)
ctl.id ="ucID" + i//这是创建唯一的ID;
placeholder.Controls.add(ctl);
}

完成了.
由于控件是动态加载的,因此在每个page_load调用中都调用此函数,因此每次您都需要创建控件时.
1. Create a user control with the controls you want.
2. Expose properties within the usercontrol to get each of the cotnrol values.
eg: public string Education
{
get { your control value }
}
3. Specify a asp.net place holder on your page for the usercontrol.
4. add a server side hidden control to capture the usercontrolcount or use viewstate and assign the usercontrol count.
for example you have to show by default one row so set initially the control count as 1.
viewstate["controlcount"] = 1;
5. on page_load everytime check for the control that fired the postback (if any ). this is to check the Add button click event.
if postbACK control name is "btnAdd" the increment the viewstate["controlcount"] value by 1;
6. on page load you need to create the usercontrols based on the viewstate["controlcount"] value
something like
for (int i=0; i< viewstate["controlcount"] ; ....)
{
usercontrol ctl = Loadcontrol (./....../myusercontrol.ascx)
ctl.id = "ucID" + i //this is to create a unique id;
placeholder.Controls.add(ctl);
}

you are done.
Call this every page_load call as the controls are loaded dynamically so everytime you need to create the same.


这篇关于asp.net中的动态行生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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