TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
43
62.7k
Retrieve Next Record from db in WebApplications
Nov 25 2010 6:47 AM
my Query is i want to retrieve next record from db in web application using sessions or viewstate .when am click on next button always that shows first record.
am sending code please check it once.
Default.aspx Page
:-
<asp:Label ID="lblUserId" runat="server" ></asp:Label><br />
<asp:Button ID="btnShowData" runat="server" Text="Show Data"
onclick="btnShowData_Click" />             
<asp:Button ID="btnNext" runat="server" Text="Next" onclick="btnNext_Click1" />
My Connection string from Web.config File:-
string conn = ConfigurationManager.ConnectionStrings["SqlConn1"].ToString();
In PageLoad:-
DataTable dt = getData();
lblUserId.Text = dt.Rows[0]["UserId"].ToString();
int count = 0;
Session["dt"] = dt;
Session["count"] = count;
Method:-
public DataTable getData()
{
SqlConnection con = new SqlConnection(conn);
con.Open();
SqlCommand cmd = new SqlCommand("Select * from registration", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
con.Close();
return dt;
}
Next ButtonClick:-
protected void btnNext_Click1(object sender, EventArgs e)
{
if (Session["dt"] != null)
{
DataTable dt = (DataTable)Session["dt"];
int count = (int)Session["count"];
count = count + 1;
lblUserId.Text = dt.Rows[count]["UserId"].ToString();
}
}
Reply
Answers (
3
)
retrieve selected row Gridview data and display on other page text boxes
How to send SMS in asp.net?