DataGrid控件数据连接不上的问题
<%@ImportNamespace="System.IO"%><%@ImportNamespace="System.Data"%><scriptlanguage="C#...
<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="System.Data"%>
<script language="C#" runat="server">
protected void PageLoad()
{
if(!Page.IsPostBack)
{
BindData();
}
}
protected void MyDG_Delete(Object sender,DataGridCommandEventArgs E)
{
String myfile;
myfile=Server.MapPath(@"upload\"+MyDG.DataKeys[E.Item.ItemIndex]);
File.Delete(myfile);
MyDG.EditItemIndex=-1;
BindData();
}
protected void BindData()
{
DirectoryInfo mydir=new DirectoryInfo(Server.MapPath("upload"));
MyDG.DataSource=mydir.GetFiles("*.*");
MyDG.DataBind();
}
</script>
<html>
<body>
<h4 align="center">我的文件管理器</h4>
<a href="upload.aspx">上传文件</a>
<form runat="server">
<ASP:DataGrid id="MyDG" HeaderStyle-BackColor="#BCBCBC"
Width="100%" AutoGenerateColumns="false" OnDeleteCommand="MyDG_Delete"
DataKeyField="Name" runat="server">
<Columns>
<asp:HyperLinkColumn HeaderText="名称" DataTextField="Name"
DataNavigateUrlField="Name" DataNavigateUrlFormatString="upload/{0}"
Target="_blank"/>
<asp:BoundColumn HeaderText="大小" DataField="Length"/>
<asp:BoundColumn HeaderText="类型" DataField="Extension" />
<asp:BoundColumn HeaderText="修改时间"
DataField="LastWriteTime" />
<asp:ButtonColumn Text="删除" CommandName="Delete"/>
</Columns>
</asp:DataGrid>
</form>
</body>
</html>
============================================
程序没有错误,但DataGrid控件没有显示,数据源没连好,应该怎么设?谢啦! 展开
<%@ Import Namespace="System.Data"%>
<script language="C#" runat="server">
protected void PageLoad()
{
if(!Page.IsPostBack)
{
BindData();
}
}
protected void MyDG_Delete(Object sender,DataGridCommandEventArgs E)
{
String myfile;
myfile=Server.MapPath(@"upload\"+MyDG.DataKeys[E.Item.ItemIndex]);
File.Delete(myfile);
MyDG.EditItemIndex=-1;
BindData();
}
protected void BindData()
{
DirectoryInfo mydir=new DirectoryInfo(Server.MapPath("upload"));
MyDG.DataSource=mydir.GetFiles("*.*");
MyDG.DataBind();
}
</script>
<html>
<body>
<h4 align="center">我的文件管理器</h4>
<a href="upload.aspx">上传文件</a>
<form runat="server">
<ASP:DataGrid id="MyDG" HeaderStyle-BackColor="#BCBCBC"
Width="100%" AutoGenerateColumns="false" OnDeleteCommand="MyDG_Delete"
DataKeyField="Name" runat="server">
<Columns>
<asp:HyperLinkColumn HeaderText="名称" DataTextField="Name"
DataNavigateUrlField="Name" DataNavigateUrlFormatString="upload/{0}"
Target="_blank"/>
<asp:BoundColumn HeaderText="大小" DataField="Length"/>
<asp:BoundColumn HeaderText="类型" DataField="Extension" />
<asp:BoundColumn HeaderText="修改时间"
DataField="LastWriteTime" />
<asp:ButtonColumn Text="删除" CommandName="Delete"/>
</Columns>
</asp:DataGrid>
</form>
</body>
</html>
============================================
程序没有错误,但DataGrid控件没有显示,数据源没连好,应该怎么设?谢啦! 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询