Click here to Skip to main content
15,902,299 members
Please Sign up or sign in to vote.
1.33/5 (3 votes)
See more:
Good morning friends,
I take a one literal for dynamically display the code in similar design. In that each description has button which is dynamically create. All things display correctly but cant able to handle that on click command .
Can anyone help me please...

My code is

string str = "<div id=\"testDiv\"> ";
              if (dt.Rows.Count > 0)
              {
                  for (int i = 0; i < dt.Rows.Count; i++)
                  {
                      string JobTitle = dt.Rows[i]["Title"].ToString();
                      string Description = dt.Rows[i]["Description"].ToString();
                      string Company = dt.Rows[i]["EmployerName"].ToString();
                      string Location = dt.Rows[i]["Location"].ToString();
                      string AddedDate = Convert.ToDateTime(dt.Rows[i]["CreatedDate"].ToString()).ToString("D");
                      string Exp = dt.Rows[i]["MinExperience"].ToString() + " - " + dt.Rows[i]["MaxExperience"].ToString() + " Years";
                      string Salary = dt.Rows[i]["MinAnnualCTC"].ToString() + " - " + dt.Rows[i]["MaxAnnualCTC"].ToString() + " Lac P.A.";
                      string JobType = dt.Rows[i]["JobType"].ToString();
                      string JobID = dt.Rows[i]["JobID"].ToString();
                      string apply = "true";
                      if (Description.Length > 70)
                          Description = Description.Substring(0, 70).ToString() + " ... ";

                      str += "<div class=\"job_box\">" +
                            "    <div class=\"job_related_img\">" +
                            "      <img class=\"img-responsive\" src=\"../images/job_img.jpg\">" +
                            "   </div>" +
                            "   <div class=\"job_related_info\">" +
                            "     <div class=\"headtext\">" +
                            "   " + JobTitle + "</div>" +
                            "        <div>" +
                            "   <p>" +
                            "       " + Description + "</p>" +
                            "      </div>" +
                            "    <div class=\"comp_name\">" +
                            "   <p>" +
                            "       " + Company + "</p>" +
                            "       </div>" +
                            "      <div class=\"comp_location\">" +
                            "       <img src=\"../images/location.png\">" + Location + "" +
                            "         </div>" +
                            "        <div class=\"post_dt\">" +
                            "   <span>|</span> added " + AddedDate + "</div>" +
                            "      <div class=\"clearfix\">" +
                            "    </div>" +
                            "   <div class=\"set_bor\">" +
                            "    </div>" +
                            "   </div>" +
                            "  <div class=\"time_duration\">" +
                            "     <img src=\"../images/time.png\">" +
                            "     <span>" + JobType + "</span></div>" +
                            "<div class=\"time_durationhrs\">" +
                            "    <img src=\"../images/hrs.png\">" +
                            "   <span>" + Salary + "</span></div>" +
                            " <div class=\"app_vew_btn\">"+
                            "  <div> <span><font color=red>APPLIED</font></span></div><a class=\"log_in\" href=\"../JobDescription.aspx?id=" + JobID + "&apply=" + apply + "\">VIEW MORE</a></div>" +
                            "<div class=\"clearfix\">" +
                            "</div>" +

                  }
              }
              str += "    </div>";
              litBrowseAppliedJobs.Text = str;

          }

In place of anchor tag I want button.
Posted
Updated 7-Dec-15 22:02pm
v2
Comments
Suvendu Shekhar Giri 7-Dec-15 23:43pm    
Share the relevant code so that we'll be able to know how you are doing this and accordingly can suggest a solution.
asplover1 8-Dec-15 4:03am    
Thanx for replay I shared my code please see.
[no name] 8-Dec-15 0:47am    
Please share the code which are relevant to your issue. Just add code by the help of "Improve question" link.
asplover1 8-Dec-15 4:03am    
Thanx for replay I shared my code please see.
Ralf Meier 8-Dec-15 5:07am    
Maybe my glasses are dirty ... but I can't see the code-line where the Buttons are created dynamicly. Please check this ...

1 solution

Try with below code:

Change following code for adding button instead of anchor tag:
C#
"<div> <span><font color="red">APPLIED</font></span></div>
<button onclick="myFunction(\"JobDescription.aspx?id=" + JobID + "&apply=" + apply + "\")">VIEW MORE</button>" +

Add javascript function to redirect:
JavaScript
<script type="text/javascript">
  function myFunction() {
    location.href = "http://www.cnn.com";
  }
</script>
 
Share this answer
 

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