Data extraction into a modular window from the database



  • There's a website with the contact table.

    введите сюда описание изображения

    It's great, I'm taking data from the base all work.

    Now the problem with the "know" button. It's a fashion window button.

    <td>                                        
    <asp:Button ID="ShowContact" runat="server" Text="Узнать всё" data-toggle="modal" CssClass="btn btn-success btn-xs" CommandArgument = '<%# Eval("id") %>' data-target="#myModal" OnCommand="ShowContact_Click"/>
    </td>
    

    This is where I hand over the id records. CommandArgument = '<%# Eval("id") %>'the one that called the fashion window.

    I understand I need a click event. OnCommand="ShowContact_Click" send a request to the database and get the contact details. How do I do that?

    protected void ShowContact_Click(object sender, CommandEventArgs e)
            {
                int rowInd = Convert.ToInt32(e.CommandArgument);
                conn = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MySQLString"].ConnectionString);
                comm = new MySqlCommand("Команда", conn);
    
        }
    }
    

    Type base

    persons

    +----+-----------+-----+
    | id | firstname | age |
    +----+-----------+-----+
    | 1 | Катя | 12 |
    | 2 | Лена | 18 |
    +----+-----------+-----+
    email

    +----+-----------+-----------+
    | id | email     | person_id |
    +----+-----------+-----------+
    |  1 | wer@sdf.ru|  1        |
    |  2 |           |  2        |
    +----+-----------+-----------+
    

    telephone

    +----+-----------+-----------+
    | id | phone     | person_id |
    +----+-----------+-----------+
    |  1 | 3423434324|  1        |
    |  2 |           |  2        |
    +----+-----------+-----------+
    

    How do I put a man in the head of the fashion window?

    Modular window code:

        <!-- Modal -->
    <div id="myModal" class="modal fade" role="dialog">
    <div class="modal-dialog">
    <asp:UpdatePanel ID="upModal" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
    <ContentTemplate>
    <!-- Modal content-->
    <div class="modal-content">
    <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">&times;</button>
    <h4 class="modal-title">
    </h4>
    </div>
    <div class="modal-body">
    <p>Some text in the modal.</p>
    </div>
    <div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
    </div>
    </div>
    </ContentTemplate>
    </asp:UpdatePanel>
    </div>
    </div>



  • Maybe someone needs it!

    protected void ShowContact_Command(object sender, CommandEventArgs e)
    {
        int rowInd = Convert.ToInt32(e.CommandArgument);
        conn = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MySQLString"].ConnectionString);
    
    comm = new MySqlCommand("SELECT * FROM persons WHERE id = @id", conn);
    comm.Parameters.AddWithValue("@id", rowInd);
    conn.Open();
    List&lt;string&gt; fio = new List&lt;string&gt;();
    MySqlDataReader reader = comm.ExecuteReader();
    ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);
    while (reader.Read())
    {
        this.FIO.Text = string.Format("{0} {1} {2}", reader.GetString("lastname"), reader.GetString("firstname"), reader.GetString("middlename"));
    }
    reader.Close();
    conn.Close();
    

    }




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2