Click here to Skip to main content
15,887,434 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi guys

I want multiple values from a method in c#.

How can I run this scenario?

What I have tried:

ASP.NET
<div>
    <asp:Image ID="Image" runat="server" ImageUrl="<%#Eval("Url")%>" />
    <h2><%#Eval("Title1")%></h2>
    <p><%#Eval("Text")%></p>
</div>


C#
protected void Page_Load(object sender, EventArgs e)
 {
     Getdata();
 }
 private void Getdata()
 {
     sqlCon.Open();
     SqlCommand sqlCmd = new SqlCommand("Getdata", sqlCon);
     sqlCmd.CommandType = CommandType.StoredProcedure;
     DataSet ds = new DataSet();
     SqlDataAdapter da = new SqlDataAdapter(sqlCmd);
     da.Fill(ds);
     if (ds.Tables[0].Rows.Count > 0)
     {
         Url = ds.Tables[0].Rows[0]["Url"].ToString();
         Title1 = ds.Tables[0].Rows[0]["Title1"].ToString();
         Text = ds.Tables[0].Rows[0]["Text"].ToString();
     }
     sqlCon.Close();
 }


Thanks everyone
Posted
Updated 4-Jul-17 18:12pm
Comments
Karthik_Mahalingam 5-Jul-17 0:05am    
what is the issue?

try %=

<asp:Image ID="Image" runat="server" ImageUrl='<%= Url %>' />
  <h2><%= Title1 %></h2>
  <p><%= Text %></p>
 
Share this answer
 
I'm assuming the code has the following variable declaration since you didn't post it.
C#
public string Url { get; set; }
public string Title1 { get; set; }
public string Text { get; set; }


The code-behind look OK.

Here I think what it should look like based on your current situation. In the .aspx page. Replace the #eval (data binding syntax) with Response.Write (<%=...) since it has nothing to do with server controls databound. Replace the server side image control with the client side to prevent the tag error. Let me know if it help.

HTML
<div>
    <img ID="Image" src="<%= Url %>" />
    <h2><%= Title1 %></h2>
    <p><%= Text %></p>
</div>
 
Share this answer
 
Comments
Member 10871138 5-Jul-17 4:06am    
Thanks Bryian Tan
Perfect and accurate

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900