求如何实现动态增加控件和去除控件,在线等 可以用这些控件实现也可以用panel来实现添加按钮事件里定义出对象,然后panel1.controls.add() 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 楼主是想做批量录入建议用DataGrid来做吧,这里要用到模版,代码还有比较多的 我用的vs2008,没有datagrid了 诸位能说得详细点吗,我asp.net不太熟 这是我的代码,你自己修改下就好了,前台:<style>#tab {border:1px solid #a4d140;border-collapse:collapse;width:400px;}#tab th{border:1px solid #aaaaaa;background:#cce98b;border-collapse:collapse;text-align:left;}#tab td{border:1px solid #cce98b;border-collapse:collapse;}.txt{ border:1px solid #888;background:#ECE9D8;}.checkBg{border:1px solid #a4d140;background:#ECE9D8;}.button { border:1px solid #a4d140;margin:5px 0px; width:80px;background:#cce98b;height:22px;line-height:22px;}</style><script language="javascript" type="text/javascript">function $(id) {return document.getElementById(id);}function $F(name){return document.getElementsByTagName(name);}function add(){var otr = document.getElementById("tab").insertRow(-1);var checkTd=document.createElement("td");checkTd.innerHTML = '<input name="delx" type="button" class="button" onclick="del();" value="删除" />';var otd1 = document.createElement("td");otd1.innerHTML = '<input type="file" id="File1" name="File1" size="30" runat="server" />';otr.appendChild(checkTd);otr.appendChild(otd1); }function del(){ var dgTable=document.getElementById("tab").rows; var pp=event.srcElement; for (var i=0; i < dgTable.length; i++) { if(pp==dgTable[i].cells[0].getElementsByTagName("input")[0]) { document.getElementById("tab").deleteRow(i); } }} </script><input name="addv_btn" id="addv_btn" type="button" class="button" onclick="add();" value="添加" /> <table id="tab" name="tab" ><tr><th width="100px"></th><th width="300px">文件</th></tr></table><asp:Button ID="Button1" runat="server" CssClass="button" Text="确认上传" OnClick="Button1_Click" /><br /><asp:Label ID="errorLabel" runat="server"></asp:Label>后台: static public string _SavePath; static public string[] FileNames; protected void Page_Load(object sender, EventArgs e) { } public string[] AllFiles { get { return FileNames; } } public string SavePath { set { _SavePath=value; } } void GetControlsToUpload() { HttpFileCollection files = HttpContext.Current.Request.Files; FileNames=new string[files.Count]; for (int i = 0; i < files.Count; i++) { HttpPostedFile file = files[i]; UpFile(file,i); } } protected void UpFile(HttpPostedFile File,int Index) { if (File.FileName != ""&&File.FileName !=null) { string oldName = File.FileName.Substring(File.FileName.LastIndexOf('\\') + 1, File.FileName.Length - File.FileName.LastIndexOf('\\')-1); string newName = DateTime.Now.ToString("yyyyMMddhhmmss") + "_" +oldName ; try { File.SaveAs(Server.MapPath(_SavePath + newName)); errorLabel.Text += File.FileName+"上传成功<br>"; FileNames[Index]=newName; } catch { errorLabel.Text += File.FileName+"上传失败<br/>"; } } } protected void Button1_Click(object sender, EventArgs e) { GetControlsToUpload(); } http://blog.csdn.net/mngzilin/archive/2009/08/19/4463988.aspx TextBox tb=new TextBox();tb.text="";tb.ID="";Panel.controls.add(tb);大概是这个过程 //添加for (int i = 0; i < 5; i++ ) { FileUpload fi = new FileUpload(); fi.ID = "Fi" + i.ToString(); Panel1.Controls.Add(fi); Panel1.Controls.Add(new LiteralControl("</br>")); }//移除Panel1.Controls.Clear(); 取值的话用FindControl方法 string filename=((FileUpload)Panel1.FindControl("Fi1")).FileName; 点“添加”按钮时弹出一个新的窗体让他输入数据不好吗?隐藏? visible? 用GridView的模板列应该很方便 使用js insertRow实现添加或者这些控件本来就存在的 然后放在div中控制显示与否(display)如果你用动态生成控件的话,就必须放在Page_Init并且不可添加!IsPostBack,否则控件回发丢失 XML组织数据,JS控制控件, 多线程操作,通过add控件的方法 asp.net 三层架构调用存储过程 cookie 的文件名是windows自动命名的吗 最近用.net做了个网站,放服务器上老出问题。。大家都提提意见,.net程序要注意什么? 一个简单的页面传值问题..... FtpSupport.dll 上传文件时有大小限制 自已搞不定,恳请大伙帮助!OCX控件问题。。 引用模板页的页面中如何加入已经定义好的CSS 动态添加控件的访问 求一个流量统计中获取搜索引擎转过来的关键词算法,高手请进!急 朋友们帮帮忙啊关于建设网站中文韩文的问题 图片自动播放 面试的sql题目
我用的vs2008,没有datagrid了
前台:
<style>
#tab {
border:1px solid #a4d140;
border-collapse:collapse;
width:400px;
}
#tab th{
border:1px solid #aaaaaa;
background:#cce98b;
border-collapse:collapse;
text-align:left;
}
#tab td{
border:1px solid #cce98b;
border-collapse:collapse;
}
.txt{
border:1px solid #888;
background:#ECE9D8;
}
.checkBg{
border:1px solid #a4d140;
background:#ECE9D8;
}
.button {
border:1px solid #a4d140;margin:5px 0px;
width:80px;background:#cce98b;height:22px;line-height:22px;
}
</style>
<script language="javascript" type="text/javascript">
function $(id) {return document.getElementById(id);}
function $F(name){return document.getElementsByTagName(name);}function add(){
var otr = document.getElementById("tab").insertRow(-1);
var checkTd=document.createElement("td");
checkTd.innerHTML = '<input name="delx" type="button" class="button" onclick="del();" value="删除" />';
var otd1 = document.createElement("td");
otd1.innerHTML = '<input type="file" id="File1" name="File1" size="30" runat="server" />';otr.appendChild(checkTd);
otr.appendChild(otd1);
}
function del()
{
var dgTable=document.getElementById("tab").rows;
var pp=event.srcElement;
for (var i=0; i < dgTable.length; i++)
{
if(pp==dgTable[i].cells[0].getElementsByTagName("input")[0])
{
document.getElementById("tab").deleteRow(i);
}
}
}
</script>
<input name="addv_btn" id="addv_btn" type="button" class="button" onclick="add();" value="添加" /> <table id="tab" name="tab" >
<tr>
<th width="100px"></th>
<th width="300px">文件</th>
</tr>
</table>
<asp:Button ID="Button1" runat="server" CssClass="button" Text="确认上传" OnClick="Button1_Click" /><br />
<asp:Label ID="errorLabel" runat="server"></asp:Label>
后台: static public string _SavePath;
static public string[] FileNames;
protected void Page_Load(object sender, EventArgs e)
{
}
public string[] AllFiles
{
get {
return FileNames;
}
}
public string SavePath
{
set
{
_SavePath=value;
}
}
void GetControlsToUpload()
{
HttpFileCollection files = HttpContext.Current.Request.Files;
FileNames=new string[files.Count];
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile file = files[i];
UpFile(file,i);
}
}
protected void UpFile(HttpPostedFile File,int Index)
{
if (File.FileName != ""&&File.FileName !=null)
{
string oldName = File.FileName.Substring(File.FileName.LastIndexOf('\\') + 1, File.FileName.Length - File.FileName.LastIndexOf('\\')-1);
string newName = DateTime.Now.ToString("yyyyMMddhhmmss") + "_" +oldName ;
try
{
File.SaveAs(Server.MapPath(_SavePath + newName));
errorLabel.Text += File.FileName+"上传成功<br>";
FileNames[Index]=newName; }
catch
{
errorLabel.Text += File.FileName+"上传失败<br/>";
} }
}
protected void Button1_Click(object sender, EventArgs e)
{
GetControlsToUpload();
}
tb.text="";
tb.ID="";
Panel.controls.add(tb);
大概是这个过程
//添加
for (int i = 0; i < 5; i++ )
{
FileUpload fi = new FileUpload();
fi.ID = "Fi" + i.ToString();
Panel1.Controls.Add(fi);
Panel1.Controls.Add(new LiteralControl("</br>"));
}//移除
Panel1.Controls.Clear();
取值的话用FindControl方法 string filename=((FileUpload)Panel1.FindControl("Fi1")).FileName;
点“添加”按钮时弹出一个新的窗体让他输入数据不好吗?
隐藏? visible?
或者这些控件本来就存在的 然后放在div中控制显示与否(display)
如果你用动态生成控件的话,就必须放在Page_Init并且不可添加!IsPostBack,否则控件回发丢失
JS控制控件,