本文介绍了如何在C#中从数据库下载文件后显示消息框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 protected void GridView1_RowCommand(object sender,GridViewCommandEventArgs e)
{
if(e.CommandName ==Download)
{
byte [ ] byteimg = null;
byte [] byteimg1 = null;
bool replica = false;
GridViewRow gvrow =(GridViewRow)((ImageButton)e.CommandSource).NamingContainer;
string id = gvrow.Cells [0] .Text;
string servername = gvrow.Cells [2] .Text;
string filename = gvrow.Cells [1] .Text;
string f1 = filename.Replace('','_');
string ext = Path.GetExtension(filename);
Random rnd = new Random();
int random = rnd.Next(0,9);

if(servername ==S1)
{
if(random == 0 || random == 6 || random == 9 || random == 3 || random == 1 || random == 7)
{
ScriptManager.RegisterStartupScript(this,this.GetType(),,alert('服务器已崩溃.. ');,真实);
byteimg1 = db.getbytesreplica1(id);
replica = true;
}
else
{
byteimg = db.getbytes1(id);
}

}
else if(servername ==S2)
{
byteimg1 = db.getbytesreplica2(id);
byteimg = db.getbytes2(id);

}
else if(servername ==S3)
{
byteimg1 = db.getbytesreplica3(id);
byteimg = db.getbytes3(id);

}
else
{
byteimg1 = db.getbytesreplica4(id);
byteimg = db.getbytes4(id);
}

if(ext ==。pdf)
{
Response.ContentType =application / pdf;
}

else if(ext ==。doc|| ext ==。rtf|| ext ==。docx)
{
Response.ContentType =Application / msword;
}

else if(ext ==。txt)
{
Response.ContentType =text / Plain;
}

else if(ext ==.rar)
{
Response.ContentType =Application / x-rar-compressed;
}
else if(ext ==。jpeg|| ext ==.jpg)
{
Response.ContentType =image / jpeg;
divmsg.InnerHtml =asd;
}

else if(ext ==。png)
{
Response.ContentType =image / png;
}
else
{
Response.ContentType =Application / octetstream;
}
popup.Show();
Response.AddHeader(Content-disposition,attachment; filename =+ f1);
// Response.AppendHeader(Content-disposition,filename.ToString());
if(replica)
{

Response.BinaryWrite(byteimg1);
}
else
{
Response.BinaryWrite(byteimg);
}
Response.Flush();
Response.End();
}


}





上面的scriptmanager代码是没有注意,也没有弹出消息....请帮助我。

我也使用ModalPopupcontrol扩展器来显示消息,但它仍然没有显示消息......

i已将剧本管理员放入Bold ..上面的代码

提前谢谢.. !! :)

解决方案

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
   {
       if (e.CommandName == "Download")
       {
           byte[] byteimg = null;
           byte[] byteimg1 = null;
           bool replica = false;
           GridViewRow gvrow = (GridViewRow)((ImageButton)e.CommandSource).NamingContainer;
           string id = gvrow.Cells[0].Text;
           string servername = gvrow.Cells[2].Text;
           string filename = gvrow.Cells[1].Text;
           string f1=filename.Replace(' ', '_');
           string ext = Path.GetExtension(filename);
           Random rnd = new Random();
           int random = rnd.Next(0, 9);

           if (servername == "S1")
           {
               if (random == 0 || random == 6 || random == 9 || random == 3 || random == 1 || random == 7)
               {
                   ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('Server has been crashed.. ');", true); 
                   byteimg1 = db.getbytesreplica1(id);
                   replica = true;
                }
               else
               {
                   byteimg = db.getbytes1(id);
               }

           }
           else if (servername == "S2")
           {
               byteimg1 = db.getbytesreplica2(id);
               byteimg = db.getbytes2(id);

           }
           else if (servername == "S3")
           {
               byteimg1 = db.getbytesreplica3(id);
               byteimg = db.getbytes3(id);

           }
           else
           {
               byteimg1 = db.getbytesreplica4(id);
               byteimg = db.getbytes4(id);
           }

           if (ext == ".pdf")
           {
               Response.ContentType = "application/pdf";
           }

           else if (ext == ".doc" || ext == ".rtf" || ext == ".docx")
           {
               Response.ContentType = "Application/msword";
           }

           else if (ext == ".txt")
           {
               Response.ContentType = "text/Plain";
           }

           else if (ext == ".rar")
           {
               Response.ContentType = "Application/x-rar-compressed";
           }
           else if (ext == ".jpeg" || ext == ".jpg")
           {
               Response.ContentType = "image/jpeg";
               divmsg.InnerHtml = "asd";
           }

           else if (ext == ".png")
           {
               Response.ContentType = "image/png";
           }
           else
           {
               Response.ContentType = "Application/octetstream";
           }
           popup.Show();
          Response.AddHeader("Content-disposition", "attachment; filename=" + f1);
          // Response.AppendHeader("Content-disposition", filename.ToString());
           if (replica)
           {

               Response.BinaryWrite(byteimg1);
           }
           else
           {
               Response.BinaryWrite(byteimg);
           }
           Response.Flush();
           Response.End();
       }


   }



Above code of scriptmanager is not worng and not popping up the message....plz help me with that.
I have also used ModalPopupcontrol extender to show the message but it still does not shows the message......
i have put the scriptmanager in Bold..in above code
Thanks in advance..!! :)

解决方案


这篇关于如何在C#中从数据库下载文件后显示消息框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 21:07