GridView顯示服務(wù)器圖片(保存為圖片路徑)_.Net教程

      編輯Tag賺U幣
      教程Tag:暫無(wú)Tag,歡迎添加,賺取U幣!

      推薦:解讀ASP.NET密碼強(qiáng)度驗(yàn)證代碼實(shí)例
      效果如下: 輸入密碼: 密碼強(qiáng)度: 弱 中 強(qiáng) 代碼如下: %@PageLanguage=C#AutoEventWireup=trueCodeFile=Default.aspx.csInherits=_Default% EhtmlPUBLIC-//W3C//DTDXHTML1.0xhtml1-trans

      //前臺(tái)頁(yè)面創(chuàng)建顯示圖片列
       <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">   
         <asp:TemplateField headertext="顯示圖片">   
             <ItemTemplate>   
                <asp:Image ID="img" Height="20" Width="20" ImageURL=’<%# GetImg(Eval("表中列名").ToString())%>’ runat="server" /> (注:后臺(tái)方法名用來(lái)得到服務(wù)器中全路徑)   
             </ItemTemplate>   
             <FooterStyle HorizontalAlign="Center" />   
             <ItemStyle HorizontalAlign="Center" />   
             <HeaderStyle Width="20%" />   
             </asp:TemplateField>   
      或者2:   
          <asp:TemplateField>   
             <HeaderTemplate>   
                顯示圖片   
              </HeaderTemplate>   
             <ItemTemplate>   
                       <a href="<%#GetImagePath()+Convert.ToString(Eval("表中列名"))%>" target="_blank"><img src="<%#GetImagePath()+Convert.ToString(Eval("表中列名"))%>"    
      alt=""  width="20px" height="20px"  /></a>   
             </ItemTemplate>   
             <FooterStyle HorizontalAlign="Center" />   
             <ItemStyle HorizontalAlign="Center" />   
             <HeaderStyle Width="10%" />   
             </asp:TemplateField>   
          </asp:GridView>  
       

      后臺(tái)代碼: 

      //獲取圖片
              protected string GetImg(string img)
              {
                  string imgurl = ImageURL + img;  注:ImageURL為服務(wù)器保存圖片文件夾的路徑
                  return imgurl;
              }

       public static string ImageURL {
                  get {
                      string imageurl = ConfigurationManager.AppSettings["ImageURL"].ToString()+"/";
                      if (imageurl != null) {
                          return imageurl;
                      }
                      return "";
                  }
              }

      或者2(顯示的圖片點(diǎn)擊可鏈接到對(duì)應(yīng)的圖片地址):

      public static  string GetImagePath()
             {
                 return ConfigurationManager.AppSettings["ImageUrl"].ToString();
             }

      分享:解讀asp.net點(diǎn)擊textbox自動(dòng)清除其中文字
      在cs后臺(tái)代碼中直接添加: protectedvoidPage_Load(objectsender,EventArgse) { TextBox1.Attributes.Add(OnClick,this.value=\\);...

      來(lái)源:模板無(wú)憂//所屬分類(lèi):.Net教程/更新時(shí)間:2010-02-03
      相關(guān).Net教程