Hello
So I am working on a project, and when the button is clicked I want to select the first 10 rows from a database, and when clicked again it selects the next 10 rows, and the next and so on. What I am working on is something of along the lines as a user blog,
where that the user can click on the comments, and the first 10 comments are visible, and then they have the ability to click on view more comments, which will then display the next 10 comments. it allows 10 comments at a time.
Here is a look at my code, and if more code is needed just let me know, but this is where a lot of the action is.
Thanks and I appreciate any help
protected void ViewMoreComments_Click(object sender, EventArgs e)
{
LinkButton MoreComments = sender as LinkButton;
string UserName = Session["UserName"].ToString();
string Id = MoreComments.ID.Remove(0, 16);
//ViewMoreComments[Convert.ToInt32(Id)].Visible = false;
//CommentBox[Convert.ToInt32(Id)].Visible = false;
//PostComment[Convert.ToInt32(Id)].Visible = false;
BlogPost.RetrieveComments(UserName, UserPosts, Id, Text, UserComments,
CommentImage, CommentName, CommentDate, NumOfComments, ViewMoreComments);
}
public void RetrieveComments(string UserName, Panel UserPosts, string Comment, Label[] Text,
Label[,] UserComments, ImageButton[,] CommentImage,
Label[,] CommentName, Label[,] CommentDate,
LinkButton[] NumOfComments, LinkButton[] ViewMoreComments)
{
SqlCommand UpdateComments = new SqlCommand(@"Select Comments, UserName, Date FROM BlogComments WHERE UserPost=@UserPost", connection);
UpdateComments.Parameters.AddWithValue("@UserPost", Text[Convert.ToInt32(Comment)].Text);
UpdateComments.Parameters.AddWithValue("@UserName", UserName);
//int PostNumber = Convert.ToInt32(Comment[c].ID.Remove(0, 7));
//UpdateComments.Parameters["@PostNumber"].Value = Comment;
//int Post = Convert.ToInt32(UpdateComments.ExecuteScalar());
SqlDataAdapter adapter = new SqlDataAdapter(UpdateComments);
DataTable dt = new DataTable();
adapter.Fill(dt);
try
{
for (int c = 0; c < 10; c++)
{
CommentImage[Convert.ToInt32(Comment), c].AlternateText = dt.Rows[c]["UserName"].ToString();
CommentImage[Convert.ToInt32(Comment), c].ToolTip = dt.Rows[c]["UserName"].ToString();
CommentName[Convert.ToInt32(Comment), c].Text = dt.Rows[c]["UserName"].ToString();
CommentDate[Convert.ToInt32(Comment), c].Text = dt.Rows[c]["Date"].ToString();
UserComments[Convert.ToInt32(Comment), c].Text = dt.Rows[c]["Comments"].ToString();
if (UserComments[Convert.ToInt32(Comment), c].Visible == false)
{
UserComments[Convert.ToInt32(Comment), c].Visible = true;
CommentImage[Convert.ToInt32(Comment),c].Visible = true;
CommentName[Convert.ToInt32(Comment), c].Visible = true;
CommentDate[Convert.ToInt32(Comment), c].Visible = true;
if (c == 0)
{
c = 1;
NumOfComments[Convert.ToInt32(Comment)].Text = c + " Comment";
c = 0;
}
else if (c == 1)
{
c = 2;
NumOfComments[Convert.ToInt32(Comment)].Text = c + " Comments";
c = 1;
}
else
{
c = c + 1;
NumOfComments[Convert.ToInt32(Comment)].Text = c + " Comments";
c = c - 1;
}
if(c == 9)
{
ViewMoreComments[Convert.ToInt32(Comment)].Visible = true;
}
else
{
ViewMoreComments[Convert.ToInt32(Comment)].Visible = false;
}
}
else
{
UserComments[Convert.ToInt32(Comment), c].Visible = false;
CommentImage[Convert.ToInt32(Comment),c].Visible = false;
CommentName[Convert.ToInt32(Comment), c].Visible = false;
CommentDate[Convert.ToInt32(Comment), c].Visible = false;
}
}
}
catch
{
connection.Close();
return;
}
connection.Close();
}