title: Show modal by item ID in ASP.NET WebForms
body: <p>I'm using repeaters to display a list of items retrieved from the database. I would like to support basic CRUD operations on such items via a simple modal dialog box.</p>
  
  <p>I have tried using <code>onitemcommand</code> to manipulate each item, I tried using labels to get id, I have also tried using <code>OnClick</code> on the buttons, with no luck. 
  Here it is the code for my repeater:</p>
  
  <pre><code>    &lt;div class="container-fluid"&gt;
        &lt;div class="row justify-content-left card-group"&gt;
           &lt;asp:Repeater  ID="DataList1" runat="server" onitemcommand="DataList1_ItemCommand"&gt;
              &lt;ItemTemplate&gt;
                 &lt;div class="col-md-4  " style="margin-bottom: 1em;"&gt;
                    &lt;%--A loop through the records in database--%&gt;
                    &lt;div class="card border-light mb-4 "&gt;
                       &lt;div class="card-content " &gt;
                          &lt;div class="card-header "&gt;
                             &lt;h4 class="my-0 font-weight-normal"&gt;
                                &lt;asp:label ID="nameTage" style="font-size:16px;color:steelblue;" Text= '&lt;%# Eval("ProjectName") %&gt;' runat="server"/&gt;
                                 &lt;asp:label ID="pID" Text='&lt;%#  DataBinder.Eval(Container.DataItem,"ProjectID") %&gt;' runat="server" Visible="false"/&gt;
                             &lt;/h4&gt;
                          &lt;/div&gt;
                          &lt;div class="card-body "&gt;
                             &lt;div class="d-flex justify-content-between align-items-center"&gt;
                                &lt;div class="btn-group"&gt;
                                   &lt;h6 class="card-text" style="font-size:10px; color:#a51313"&gt;
                                      &lt;span class="Text" &gt;  &lt;%--The project description goes here--%&gt;                            
                                      &lt;%-- &lt;%= myItem["ProjDescription"].ToString() %&gt;--%&gt;
                                      &lt;%# Eval("ProjDescription") %&gt;
                                      &lt;/span&gt;
                                   &lt;/h6&gt;
                                &lt;/div&gt;
                             &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="card-footer "&gt;
                             &lt;%--These are not for the submit buttons, they are for the models--%&gt; 
                             &lt;%--Get the ID of the Project--%&gt;
  
  
                             &lt;%--&lt;div class="btn-toolbar  pull-right" id="buttonID" role="group" aria-label="Basic example" style="font-size:9px; color:white; align-content:center" runat="server"&gt;--%&gt;
                                &lt;asp:LinkButton type="button" ID="btn_details" class="btn btn-success btn-sm m-1" aria-pressed="true" data-toggle="modal" data-target="#detailsModal" runat="server" OnClick="IDButton1_Click" CausesValidation="false" CommandArgument='&lt;%# DataBinder.Eval(Container.DataItem,"ProjectID") %&gt;' CommandName="Details" Text="Details"&gt;&lt;/asp:LinkButton&gt;
                                &lt;asp:LinkButton type="button" ID="btn_edit"   class="btn btn-success btn-sm m-1" aria-pressed="true" data-toggle="modal" data-target="#editModal"   runat="server"  CausesValidation="false" CommandArgument='&lt;%# Eval("ProjectID") %&gt;' CommandName="Edit" Text="Edit"&gt;&lt;/asp:LinkButton&gt;
                                &lt;asp:LinkButton type="button" ID="btn_delete" class="btn btn-success btn-sm m-1" aria-pressed="true" data-toggle="modal" data-target="#deleteModal" runat="server"  CausesValidation="false" CommandArgument='&lt;%# Eval("ProjectID") %&gt;' CommandName="Delete" Text="Delete"&gt;&lt;/asp:LinkButton&gt;
                             &lt;%--&lt;/div&gt;--%&gt;
                          &lt;/div&gt;
                       &lt;/div&gt;
                    &lt;/div&gt;
                 &lt;/div&gt;
              &lt;/ItemTemplate&gt;
           &lt;/asp:Repeater&gt;
           &lt;%-- &lt;% } %&gt;--%&gt;
        &lt;/div&gt;
     &lt;/div&gt;
  '''
  &lt;!-- Modal for Details --&gt;
      &lt;%--Get the ID of the Project--%&gt;
     &lt;div class="modal fade" id="detailsModal" tabindex="-1" role="dialog" aria-labelledby="detailsModalLabel" aria-hidden="true"&gt;
        &lt;div class="modal-dialog" role="document"&gt;
           &lt;div class="modal-content"&gt;
              &lt;div class="modal-header"&gt;
                 &lt;h5 class="modal-title" id="detailsModalLabel"&gt;Mission Project&lt;/h5&gt;
                 &lt;%--project.Name--%&gt;
                 &lt;button type="button" class="close" data-dismiss="modal" aria-label="Close"&gt;
                 &lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;
                 &lt;/button&gt;
              &lt;/div&gt;
              &lt;div class="modal-body"&gt;              
                 &lt;div class="form-horizontal col-8"&gt;
                    &lt;div class="form-group row"&gt;
                       &lt;asp:label Text="Project Title:" class="control-label" runat="server"/&gt;
                       &lt;asp:TextBox ID="TB1" Text="" runat="server" class="form-control" ReadOnly="true"&gt;&lt;/asp:TextBox&gt;
                    &lt;/div&gt;
                    &lt;div class="form-group row"&gt;
                       &lt;asp:label Text="Project Description:" class="control-label" runat="server"/&gt;
                       &lt;asp:TextBox ID="TB2" runat="server" class="form-control" rows="4" TextMode="multiline" ReadOnly="true"&gt;&lt;/asp:TextBox&gt;
                    &lt;/div&gt;
                    &lt;div class="form-group row"&gt;
                       &lt;asp:label  Text="Department:" class="control-label" runat="server"/&gt;
                       &lt;asp:TextBox ID="TB3" runat="server" class="form-control" ReadOnly="true"&gt;&lt;/asp:TextBox&gt;
                    &lt;/div&gt;
                    &lt;div class="form-group row"&gt;
                       &lt;asp:label ID="HEreThere" Text="Contact Name:" class="control-label" runat="server"/&gt;
                       &lt;asp:TextBox ID="TB4" runat="server" class="form-control" ReadOnly="true"&gt;&lt;/asp:TextBox&gt;
                    &lt;/div&gt;
                    &lt;div class="form-group row"&gt;
                       &lt;asp:label Text="Launch Date:" class="control-label" runat="server"/&gt;
                       &lt;asp:TextBox ID="TB5" runat="server" class="form-control" ReadOnly="true"&gt;&lt;/asp:TextBox&gt;
                    &lt;/div&gt;
                    &lt;div class="form-group row"&gt;
                       &lt;asp:label Text="Note:" class="control-label" runat="server"/&gt;
                       &lt;asp:TextBox ID="TB6" runat="server" class="form-control" rows="7" TextMode="multiline" ReadOnly="true"&gt;&lt;/asp:TextBox&gt;
                    &lt;/div&gt;
                    &lt;div class="form-group row"&gt;
                       &lt;asp:label Text="Project Status:" class="control-label" runat="server"/&gt;
                       &lt;asp:TextBox ID="TB7" runat="server" class="form-control" ReadOnly="true"&gt;&lt;/asp:TextBox&gt;
                    &lt;/div&gt;
                 &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="modal-footer"&gt;
                 &lt;asp:Button type="button" class="btn btn-secondary" data-dismiss="modal" runat="server" Text="Close" /&gt;
              &lt;/div&gt;
           &lt;/div&gt;
        &lt;/div&gt;
     &lt;/div&gt;
  
      protected void Page_Load(object sender, EventArgs e)
      {
          lblMessage.Text = "";
  
          //data = "";
  
          if (!IsPostBack)
          {
  
          }
  
          DataList1.DataSource = GetProjects();
          DataList1.DataBind();
    }
  
  
      protected void DataList1_ItemCommand(object source, RepeaterCommandEventArgs e)
      {
          if (e.CommandArgument != null)
          {
              if (e.CommandName.Equals("Details"))
              {
                  //int MissID = Convert.ToInt32(e.CommandArgument.ToString());
                  //lblMessage.Text = MissID.ToString
                  ((Label)e.Item.FindControl("pID")).Visible = true;
  
              }
              else if (e.CommandName.Equals("Edit"))
              {
                  ((Label)e.Item.FindControl("pID")).Visible = true;
              }
              else if (e.CommandName.Equals("Delete"))
              {
                  ((Label)e.Item.FindControl("pID")).Visible = true;
              }
  
          }
          //    Label label = e.Item.FindControl("pID") as Label;
  
      }
  
  protected void IDButton1_Click(object sender, EventArgs e)
  {
      RepeaterItem item = (sender as LinkButton).Parent as RepeaterItem;
  
      int MissID = Convert.ToInt32((item.FindControl("pID") as Label).Text);
  
      (item.FindControl("pID") as Label).Visible = true;
      //    get command argument here
      //    int MissID = Convert.ToInt32(((sender as Button).NamingContainer.FindControl("pID") as Label).Text);
  
      //    lblMessage.Text = MissID.ToString();
  
      DataSet dsID = GetProjectByID(MissID);
  
  
      this.TB1.Text = dsID.Tables[0].Rows[0]["ProjectName"].ToString();
      this.TB2.Text = dsID.Tables[0].Rows[0]["ProjDescription"].ToString();
      this.TB3.Text = dsID.Tables[0].Rows[0]["Department"].ToString();
      this.TB4.Text = dsID.Tables[0].Rows[0]["ContactName"].ToString();
      this.TB5.Text = dsID.Tables[0].Rows[0]["DueDate"].ToString();
      this.TB6.Text = dsID.Tables[0].Rows[0]["Notes"].ToString();
      this.TB7.Text = GetStatusText(dsID.Tables[0].Rows[0]["StatusID"].ToString());
  
  }
  </code></pre>