我需要 Ajax 更新面板中的 gridView 来绑定其新数据
我说的是 ASP.NET Ajax Control Toolkit、GridView 和 AsyncFileUpload。
我有一个 UpdatePanel 包含:GridView、AsyncFileUpload。
gridView 查看 asyncFileUpload 上传的文件名。
当我完成上传文件时,网格视图不会绑定其新数据,直到我进行刷新。
我在 OnUploadCompleted 事件中尝试过: gridView.DataBind() ,但失败了。
我很好奇!我想要一行在 ajax 内部进行回发以查看新数据!
重点是什么?
编辑:(代码)
protected void btnUploadReport(object sender, EventArgs e)
{
if (fuReports.HasFile)
{
try
{
string newFileName = fuReports.FileName.Insert(fuReports.FileName.Length - 5, DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString());
newFileName = Server.MapPath("~/Files/Reports/TextReports/") + newFileName;
fuReports.SaveAs(newFileName);
System.Collections.Specialized.ListDictionary item = new System.Collections.Specialized.ListDictionary();
item.Add("project_id", Request.QueryString["pid"]);
item.Add("title", fuReports.FileName);
item.Add("type", "text");
item.Add("url", newFileName);
ldsReports.Insert(item); // lds means LinqDataSource
grdReports.DataBind();
}
catch (Exception ex)
{
Session["Message"] = ex.Message;
Response.Redirect("~/Message.aspx");
}
}
}
I'm talking about ASP.NET Ajax Control Toolkit, GridView and AsyncFileUpload.
I have an UpdatePanel contains: GridView, AsyncFileUpload.
The gridView views fileNames uploaded by the asyncFileUpload.
When I finish uploading a file, the grid view does NOT bind its new data until I do a refresh.
I've tried: gridView.DataBind() in the OnUploadCompleted Event, but it failed.
I'm wondering! I want a line to do a post back inside the ajax to view the new data!
What is the point?
Edit: (Code)
protected void btnUploadReport(object sender, EventArgs e)
{
if (fuReports.HasFile)
{
try
{
string newFileName = fuReports.FileName.Insert(fuReports.FileName.Length - 5, DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString());
newFileName = Server.MapPath("~/Files/Reports/TextReports/") + newFileName;
fuReports.SaveAs(newFileName);
System.Collections.Specialized.ListDictionary item = new System.Collections.Specialized.ListDictionary();
item.Add("project_id", Request.QueryString["pid"]);
item.Add("title", fuReports.FileName);
item.Add("type", "text");
item.Add("url", newFileName);
ldsReports.Insert(item); // lds means LinqDataSource
grdReports.DataBind();
}
catch (Exception ex)
{
Session["Message"] = ex.Message;
Response.Redirect("~/Message.aspx");
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
数据绑定还不够。您首先需要使用上传的新文件名更新 DataList,然后调用 DataBind。
如果您在此处显示代码,我可以为您提供更多详细信息,但这里的情况是这样,数据不会在您的 GridView 上更新,这就是为什么您看不到它们
The DataBind is not enough. You need first to update the DataList with the new file names that you upload, then call the DataBind.
If you show the code here I can give you some more details, but this is the case here, the data is not updated on your GridView and that why you not see them