How to add link button in gridview and display result in form view after clicking link button on another page
Designer Code
<asp:GridView ID="GridView2" runat="server" >
<Columns>
<asp:TemplateField HeaderText="More Info" SortExpression="member_id">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("member_id") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" OnClick="LinkButton2_Click">Get
Details</asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
</asp:GridView>
Code Behind
protected void GridView2_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Text = "More Info";
e.Row.Cells[1].Text = "Posting Date";
e.Row.Cells[2].Text = "Want To";
e.Row.Cells[3].Text = "City";
e.Row.Cells[4].Text = "Property Type";
e.Row.Cells[5].Text = "Area(Sq/ft)";
e.Row.Cells[6].Text = "Property Rent / Price";
e.Row.Cells[7].Text = "Member Id";
}
e.Row.Cells[7].Visible = false; // hiding column in runtime
}
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Text = "More Info";
e.Row.Cells[1].Text = "Posting Date";
e.Row.Cells[2].Text = "Want To";
e.Row.Cells[3].Text = "City";
e.Row.Cells[4].Text = "Property Type";
e.Row.Cells[5].Text = "Area(Sq/ft)";
e.Row.Cells[6].Text = "Property Rent / Price";
e.Row.Cells[7].Text = "Member Id";
}
e.Row.Cells[7].Visible = false; // hiding column in runtime
}
protected void btnSearch_Click(object sender, EventArgs e)
{
{
SqlConnection con = new SqlConnection(strConnString);
SqlDataAdapter da = new SqlDataAdapter("select query", con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView2.DataSource = ds;
GridView2.DataBind();
SqlDataAdapter da = new SqlDataAdapter("select query", con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView2.DataSource = ds;
GridView2.DataBind();
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
GridViewRow gvr = (GridViewRow)((LinkButton)sender).Parent.Parent;
string memberID = gvr.Cells[7].Text;
Response.Redirect("property-details.aspx?memberID=" + memberID);
}
{
GridViewRow gvr = (GridViewRow)((LinkButton)sender).Parent.Parent;
string memberID = gvr.Cells[7].Text;
Response.Redirect("property-details.aspx?memberID=" + memberID);
}
On another page.aspx
Designer Code
<asp:FormView ID="FormView1" runat="server">
<ItemTemplate>
<table style="width: 90%">
<tr>
<td align="right" colspan="2" style="color: Red ; font-size: small;">
<%# Eval("column1") %>
</td>
</tr>
<tr>
<td align="center" style="color: #FFFFFF; font-size: large;" bgcolor="#0066CC"
colspan="2">
Property Details</td>
</tr>
<tr>
<td align="left" colspan="2" style="color: #000000;">
<br /><b>Address:</b> <%# Eval("column2") %>
<br /><br />
</td>
</tr>
</table>
</ItemTemplate>
</asp:FormView>
Code Behind
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SqlConnection con = new SqlConnection(strConnString);
SqlDataAdapter da = new SqlDataAdapter("select ... where member_id='" + Request.QueryString["memberID"].ToString() + "'", con);
DataSet ds = new DataSet();
da.Fill(ds);
FormView1.DataSource = ds;
FormView1.DataBind();
}
{
if (!Page.IsPostBack)
{
SqlConnection con = new SqlConnection(strConnString);
SqlDataAdapter da = new SqlDataAdapter("select ... where member_id='" + Request.QueryString["memberID"].ToString() + "'", con);
DataSet ds = new DataSet();
da.Fill(ds);
FormView1.DataSource = ds;
FormView1.DataBind();
}
No comments:
Post a Comment