0

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>
Yehor Androsov
  • 4,885
  • 2
  • 23
  • 40
zaknafein
  • 21
  • 4
  • 1
    you can make an ajax call on button's click event https://stackoverflow.com/questions/12656833/jquery-post-data-in-aspx-page – Mihir Dave Dec 29 '20 at 09:58

1 Answers1

0

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?