sanjlaxmi

sanjlaxmi

  • NA
  • 10
  • 4.1k

How to retrive information on click event of Linkbutton

Jan 22 2014 3:39 AM
Hi All,
Pls Check below code,I want to retrieve information related to linkbutton


***********First Aspx Page ***************

<asp:GridView ID="gvForum" CssClass="gvForum" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" CellPadding="4" ForeColor="#333333"
GridLines="None" onrowcommand="gvForum_RowCommand">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="ForumTitle" SortExpression="ForumTitle">

<ItemTemplate>
<asp:LinkButton ID="lbForumTitle" runat="server" Text='<%# Bind("ForumTitle") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ForumType" SortExpression="ForumType">

<ItemTemplate>
<asp:LinkButton ID="lbForumType" runat="server" Text='<%# Bind("ForumType") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="UserName" SortExpression="UserName">

<ItemTemplate>
<asp:LinkButton ID="lbUserName" runat="server" Text='<%# Bind("UserName") %>' CommandName="UserNameQuest" CommandArgument='<%#Eval("UserName") %>'>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PostDate" SortExpression="PostDate">

<ItemTemplate>
<asp:Label ID="lbPostDate" runat="server" Text='<%# Bind("PostDate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

</Columns>

</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

SelectCommand="SELECT tbl_Forum.ForumTitle, tbl_ForumTypes.ForumType, UserInfo.UserName, tbl_Forum.PostDate FROM tbl_Forum INNER JOIN tbl_ForumTypes ON tbl_Forum.ForumTypeId = tbl_ForumTypes.ForumTypeId INNER JOIN UserInfo ON tbl_Forum.UserId = UserInfo.UserId">
</asp:SqlDataSource>


***********First Aspx.cs Code********



protected void gvForum_RowCommand(object sender, GridViewCommandEventArgs e)
{

if (e.CommandArgument != null)
{
Response.Redirect("~/Forum/UserQuest.aspx?UserName=" + e.CommandArgument.ToString());
}
}




*********Second Aspx Page*********i.e /Forum/UserQuest.aspx

<asp:GridView ID="GridView1" runat="server">
</asp:GridView>


********Second Aspx.cs Code***********


protected void Page_Load(object sender, EventArgs e)
{
string name = Convert.ToString(Request.QueryString["UserName"]);

SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\ASPNETDB.MDF;Integrated Security=True;User Instance=True";
con.Open();
SqlCommand cmd = new SqlCommand("SELECT tbl_Forum.ForumTitle, tbl_ForumTypes.ForumType, UserInfo.UserName, tbl_Forum.PostDate FROM tbl_Forum INNER JOIN tbl_ForumTypes ON tbl_Forum.ForumTypeId = tbl_ForumTypes.ForumTypeId INNER JOIN UserInfo ON tbl_Forum.UserId = UserInfo.UserId WHERE UserInfo.UserName ="'+name+'"", con);

SqlDataAdapter da = new SqlDataAdapter(cmd);

//DataSet ds = new DataSet();
//da.Fill(ds);

DataTable dt = new DataTable();
da.Fill(dt);

GridView1.DataSource = dt;
GridView1.DataBind();
con.Close();

}


please help me out to try solve

after click on linkbutton in first gridview it will redirect to second page with another gridview in which all information related to linkbutton exist.

i.e if i click on username(suppose 'abc') of linkbutton of first gridvu den i wil get all question posted by that username only in second gridvu

Answers (2)