datalist by button click and display record on formview in model using Username
here is what i tried
<asp:DataList ID="GetMergedAll." runat="server">
<asp:Label ID="Name" runat="server" Text="Label"></asp:Label>
<asp:Label ID="Post" runat="server" Text="Label"></asp:Label>
<asp:LinkButton ID="LinkButton6" runat="server">LinkButton</asp:LinkButton>
</asp:DataList>
protected void Page_Load(object sender, EventArgs e)
{
// int.Parse(Request.QueryString["Id"].ToString());
if (Session["UserName"] != null && Session["UserName"].ToString() != string.Empty)
{
Session["Id"] = Session["Id"].ToString();
Session["Name"] = Session["Name"].ToString();
string username = Session["UserName"].ToString();
string id = Session["UserName"].ToString();
GetPost(username);
}
}
public void GetPost(string username)
{
// int followerid;
// int followingid;
string str = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
string getADPOST = "GetMessage";
using (SqlConnection con = new SqlConnection(str))
{
con.Open();
using (SqlCommand cmd = new SqlCommand(getADPOST, con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UserName", username);
// cmd.Parameters.AddWithValue("@FriendUserName", username);
// cmd.Parameters.AddWithValue("@FollowingId", follower);
//
SqlDataAdapter da = new SqlDataAdapter(cmd);
// DataTable ds = new DataTable();
DateTime.Now.AddDays(-5);
DataTable ds = new DataTable();
ds.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Description",typeof(string)) });
da.Fill(ds);
//
GetMergedAll.DataSource = ds;
GetMergedAll.DataBind();
}
on formview in model
public void GetProfile(string username2)
{
string str = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
string getADPOST = "GetPost";
using (SqlConnection con = new SqlConnection(str))
{
con.Open();
using (SqlCommand cmd = new SqlCommand(getADPOST, con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UserName", username2);
// cmd.Parameters.AddWithValue("@FriendUserName", Request.QueryString["Id"].ToString());
cmd.Parameters.AddWithValue("@FriendUserName", username2);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable ds = new DataTable();
da.Fill(ds);
Post.DataSource = ds;
Post.DataBind();
}
// conn.close();
}
}
html
model here
<asp:FormView ID="Post" runat="server">
<asp:Label ID="Name" runat="server" Text="Label"></asp:Label>
<asp:Label ID="Post" runat="server" Text="Label"></asp:Label>
</asp:FormView>