There is a site with a table of contacts.

enter image description here

Everything is fine, I take data from the database, everything works.

Now the problem with the button "Find All". This is the modal window call 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> 

Here I pass the record id CommandArgument = '<%# Eval("id") %>' , which caused the modal window.

As I understand it, I need to click the OnCommand="ShowContact_Click" to send a request to the database and get data on the contact. How can I do this?

 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); } } 

Base type

 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 can I transfer the full name of a person to the header of a modal window?

Modal 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> 
  • What do you mean by a modal window, since it is a question, as I understand it about ASP.Net (judging by the tag). How is it implemented: as a separate window, as a block, or how? - Ella Svetlaya
  • This is a bootstrap window. <div id = "myModal" class = "modal fade" role = "dialog"> - shatoidil
  • So what is the question after all? It is impossible to get data from the database (judging by the header), or do you need to transfer the data received from the database to the bootstrap window (ie, transfer data from the back-end to the front-end)? Display the window itself on the button you get? - Ella Svetlaya 2:58 pm
  • @ ella-svetlaya Yes, displaying a modal window is not a problem. But as I proceed from the id of the selected table, display in the modal in the heading of the full name. That is, they chose Marina and clicked the "Learn All" button. How can I display the full name in the opened modal window, then I'll figure it out myself. Thank! - shatoidil
  • I do not quite understand what the problem is. Simply assign the desired text in the label. For example, labelModalTitle = strUserFIO; Show the code of the modal window. - Ella Svetlaya

1 answer 1

Can someone come in handy!

 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<string> fio = new List<string>(); 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(); } 
  • Add a LIMIT 1 in the request. need to return only one entry. - Ella Svetlaya