.Net with C#. Iv'e created a repeater control in my ASPX and bind it from C#. I want to use the click event of the button for that, if the user clicks the button it shows the values of the row in the database.

In the repeater I bind the username from a database table. If the user clicks on the username it should display the user details in a label outside the repeater.

Code of the repeater control:

<asp:Repeater ID="rpt3" runat="server">
    <ItemTemplate>  
        <h3>   <%#Eval("name") %>  </h3>
        <asp:Button ID="Button1" runat="server" Text="Show Details"/> 
    </ItemTemplate>
</asp:Repeater>

<asp:Label ID="Label1" runat="server" ></asp:Label>

C# code behind

public void Getuser()
{
    using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
    {

        SqlCommand cmd = new SqlCommand("select name from message  where emailid= '" + Session["un"].ToString() + "'", con);
        DataTable dt = new DataTable();
        SqlDataAdapter da = new SqlDataAdapter(cmd);

        con.Open();
        da.Fill(dt);
        if (dt.Rows.Count > 0 && dt.Rows[0][0] != string.Empty)
        {
            rpt3.DataSource = dt;
            rpt3.DataBind();
        }
        else
        {
            rpt3.DataSource = null;
            rpt3.DataBind();
        }
        con.Close();
    }
}

Design that i want

0 Answers