C# 如何在c语言中将图像列表分配给图像属性#
我有一个图像列表,希望将它们指定给要在数据表中显示的图像属性。我该怎么做?C# 如何在c语言中将图像列表分配给图像属性#,c#,asp.net,json,image,datatable,C#,Asp.net,Json,Image,Datatable,我有一个图像列表,希望将它们指定给要在数据表中显示的图像属性。我该怎么做? 我的想法是从数据库中检索值,并根据该值显示图像。例如如果值=2,则显示2幅图像;如果它=3,则显示3个图像 我得到这个:不能隐式转换类型 此语句的System.Collections.Generic.List到System.Windows.Controls.Image:Project.team_members=名片 这是我的代码: 项目类 asmx 我已经有一段时间没有使用asp了,但对于问题的第一部分,您可以遵循如下所
我的想法是从数据库中检索值,并根据该值显示图像。例如如果值=2,则显示2幅图像;如果它=3,则显示3个图像 我得到这个:不能隐式转换类型 此语句的System.Collections.Generic.List到System.Windows.Controls.Image:Project.team_members=名片 这是我的代码: 项目类 asmx
我已经有一段时间没有使用asp了,但对于问题的第一部分,您可以遵循如下所示的类似实现: 在HTML标记/ASPX页面中: 假设你有三个图像,即
<img src="~/Img1.jpg" runat="server" />
<img src="~/Img2.jpg" runat="server" />
<img src="~/Img3.jpg" runat="server" />
在C#代码隐藏中:
string filePath1 = "Img1.jpg"; //You'll do the same for the other two images
Image img1 = new Image(string filePath1);
Image img2 = new Image(string filePath2);
Image img3 = new Image(string filePath3);
List<Image> listOfImageCollection = new List<Image>();
listOfImageCollection.Add(img1);
listOfImageCollection.Add(img2);
listOfImageCollection.Add(img3);
DataTable dt = new DataTable();
foreach(Image imgs in listOfImageCollection)
{
dt.DataSource = imgs;
dt.DataBind();
}
string myConnectionString = "";
SqlConnection mySQLConnection;
SqlCommand mySQLCommand;
SqlDataReader mySQLDataReader;
myConnectionString = ConfigurationManager.ConnectionStrings["ConnectionStringToTheDB"].ConnectionString;
using (mySQLConnection = new SqlConnection(myConnectionString))
{
mySQLCommand = new SqlCommand("storedProcedureNameToGetValue", mySQLConnection);
mySQLCommand.CommandType = CommandType.StoredProcedure;
mySqlParameter = new SqlParameter();
mySqlParameter.ParameterName = "@Value";
mySqlParameter.Value = Value;
mySQLCommand.Parameters.Add(mySqlParameter);
mySQLConnection.Open();
mySQLDataReader = mySQLCommand.ExecuteReader();
//Create a class to hold your DB properties
ClassName classInstance = new ClassName();
while (mySQLDataReader.Read())
{
classInstance.Value = Convert.ToInt32(mySQLDataReader["DBColumnNameHoldingValue"]);
}
if(classInstance.Value == 1 && dt.Count == 1)
{
//Display one Image then follow the same procedure for the other conditions
}
}
stringfilepath1=“Img1.jpg”//您将对其他两个图像执行相同的操作
图像img1=新图像(字符串filePath1);
Image img2=新映像(字符串filePath2);
Image img3=新图像(字符串filePath3);
List listOfImageCollection=新列表();
添加(img1);
添加(img2);
添加(img3);
DataTable dt=新的DataTable();
foreach(listOfImageCollection中的图像imgs)
{
dt.DataSource=imgs;
dt.DataBind();
}
字符串myConnectionString=“”;
SqlConnection-mySQLConnection;
SqlCommand-mySQLCommand;
SqlDataReader-mySQLDataReader;
myConnectionString=ConfigurationManager.ConnectionString[“ConnectionStringToTheDB”]。ConnectionString;
使用(mySQLConnection=newsqlconnection(myConnectionString))
{
mySQLCommand=newsqlcommand(“storedProcedureNameToGetValue”,mySQLConnection);
mySQLCommand.CommandType=CommandType.StoredProcess;
mySqlParameter=新的SqlParameter();
mySqlParameter.ParameterName=“@Value”;
mySqlParameter.Value=Value;
mySQLCommand.Parameters.Add(mySqlParameter);
mySQLConnection.Open();
mySQLDataReader=mySQLCommand.ExecuteReader();
//创建一个类来保存数据库属性
ClassName classInstance=新的ClassName();
while(mySQLDataReader.Read())
{
classInstance.Value=Convert.ToInt32(mySQLDataReader[“DBColumnNameHoldingValue]”);
}
if(classInstance.Value==1和&dt.Count==1)
{
//显示一个图像,然后对其他条件执行相同的步骤
}
}
var datatableVariable = $('#projects-progress').DataTable({
data: data,
columns: [
{ 'data': 'developer_name' },
{ 'data': 'team_member' },
]
<img src="~/Img1.jpg" runat="server" />
<img src="~/Img2.jpg" runat="server" />
<img src="~/Img3.jpg" runat="server" />
string filePath1 = "Img1.jpg"; //You'll do the same for the other two images
Image img1 = new Image(string filePath1);
Image img2 = new Image(string filePath2);
Image img3 = new Image(string filePath3);
List<Image> listOfImageCollection = new List<Image>();
listOfImageCollection.Add(img1);
listOfImageCollection.Add(img2);
listOfImageCollection.Add(img3);
DataTable dt = new DataTable();
foreach(Image imgs in listOfImageCollection)
{
dt.DataSource = imgs;
dt.DataBind();
}
string myConnectionString = "";
SqlConnection mySQLConnection;
SqlCommand mySQLCommand;
SqlDataReader mySQLDataReader;
myConnectionString = ConfigurationManager.ConnectionStrings["ConnectionStringToTheDB"].ConnectionString;
using (mySQLConnection = new SqlConnection(myConnectionString))
{
mySQLCommand = new SqlCommand("storedProcedureNameToGetValue", mySQLConnection);
mySQLCommand.CommandType = CommandType.StoredProcedure;
mySqlParameter = new SqlParameter();
mySqlParameter.ParameterName = "@Value";
mySqlParameter.Value = Value;
mySQLCommand.Parameters.Add(mySqlParameter);
mySQLConnection.Open();
mySQLDataReader = mySQLCommand.ExecuteReader();
//Create a class to hold your DB properties
ClassName classInstance = new ClassName();
while (mySQLDataReader.Read())
{
classInstance.Value = Convert.ToInt32(mySQLDataReader["DBColumnNameHoldingValue"]);
}
if(classInstance.Value == 1 && dt.Count == 1)
{
//Display one Image then follow the same procedure for the other conditions
}
}