How to get data from html column of table and pass to C#

I have a html table with data from sql. Each line has a “give” button. I need that when pressed, the value of the “code” cell is transferred to C# code. The “code” column has unique values and can be used as id.

<asp:Repeater ID="Repeater1" runat="server">  
    <HeaderTemplate>
<table class="table table-striped table-hover">
  <thead class="thead-light">
    <tr>
      <th></th>
      <th scope="col">name</th>
      <th scope="col">sur</th>
      <th scope="col">code</th>
    </tr>
  </thead>
    </HeaderTemplate>
     <ItemTemplate>
  <tbody id="myTable">
    <tr>
      <th><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">give</button> </th>
     
        <td><%# Eval("name")%></td>
        <td><%# Eval("sur")%></td>
        <td><%# Eval("code")%></td>
              
    </tr>
      </tbody>
   </itemtemplate>
     <FooterTemplate>
         
   </table>

        </FooterTemplate>
    
     </asp:Repeater>

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

If I get your question truly,

you can use commandArgument
But first if you dont have any guid or Id
you have create it in sql or frontSide, my opinion newID() in sql query is perfect
then put it in hiddenvalue or CommandArgument in frontSide.
then C# side you can handle all process in Repeater1_ItemCommand and take data from

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    if (e.CommandName == "guid")
    {
        Int32 id = Convert.ToInt32(e.CommandArgument);
    }
}

Also look the article
Pass an ID to OnClick event with Repeater control?


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x