locked
put the dynamic link button into html.append RRS feed

  • Question

  • User-646447061 posted

    i have code behind like this

    html.append("<table>");
    html.append("<tr>");
    html.append("<td>");
    html.append("</td>");
    html.append("</tr>");
    html.append("</table>");

    PlaceHolder1.Controls.Add(new Literal { Text = html.ToString() });

    and 

    LinkButton likbt = new LinkButton();
    likbt.Text = "Accept";
    likbt.ID = "lnkbtn"+row["id_order"];
    likbt.CommandArgument = row["id_order"].ToString();
    likbt.Attributes.Add("UseSubmitBehavior", "false");
    likbt.Command += likbt_Click;

    how to put the linkbutton into between tag <td></tr>

    Sunday, October 16, 2016 3:34 PM

All replies

  • User1724605321 posted

    Hi motorrevo00,

    You could use HtmlTable control :

        protected void Page_Load(object sender, EventArgs e)
        {
            HtmlTable tbl = new HtmlTable();
            HtmlTableRow tr = new HtmlTableRow();
            HtmlTableCell td = new HtmlTableCell();
            tr.Cells.Add(td);
            tbl.Rows.Add(tr);
    
    
            LinkButton lbtn = new LinkButton();
            lbtn.Text = "My Link Button";
            lbtn.Click += new EventHandler(LinkButton1_Click);
    
    
            td.Controls.Add(lbtn);
        }
    
    
        protected void LinkButton1_Click(object sender, EventArgs e)
        {
    //your implementation of link button click goes here
        }

    or use html <a> tag :

               StringBuilder html =new StringBuilder();
                html.Append("<table>");
                html.Append("<tr>");
                html.Append("<td>");
                //You can use an <a> instead of <linkbutton>
                html.Append("<a id='lnkbtn*' href='***' usesubmitbehavior = 'false'>Accept</a>");
                html.Append("</td>");
                html.Append("</tr>");
                html.Append("</table>");
                PlaceHolder1.Controls.Add(new Literal { Text = html.ToString() });
    

    Best Regards,

    Nan Yu

    Monday, October 17, 2016 7:44 AM
  • User-2001765250 posted

    You can do this using table class Or HTMLtable class.

    refer the below code using Table.

     Table tbl = new Table();
    TableRow tRow = new TableRow(); tbl.Rows.Add(tRow); for (cellCtr = 1; cellCtr <= cellCnt; cellCtr++) { // Create a new cell and add it to the row. TableCell tCell = new TableCell(); tCell.Text = "Row " + rowCtr + ", Cell " + cellCtr; tRow.Cells.Add(tCell); }
    tbl.Controls.Add(tRow);

    Hope this helps.
    Monday, October 17, 2016 7:46 AM
  • User-646447061 posted

    how to add command argument in tag a href ?

    try to write this code :

    html.Append("<a UseSubmitBehavior='false' OnClick='likbt_Click' CommandArgument=");
    html.Append(row["id_order"].ToString());
    html.Append(" >Accept</a>");

    protected void likbt_Click(object sender, CommandEventArgs e)

    {
    Session["id_order"] = e.CommandArgument ;
    ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openmodalaccept();", true);
    }



    but when i'm clicking nothing happen

    if, use select button the code work .. but i prefer to use us an <a></a>

    thanks before Nan Yu

    Monday, October 17, 2016 8:26 PM
  • User1724605321 posted

    Hi motorrevo00,

    You could record id in name attribute of a tag :

                StringBuilder html = new StringBuilder();
                html.Append("<table>");
                html.Append("<tr>");
                html.Append("<td>");
                //You can use an <a></a> instead of <linkbutton>
                html.Append("<a id='lnkbtn1' name = '123' onclick='test(this)' > Accept</a>");
    
                html.Append("</td>");
                html.Append("</tr>");
                html.Append("</table>");
                PlaceHolder1.Controls.Add(new Literal { Text = html.ToString() }); 

    Get the attribute and call model popup :

                function test(obj) {      
                var currentOrderID = $(obj).attr('name');
                alert(currentOrderID);
                // Call model popup 
                openmodalaccept();
                } 

    Best Regards,

    Nan Yu

    Tuesday, October 18, 2016 9:37 AM
  • User-646447061 posted

    i'm planning when the a href is click then the id set session and open the modal .. so, i want running code behind 
    Thank You Nan Yu

    Tuesday, October 18, 2016 3:17 PM
  • User1724605321 posted

    Hi ,

    Then try to use HtmlTable control as shown above code sample  . or use jquery ajax call server side function to store id in session , then call modal popup .

    Best Regards,

    Nan Yu

    Wednesday, October 19, 2016 1:19 AM
  • User-646447061 posted

    so hard =( , so i use repeter control to show data and add link button ..
    Thank Nan Yu

    Friday, October 21, 2016 3:38 AM