我如何使用listview或网格视图或使用任何控制器一次查看多个图像? [英] how i view serveral images at once for using listview or grid view, or using any controller?

查看:46
本文介绍了我如何使用listview或网格视图或使用任何控制器一次查看多个图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SqlConnection con = new SqlConnection();
            con.ConnectionString = "Data Source=PROMOD-PC;Initial Catalog=travel_Directions;Integrated Security=True";
    
        SqlCommand scmd1 = null;
        SqlDataAdapter sDatAdp = new SqlDataAdapter();
    
    String selQuery = "SELECT Id FROM MapDataImage WHERE Source='" + TextBox1.Text + "';";
            {

            SqlCommand scmd = new SqlCommand(selQuery, con);

            con.Open();

            SqlDataReader sqldread = scmd.ExecuteReader();

            while (sqldread.Read())
            {
                int Dbid = (int)sqldread["Id"];


                Label4.Text = Convert.ToString(Dbid);
                if (Dbid != null)
                {
                    String QueryStr = "SELECT Image FROM User_Images WHERE Id='" + Dbid + "'";
                    scmd1 = new SqlCommand(QueryStr, con);

                }
            }

            sqldread.Dispose(); 
            //scmd1.CommandType = CommandType.Text;
            //scmd1.Connection = con;

        SqlDataReader dr = scmd1.ExecuteReader();
        dr.Read();
        Context.Response.BinaryWrite((byte[])dr["Image"]);
        Context.Response.ContentType = "image/jpg";

        sDatAdp.SelectCommand = scmd1;


        GridView1.DataSource = dr;
        GridView1.DataBind();

        con.Close();
        dr.Close();
        sDatAdp.Dispose();
        con.Dispose();
}





我的方案是我的第一个查询检查用户输入是否正确,如果正确则会检索其id第二个查询获取与特定ID相关的所有图像...



我将如何做到这一点?



我必须使用for循环吗?



我的数据库是否存在不同大小的图像?



我可以一次查看所有图像吗?在同一页面?



当前它显示的是与该特定ID相关的第一张图像,现在它只查看不同页面中的图像?



请有人帮帮我........



my scenario is my first query checks whether the user input is corrrect, if its correct it will retrieve its id and second query gets all the images which related to particular id...

how i'm gonna do that?

do i have to use for loop?

the thing is my database holds differant sizes of images?

so can i view all the images at once? in same page?

currenly it shows 1st image of which related to that particular id and, now it views only image in a differant page?

Please someone help me........

推荐答案

你可以使用DataGrid,DataList,Repeater。

尝试使用Datalist Control ... :)



.aspx page ... :)



You can use DataGrid,DataList ,Repeater for that.
Try this with Datalist Control...:)

.aspx page...:)

<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
<title>Bind Images to Datalist from folder</title>
</head>
<body>
<form id="form1"  runat="server">
<div>
<asp:FileUpload ID="fileupload1" runat="server" />
<asp:Button ID="btnsave" runat="server" Text="Upload" onclick="btnsave_Click" />
</div>
<div>
<asp:DataList ID="dtlist" runat="server" RepeatColumns="4" CellPadding="5">
<ItemTemplate>
<asp:Image Width="100" ID="Image1" ImageUrl='<%# Bind("Name", "~/Images/{0}") %>' runat="server" />
<br />
<asp:HyperLink ID="HyperLink1" Text='<%# Bind("Name") %>' NavigateUrl='<%# Bind("Name", "~/Images/{0}") %>' runat="server"/>
</ItemTemplate>
<ItemStyle BorderColor="Brown" BorderStyle="dotted" BorderWidth="3px" HorizontalAlign="Center"
VerticalAlign="Bottom" />
</asp:DataList>
</div>
</form>
</body>
</html>





.aspx.cs页面... :)





.aspx.cs page...:)

add
After that add using System.IO and using System.Collections namespaces and write the following code in code behind







protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDataList();
}
}
protected void BindDataList()
{
DirectoryInfo dir = new DirectoryInfo(MapPath("Images"));
FileInfo[] files = dir.GetFiles();
ArrayList listItems = new ArrayList();
foreach (FileInfo info in files)
{
listItems.Add(info);
}
dtlist.DataSource = listItems;
dtlist.DataBind();

}
protected void btnsave_Click(object sender, EventArgs e)
{
string filename = Path.GetFileName(fileupload1.PostedFile.FileName);
fileupload1.SaveAs(Server.MapPath("Images/" + filename));
BindDataList();
}


这篇关于我如何使用listview或网格视图或使用任何控制器一次查看多个图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆