首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

asp.net动态生成控件有关问题

2012-03-25 
asp.net动态生成控件问题在页面中有一个上传文件的file控件和一个button,要求选择要上传的文件后点击butto

asp.net动态生成控件问题
在页面中有一个上传文件的file控件和一个button,要求选择要上传的文件后点击button,文件存放到指定文件夹,然后在file和button的下方显示刚上传的文件名称和一个删除按钮, 上传第二个文件后,下面依次增加文件名称和删除按钮
上传部分好解决,请问下面的显示文件名和删除按钮怎么做?
谢谢!!

[解决办法]
你可以用table化个表头 再用gridveiw 来显示 你刚刚添加上的文件。

删除按钮是有的,先把它用Visible = false; 给隐藏,判断gridveiw中用数据的时候就就显示

希望你看了有帮助:
<table id="Showtable" border="0" width="100%" cellpadding="0" cellspacing="0" style="display: inline"
runat="server">
<tr width="100%" height="27" class="lbx">
<th style="width: 30%; height: 27px;">
<a id="inDate" name="inDate" runat="server" style="cursor: hand" onclick="sort(this);">
药品名称</a></th>
<th style="width: 10%; height: 27px;">
<a id="UserName" name="UserName" runat="server" style="cursor: hand" onclick="sort(this);">
药品单位</a></th>
<th style="width: 8%; height: 27px;">
<a id="invoiceNumber" name="invoiceNumber" runat="server" style="cursor: hand" onclick="sort(this);">
数量</a></th>
<th style="width: 10%; height: 27px;">
<a id="Delete" name="Delete" runat="server" style="cursor: hand" onclick="sort(this);">
是否过期</a></th>
<th style="width: 25%; height: 27px;">
<a id="A1" name="Delete" runat="server" style="cursor: hand" onclick="sort(this);">生产厂家</a></th>
<th style="width: 8%; height: 27px;">
<a id="A2" name="Delete" runat="server" style="cursor: hand" onclick="sort(this);">零售价</a></th>
<th style="width: 9%; height: 27px;">
<a id="A3" name="Delete" runat="server" style="cursor: hand" onclick="sort(this);"><span
style="text-decoration: underline"></span></a>
</th>
</tr>
<tr>
<td align="center" colspan="7">
<asp:GridView ID="AddGridView" runat="server" AutoGenerateColumns="False" GridLines="Horizontal"
Width="100%" ShowHeader="False" AllowPaging="True" EmptyDataText="没有入库记录" PageSize="10"
OnRowCommand="AddGridView_RowCommand" OnPageIndexChanging="AddGridView_PageIndexChanging">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table border="0" width="100%" cellpadding="0" cellspacing="0">


<tr style="cursor: hand" onclick="ShowHidden('<%#Eval("repertoryInDetail_ID") %>',event,'imgchang','FamilyIDHidden')">
<td style="width: 30%" align="center">
<%#Eval("drugName")%>
</td>
<td style="width: 10%" align="center">
<%#Eval("UnitName")%>
</td>
<td style="width: 8%" align="center">
<%#Eval("amount")%>
</td>
<td style="width: 10%" align="center">
<%#Eval("isOver")%>
</td>
<td style="width: 25%" align="center">
<%#Eval("Supplier")%>
</td>
<td style="width: 8%" align="center">
<%#Eval("retailPrice")%>
</td>
<td style="width: 9%" align="center">
<asp:ImageButton ID="linkbtnDelete" runat="server" ImageUrl="~/Images/bg_sc.gif"
CausesValidation="False" CommandName="btnDelete" CommandArgument='<%# Eval("repertoryInDetail_ID") %>'
OnClientClick="return delFamilyconfirm()"></asp:ImageButton>
</td>
</tr>
</table>


[解决办法]
每点击一次,就往table里边插一次,
Table tb = new Table();
tb.Rows[i].Cells[i].Controls.Add(yourcontrol);
[解决办法]
是的,每添加一个文件就在后台执行一下动态添加按钮 名称等控件。
通过new()给table动态添加一行,再往行里面动态new出button和textbox来显示名称和删除按钮
[解决办法]
动态增加按钮:

Dim bt As New Button
bt.ID = " delbt"
Page.Controls.Add(bt)
addhandler bt.click,addressof bt_click '通过bt_click处理事件!
上传文件:
 If myfile.PostedFile.ContentLength = 0 Then
Response.Write("<script>javascript:alert('上传文件存在或上传失败!!!');</script>")
Else
'获取文件名
Dim fn() As String = Split(myfile.PostedFile.FileName, "\")
Dim filepath As String = Replace(fn(fn.Length - 1), " ", "")
Dim path As String = Server.MapPath(".") & "\uptable\" & filepath


'保存文件
myfile.PostedFile.SaveAs(path)
'显示上传结果
Response.Write("文件上传成功!<br>上传文件名:" & filepath)
 end if

热点排行