简体   繁体   English

如何在 html 表中添加按钮并使用 asp.net 和 C# 创建事件?

[英]How to add button in html table and create event using asp.net and C#?

I wanted to add button in the html table column from the C#.我想在 C# 的 html 表列中添加按钮。 I have attached the code behind and asp.net in the code.button is creating in the column for each row but not calling to the click event.我已经附加了后面的代码,并且在 code.button 中的 asp.net 正在为每一行的列中创建但不调用单击事件。

        public string getWhileLoopData()
    {
        string htmlStr = "";

        SqlCommand thisCommand = thisConnection.CreateCommand();
        thisCommand.CommandText = "SELECT Id,EmployeeEmail,PayReference from EmployeeDetails";
        thisConnection.Open();
        SqlDataReader reader = thisCommand.ExecuteReader();

        PlaceHolder PlaceHolder1 = new PlaceHolder();

        while (reader.Read())
        {
            long id = reader.GetInt64(0);
            string Name = reader.GetString(1);
            string Pass = reader.GetString(2);[enter image description here][1]
            htmlStr += "<tr class='row_data'><th data-employee-id='" + id + "'>" + id + "</th><th>" + Name + "</th><th>" + Pass + "</th><th>  <input id='Button1' runat='server' class='button right' onserverclick='Button1_Click' type='submit' value='Update' /> </th></tr>";
        }

        thisConnection.Close();
        return htmlStr;
    }

ASP.NET code is below ASP.NET 代码如下

    <table id="myTable" class="table table-striped">
        <thead align="left" style="background-color: #004080; color: White;">
            <tr>
                <th>
                    Id
                </th>
                <th>
                    Email Address
                </th>
                <th>
                    Empr Paye Ref.
                </th>
                <th>
                    Open
                </th>
            </tr>
        </thead>
        <tbody>
            <%=getWhileLoopData()%>
        </tbody>
    </table>

There's no event called onserverclick .没有名为onserverclick的事件。 You can use asp button instead of html button and use onclick event.您可以使用 asp 按钮代替 html 按钮并使用onclick事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM