Jeyhun
Jeyhun

Reputation: 469

How should I use result of SQL query in ASP.net?

Below code is from Course.aspx

 <asp:Image runat="server" ImageUrl="ShowImage.ashx?id={?}" alt="" Width="600px" Height="450px" />

Below code is from CourseDetail.cs

var courseid = Request.QueryString["courseid"].ToString();
string sql = "SELECT * FROM Course where CourseID=@CourseID";
string[] name = { "@CourseID" };
string[] value = { courseid };
DataTable dt = DataBase.SQLselect(sql, name, value);

ShowImage.ashx?id={courseid} this code works great. I check with any current number suc as ShowImage.ashx?id=5.

Now I want to know how I shloud call CourseID in Course.aspx :

ImageUrl="ShowImage.ashx?id={CourseID} ??

Upvotes: 0

Views: 207

Answers (1)

serhads
serhads

Reputation: 462

In aspx side put ID to your element.

 <asp:Image runat="server" ID="imgCourse" alt="" Width="600px" Height="450px" />

Than in .cs side call your object.

imgCourse.ImageUrl="ShowImage.ashx?id=" + dt.courseID.ToString();

Upvotes: 2

Related Questions