Here i am clicking on button to see the modal popup and in that popup i am displaying the GridView. On click of LinkButton i am putting Name column value in Textbox and in that event you can search for the Customer Name From table.
HTML:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.modalBackground
{
background-color: Black;
filter: alpha(opacity=60);
opacity: 0.6;
}
.modalPopup
{
background-color: #FFFFFF;
width: 300px;
border: 3px solid #0DA9D0;
border-radius: 12px;
padding: 0;
}
.modalPopup .header
{
background-color: #2FBDF1;
height: 30px;
color: White;
line-height: 30px;
text-align: center;
font-weight: bold;
border-top-left-radius: 6px;
border-top-right-radius: 6px;
}
.modalPopup .body
{
min-height: 50px;
line-height: 30px;
text-align: center;
font-weight: bold;
}
.modalPopup .footer
{
padding: 6px;
}
.modalPopup .yes, .modalPopup .no
{
height: 23px;
color: White;
line-height: 23px;
text-align: center;
font-weight: bold;
cursor: pointer;
border-radius: 4px;
}
.modalPopup .yes
{
background-color: #2FBDF1;
border: 1px solid #0DA9D0;
}
.modalPopup .no
{
background-color: #9F9F9F;
border: 1px solid #5C5C5C;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<cc1:ToolkitScriptManager runat="server">
</cc1:ToolkitScriptManager>
<asp:TextBox ID="txtName" runat="server" />
<asp:Button ID="btnName" Text="GetName" runat="server" />
<asp:Panel ID="pnlAddEdit" runat="server" CssClass="modalPopup" Style="display: none;
text-align: center;">
<div align="center" style="margin:10px 10px 10px 10px;">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" AlternatingRowStyle-BackColor="#C2D69B"
HeaderStyle-BackColor="green">
<Columns>
<asp:BoundField DataField="ContactName" HeaderText="Contact Name" HtmlEncode="true" />
<asp:TemplateField ItemStyle-Width="30px" HeaderText="CustomerID">
<ItemTemplate>
<asp:LinkButton ID="lnkGetName" runat="server" Text="Get Name" OnClick="GetName"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle BackColor="#C2D69B" />
</asp:GridView>
</div>
</asp:Panel>
<cc1:ModalPopupExtender ID="popup" runat="server" DropShadow="false" PopupControlID="pnlAddEdit"
TargetControlID="btnName" BackgroundCssClass="modalBackground">
</cc1:ModalPopupExtender>
</div>
</form>
</body>
</html>
C#:
private String strConnString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.BindData();
}
}
private void BindData()
{
string strQuery = "select top 10 CustomerID,ContactName,CompanyName" +
" from customers";
SqlCommand cmd = new SqlCommand(strQuery);
GridView1.DataSource = GetData(cmd);
GridView1.DataBind();
}
private DataTable GetData(SqlCommand cmd)
{
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
con.Open();
sda.SelectCommand = cmd;
sda.Fill(dt);
return dt;
}
}
}
protected void GetName(object sender, EventArgs e)
{
this.txtName.Text = ((sender as LinkButton).NamingContainer as GridViewRow).Cells[0].Text;
// Write your code to search with CustomerName
}
Thank You.