请高手看看应该选择什么控件!立刻给分

wwangzhihang100 2004-08-17 06:04:58
我现在需要在一个页面中大量的录入信息,但是录入信息的单位数量是不定的,就是需要动态生成。
不知道用什么控件合适。
我原来用了table+textbox,都是动态生成,但是当我第二次访问该页面时总是出现index error,控件的index出错。
怎么办呢?
...全文
214 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
peering08cn 2004-08-18
  • 打赏
  • 举报
回复
DATAGRID+TEXTBOX
或者
Datalist + textbox
MSNETFANS 2004-08-18
  • 打赏
  • 举报
回复
DataGrid+TextBox可以的
wwangzhihang100 2004-08-18
  • 打赏
  • 举报
回复
出现的错误
Multiple controls with the same ID 'SpecProjectName_1' were found. FindControl requires that controls have unique IDs.
怎么使用datagrid+textbox?
BillTuan 2004-08-18
  • 打赏
  • 举报
回复
//初始化编辑界面
private void InitUI()
{
int h=0;
string sql;
System.Data.DataSet ds;

if(ObjectID==0) return;

SystemFramework.Dictionary.Dictionary Dictionary=new SystemFramework.Dictionary.Dictionary(Session["LanguageTag"].ToString());

ObjCom=new DbCommon.clsSystemObjects(ObjectID,Session["LanguageTag"].ToString(),(Session["UserInfo"] as BLL.SystemManagement.clsUser).SecurityLevel);
for(int i=0;i<ObjCom.Columns.Length;i++)
{
System.Web.UI.HtmlControls.HtmlGenericControl lbl=new HtmlGenericControl("DIV");
lbl.InnerText=CtlIDtoFldName(ObjCom.Columns[i].Name) + ":";
lbl.Attributes.Add("style","DISPLAY:inline;Z-INDEX:101;Width:130px;Height:20px;POSITION:absolute;LEFT=5px;TOP=" +(i*30+50+h*100) + "px");
lbl.Attributes.Add("align","right");
lbl.Attributes.Add("ms_positioning","FlowLayout");
this.FindControl("Form1").Controls.Add(lbl);

switch(ObjCom.Columns[i].dataType)
{
case SystemFramework.Enumerations.CustomDataType.Numeric:
if(ObjCom.Columns[i].foreignKey!="")
{
System.Web.UI.WebControls.DropDownList ddl=new DropDownList();
System.Web.UI.WebControls.ListItem itEmpty=new ListItem("","0");
ddl.Items.Add(itEmpty);
if(ObjCom.Columns[i].samplingString=="")
sql="select " + ObjCom.Columns[i].foreignKey + "," + ObjCom.Columns[i].foreignField + " from " +
ObjCom.Columns[i].foreignTable + " order by " + ObjCom.Columns[i].foreignField;
else
sql=ObjCom.Columns[i].samplingString;

ds=ObjCom.GetCachedDataset(sql);
if(ds!=null)
{
for(int j=0;j<ds.Tables[0].Rows.Count;j++)
{
System.Web.UI.WebControls.ListItem it=new ListItem(ds.Tables[0].Rows[j][1].ToString(),ds.Tables[0].Rows[j][0].ToString());
ddl.Items.Add(it);
}
}
ddl.ID=ObjCom.Columns[i].Name.ToString();
if(!ObjCom.Columns[i].editable) ddl.Enabled=false;
this.FindControl("Form1").Controls.Add(ddl);
ddl.Attributes.Add("style","Z-INDEX:101;Width:230px;POSITION:absolute;LEFT=140px;TOP=" +(i*30+50+h*100) + "px");

break;
}
else
goto case SystemFramework.Enumerations.CustomDataType.String;
case SystemFramework.Enumerations.CustomDataType.LongDate:
goto case SystemFramework.Enumerations.CustomDataType.String;
case SystemFramework.Enumerations.CustomDataType.ShortDate:
goto case SystemFramework.Enumerations.CustomDataType.String;
case SystemFramework.Enumerations.CustomDataType.Time:
goto case SystemFramework.Enumerations.CustomDataType.String;
case SystemFramework.Enumerations.CustomDataType.PeriodTime:
goto case SystemFramework.Enumerations.CustomDataType.String;
case SystemFramework.Enumerations.CustomDataType.String:
System.Web.UI.WebControls.TextBox txt=new TextBox();
txt.ID=ObjCom.Columns[i].Name.ToString();
if((ObjCom.Columns[i].isKey && ObjCom.Columns[i].foreignKey=="") ||(!ObjCom.Columns[i].editable))
{
txt.Enabled=false;
}
else
{
txt.Enabled=true;
}
this.FindControl("Form1").Controls.Add(txt);
txt.Attributes.Add("style","Z-INDEX:101;Width:230px;POSITION:absolute;LEFT=140px;TOP=" +(i*30+50+h*100) + "px");

if(ObjCom.Columns[i].length>50)
{
txt.TextMode=System.Web.UI.WebControls.TextBoxMode.MultiLine;
txt.Height=100;
h++;
}
break;
case SystemFramework.Enumerations.CustomDataType.Boolean:
System.Web.UI.WebControls.RadioButtonList rbl=new RadioButtonList();
rbl.ID=ObjCom.Columns[i].Name.ToString();
rbl.RepeatDirection=System.Web.UI.WebControls.RepeatDirection.Horizontal;
rbl.Items.Add(Dictionary["true_label"]);
rbl.Items.Add(Dictionary["false_label"]);
if(!ObjCom.Columns[i].editable) rbl.Enabled=false;
this.FindControl("Form1").Controls.Add(rbl);
rbl.Attributes.Add("style","Z-INDEX:101;Width:100px;Height:20px;POSITION:absolute;LEFT=140px;TOP=" +(i*30+50+h*100) + "px");
break;
case SystemFramework.Enumerations.CustomDataType.Image:
goto case SystemFramework.Enumerations.CustomDataType.String;
}
}
}

上面是我刚写的一个程序,与你的要求差不多!
不仅支持textbox,还支持dropdownlist,radiobuttonlist,当然还可以扩充。

程序支持多语言,自定字段等相关功能的代码未贴出,你参考其中添加控件部分的代码就可以啦。
vzxq 2004-08-18
  • 打赏
  • 举报
回复
DataGrid 可以
goody9807 2004-08-18
  • 打赏
  • 举报
回复
可以用PlaceHolder控件

动态添加表格行

Function AddRow(ByVal i, ByVal tr1)

Dim td1 As New TableCell()
Dim td2 As New TableCell()
Table2.CellPadding = 0
Table2.CellSpacing = 0

tr1.BackColor = Color.LightGray

td1.HorizontalAlign = HorizontalAlign.Center
td2.HorizontalAlign = HorizontalAlign.Center
td1.VerticalAlign = VerticalAlign.Middle
td1.BorderColor = Color.Black
td2.BorderColor = Color.Black



td1.BorderWidth = Unit.Pixel(1)
td2.BorderWidth = Unit.Pixel(1)

Dim txtXx As New TextBox()
txtXx.Width = Unit.Pixel(50)
txtXx.ID = "xx" + i.ToString()


td1.Text = "option" + i.ToString()
td2.Controls.Add(txtXx)

tr1.Cells.Add(td1)
tr1.Cells.Add(td2)

Table2.Rows.Add(tr1)

End Function
Function addrow2(ByVal i)
Dim txtXx As New TextBox()
txtXx.Width = Unit.Pixel(10)
txtXx.ID = "xx" + i.ToString()
Page.Controls.Add(txtXx)
End Function
Function add3(ByVal tr As TableRow)
Dim txtXx As New TextBox()
txtXx.Width = Unit.Pixel(100)
txtXx.ID = "xx" + i.ToString()
txtXx.Text = "option" + i.ToString()

Dim td As New TableCell()
td.Controls.Add(txtXx)
tr.Cells.Add(td)
Table2.Rows.Add(tr)
End Function

Table tb=new Table();
try
{
tb.Attributes.Remove("style");
tb.Atrributes.Add("style","border-style:None;width:940px;word-break:break-all; word-wrap: break-word;");
}
catch(Exception ex)
{
throw(ex);
}
yichuan1982 2004-08-18
  • 打赏
  • 举报
回复
table+textbox应该可以的呀,具体错误信息是什么? : kanshangren(槛上人) (


我也觉得可以,要不你生成动态的之后再跳转回来看看?
codeangel 2004-08-18
  • 打赏
  • 举报
回复
可以定义一个静态变量,
在Page_Lode里写入建立控件的数量
不要写在
if(!PostBack)
{

}
CreatedControls(控件数量)

public void CreatedControls(int count)
{
TextBox txt;
Button btn;
Label lbl;

TextBox txt1;
Button btn1;
Label lbl1;

for(int i=0;i<count;i++)
{
lbl=new Label();
txt=new TextBox();
btn=new Button();


lbl.ID ="lbl_"+(i+1).ToString();
lbl.Text="新增附件";
txt.ID = "txt_"+(i+1).ToString();
txt.Text=txt.ID;

btn.ID = "btn_"+(i+1).ToString();
btn.Text="浏览文件";

this.Panel1.Controls.Add(lbl);
this.Panel1.Controls.Add(txt);
this.Panel1.Controls.Add(btn);
btn.Click += new System.EventHandler(btn_Click);

lbl1=new Label();
txt1=new TextBox();
btn1=new Button();

lbl1.ID ="lbl1_"+(i+1).ToString();
lbl1.Text="附件标题";
txt1.ID = "txt1_"+(i+1).ToString();
btn1.ID = "btn1_"+(i+1).ToString();
btn1.Text="删除本条";

this.Panel1.Controls.Add(lbl1);
this.Panel1.Controls.Add(txt1);
this.Panel1.Controls.Add(btn1);
btn1.Click += new System.EventHandler(btn1_Click);


}
codeangel 2004-08-18
  • 打赏
  • 举报
回复
do it inside

if(!PostBack)
{

}
zhpsam109 2004-08-17
  • 打赏
  • 举报
回复
DataGrid+TextBox应该可以把!
「已注销」 2004-08-17
  • 打赏
  • 举报
回复
动态生成的控件可以用PlaceHolder控件,但是~~~~~~~
呵呵,还是比较麻烦,就象你碰见的情况,不容易保存状态
cuike519 2004-08-17
  • 打赏
  • 举报
回复
用DataGrid不行吗?你要求的是什么样的输入???
MyBadBoy 2004-08-17
  • 打赏
  • 举报
回复
kanshangren 2004-08-17
  • 打赏
  • 举报
回复
table+textbox应该可以的呀,具体错误信息是什么?
pingnt 2004-08-17
  • 打赏
  • 举报
回复
我以前也做过类似的东东,是用DATAGRID+TEXTBOX.

62,266

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧