AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 How can take one by one row record from ListView
Posted by Asha Bhatt on  1/28/2010 6:06:22 AM Category: Asp.Net 2.0
Add to my favorites
Email to friend
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(scon);
da = new SqlDataAdapter("select Question,Option1,Option2,Option3,Option4 from QuestionData", con);
ds = new DataSet();
da.Fill(ds);
ListView1.Visible = true;
for (int i = 1; i < ListView1.Items.Count; i++)
{
if (ListView1.DataKeys[1].ToString().Trim() == ListView1.Items[1].ToString().Trim())
{
ListView1.SelectedIndex = i;

Response.Write(ListView1.Items[i]);

// return;
}
}
}

this is .aspx.cs page
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource2"
EnableModelValidation="True" ondatabound="ListView1_DataBound"
onselectedindexchanged="ListView1_SelectedIndexChanged" Visible="False">
<ItemTemplate>
<span style="">Question:
<asp:Label ID="QuestionLabel" runat="server" Text='<%# Eval("Question") %>' />
<br />
Option1:
<asp:Label ID="Option1Label" runat="server" Text='<%# Eval("Option1") %>' />
<br />
Option2:
<asp:Label ID="Option2Label" runat="server" Text='<%# Eval("Option2") %>' />
<br />
Option3:
<asp:Label ID="Option3Label" runat="server" Text='<%# Eval("Option3") %>' />
<br />
Option4:
<asp:Label ID="Option4Label" runat="server" Text='<%# Eval("Option4") %>' />
<br />
<br />
</span>
</ItemTemplate>
<AlternatingItemTemplate>
<span style="">Question:
<asp:Label ID="QuestionLabel" runat="server" Text='<%# Eval("Question") %>' />
<br />
Option1:
<asp:Label ID="Option1Label" runat="server" Text='<%# Eval("Option1") %>' />
<br />
Option2:
<asp:Label ID="Option2Label" runat="server" Text='<%# Eval("Option2") %>' />
<br />
Option3:
<asp:Label ID="Option3Label" runat="server" Text='<%# Eval("Option3") %>' />
<br />
Option4:
<asp:Label ID="Option4Label" runat="server" Text='<%# Eval("Option4") %>' />
<br />
<br />
</span>
</AlternatingItemTemplate>
<EmptyDataTemplate>
<span>No data was returned.</span>
</EmptyDataTemplate>
<InsertItemTemplate>
<span style="">Question:
<asp:TextBox ID="QuestionTextBox" runat="server"
Text='<%# Bind("Question") %>' />
<br />
Option1:
<asp:TextBox ID="Option1TextBox" runat="server" Text='<%# Bind("Option1") %>' />
<br />
Option2:
<asp:TextBox ID="Option2TextBox" runat="server" Text='<%# Bind("Option2") %>' />
<br />
Option3:
<asp:TextBox ID="Option3TextBox" runat="server" Text='<%# Bind("Option3") %>' />
<br />
Option4:
<asp:TextBox ID="Option4TextBox" runat="server" Text='<%# Bind("Option4") %>' />
<br />
<asp:Button ID="InsertButton" runat="server" CommandName="Insert"
Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Clear" />
<br />
<br />
</span>
</InsertItemTemplate>
<LayoutTemplate>
<div ID="itemPlaceholderContainer" runat="server" style="">
<span style="" >
Question: <span ID="itemPlaceholder" runat="server"></span></span>
</div>
<div style="">
<asp:DataPager ID="DataPager1" runat="server"
OnDataBinding="NextQusButton_Click">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</div>
</LayoutTemplate>
<EditItemTemplate>
<span style="">Question:
<asp:TextBox ID="QuestionTextBox" runat="server"
Text='<%# Bind("Question") %>' />
<br />
Option1:
<asp:TextBox ID="Option1TextBox" runat="server" Text='<%# Bind("Option1") %>' />
<br />
Option2:
<asp:TextBox ID="Option2TextBox" runat="server" Text='<%# Bind("Option2") %>' />
<br />
Option3:
<asp:TextBox ID="Option3TextBox" runat="server" Text='<%# Bind("Option3") %>' />
<br />
Option4:
<asp:TextBox ID="Option4TextBox" runat="server" Text='<%# Bind("Option4") %>' />
<br />
<asp:Button ID="UpdateButton" runat="server" CommandName="Update"
Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Cancel" />
<br />
<br />
</span>
</EditItemTemplate>
<SelectedItemTemplate>
<asp:Label ID="QuestionLabel" runat="server" Text='<%# Eval("Question") %>'></asp:Label>
<br />
Option1:
<asp:Label ID="Option1Label" runat="server" Text='<%# Eval("Option1") %>'></asp:Label>
<br />
Option2:
<asp:Label ID="Option2Label" runat="server" Text='<%# Eval("Option2") %>'></asp:Label>
<br />
Option3:
<asp:Label ID="Option3Label" runat="server" Text='<%# Eval("Option3") %>'></asp:Label>
<br />
Option4:
<asp:Label ID="Option4Label" runat="server" Text='<%# Eval("Option4") %>'></asp:Label>
<br />
<br />
</SelectedItemTemplate>
</asp:ListView>

one page load event i want to show only frist row,and after click on next button 2nd row display like that so on ...............
Please tell me how can i do that.

Post Your Reply Post New Question

 Viewer's Reply
ListView: Showing One Record at a Time
Answered By Moderator1 on 1/29/2010 8:20:47 PM
Hi,

In the ListView, you show 1 question at a time, and you have placed a button "Next" at the page level. When page loads, you show question no. 1, use ViewState or Session to store the question sequence number(QSO). When User Clicks the next button, increase the QSO by 1, and re-load the page with next question and save the new QSO into your ViewState or Session. Thus you can move question by question.

No one can provide you complete code, but logic can. If you have any issues related this, post here below this answers.
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
When Good HTML Goes Bad: How You Can Protect Your Web Applications
The PHP Anthology: 101 Essential Tips, Tricks & Hacks, 2nd Edition - Free 207 Page Preview!
No Nonsense XML Web Development With PHP - Free 146 Page Preview!