Here I made a sample for you.It might help you
Html Code
<div>
<asp:TextBox ID="txtId" runat="server"></asp:TextBox>
<asp:Button ID="btnShowDetails" runat="server" Text="ShowDetails"
onclick="btnShowDetails_Click" />
</div>
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" Visible="false">
<Columns>
<asp:BoundField DataField="ElectionId" HeaderText="ElectionId" />
<asp:BoundField DataField="UserName" HeaderText="User Name" />
<asp:BoundField DataField="Gender" HeaderText="Gender" />
<asp:BoundField DataField="VotingStatus" HeaderText="Status" />
</Columns>
</asp:GridView>
</div>
Code
private void GetData()
{
SqlDataSource SqlDataSource1 = new SqlDataSource();
this.Page.Controls.Add(SqlDataSource1);
SqlDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
SqlDataSource1.SelectCommand = "SELECT * FROM Table_Election WHERE ElectionId ='"+this.txtId.Text.Trim()+"'";
this.GridView1.DataSource = SqlDataSource1;
this.GridView1.DataBind();
this.GridView1.Visible = true;
}
protected void btnShowDetails_Click(object sender, EventArgs e)
{
this.GetData();
}
Namespaces
using System;
using System.Web.UI.WebControls;
using System.Configuration;