View datalist images based on conditions

Source: Internet
Author: User

 

Recently, I encountered the problem of storing the image into the server and then reading it to datalist.

Page:

<Div style = "margin-top: 20px">
<Asp: datalist id = "datalist1" runat = "server" repeatdirection = "horizontal" repeatcolumns = "3">
<Itemtemplate>
<Div style = "width: 600px">
'width = "200" Height = "200"/>
<Br/>
<% # Eval ("FILENAME") %>
</Div>
</Itemtemplate>
</ASP: datalist>
</Div>

Background:

Datatable dt = new datatable ();
DT. Columns. Add ("FILENAME ");
DT. Columns. Add ("filepath"); // display
String imageurl = "/userdata/uploadimg/"; // Application Path
String imgpath = server. mappath (imageurl); // The obtained path is the physical path on the server, that is, the absolute path.

If (string. isnullorempty (this. chosedate. Text ))
{
Response. Write ("<SCRIPT> alert ('select date') </SCRIPT> ");
Return;
}
Datetime chosedate = datetime. parse (this. chosedate. Text); // time range

// If (string.isnullorempty(this.txt machine. Text ))
//{
// Response. Write ("<SCRIPT> alert ('Enter the machine Code') </SCRIPT> ");
// Return;
//}
String machinecode = this.txt machine. Text. Trim (); // machine code


String imagedire = chosedate. tostring ("yyyymmdd"); // The get time folder is 20140603.

// Find the folder that meets the conditions
String searchfilename = machinecode + "_" + imagedire; // machine code + 20140202

// Path
String imagepathroot = configurationmanager. receivettings ["imagepathroot"]; // userdata/uploadimg

String machineimagepathroot = configurationmanager. appsettings ["machineimagepath"]; // C: \ myprojects \ su8pad \ SRC \ hotelpadsolution \ hotelpadweb \ userdata \ uploadimg \
// Returns the file list
String fullfilepath = machineimagepathroot + imagedire;

If (! Directory. exists (fullfilepath) // No file comes in
{
Response. Write ("<SCRIPT> alert ('file does not exist') </SCRIPT> ");
Return;

}
String [] pathlist = directory. getfiles (fullfilepath); // static


// Search for images
For (INT I = 0; I <pathlist. length; I ++)
{
Pathlist [I] = pathlist [I]. Replace (@"\","/");
String filename = pathlist [I]. substring (pathlist [I]. lastindexof ('/') + 1); // file name
// Specifies the date when the object is intercepted.
String tempfilenamecode = filename. substring (filename. indexof ('_') + 1 );
String filenamedate = tempfilenamecode. substring (0, tempfilenamecode. lastindexof ('.'));
Filenamedate = filenamedate. substring (0, 8 );
Filenamedate = filenamedate. insert (4 ,"-");
Filenamedate = filenamedate. insert (7 ,"-");
Datetime currentfiledate = datetime. parse (filenamedate );
String tempmachinecode = filename. substring (0, filename. indexof ('_'); // machine code
// Obtain the date difference
Timespan Ts = new timespan ();
TS = chosedate-currentfiledate;
If (TS. totaldays = 0 & (filename. Contains (machinecode) | machinecode = "") // fuzzy
{
Datarow DR = DT. newrow ();
Dr [0] = filename;
Dr [1] = imagepathroot + imagedire + "/" + filename; // pathlist [I];
DT. Rows. insertat (DR, DT. Rows. Count );
}
}
This. datalist1.datasource = DT;
This. datalist1.databind ();
}

View datalist images based on conditions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.