i am trying to use paging in detailsView control using a button means i am trying to change the content of detailsView control ( means if it first time showing one row the on click next button it has to show next row of data base but it's not working)
please guide me....
<asp:DetailsView ID="DetailsView1" CssClass="DetailsView1" runat="server" CellPadding="6" ForeColor="#333333" AutoGenerateRows="false"
GridLines="None" AllowPaging="True" OnPageIndexChanging="DetailsView1_PageIndexChanging1">
<Fields>
<asp:TemplateField>
<ItemTemplate>
<table id="Question_view_table">
<tr>
<td style="height:20px"></td>
</tr>
<tr>
<td style="font-family:'Times New Roman'; font-size:18px; ">
<label id="Question_detail"><%# Eval ("Question") %></label>
</td>
</tr>
<tr>
<td style="font-family:'Times New Roman'; font-size:18px;">
<ol style="list-style:upper-alpha">
<li>
<label id="optn1">   <%# Eval ("Option1") %></label></li>
<li>
<label id="optn2">   <%# Eval ("Option2") %></label></li>
<li>
<label id="optn3">   <%# Eval ("Option3") %></label></li>
<li>
<label id="optn4">   <%# Eval ("Option4") %></label></li>
</ol>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
private int btn_no, question_id = 1;
protected void Page_Load(object sender, EventArgs e)
{
if (!SM1.IsInAsyncPostBack)
{
Session["timeout"] = DateTime.Now.AddSeconds(20000).ToString();
getQuestion();
Button[] BtnArray = new Button[btn_no];
string strimgpath = "image/not_attempt.png";
String strImgLocation = "url('" + strimgpath + "')";
for (int i = 0; i < btn_no; i++)
{
BtnArray[i] = new Button();
BtnArray[i].Width = 30;
BtnArray[i].Height = 30;
BtnArray[i].Text = Convert.ToString(i + 1);
BtnArray[i].Style.Add("margin", "5px");
BtnArray[i].Style.Add("outline", "0px");
BtnArray[i].Style.Add("background-image", strImgLocation);
BtnArray[i].Style.Add("background-repeat", "no-repeat");
BtnArray[i].Style.Add("background-size", "contain");
BtnArray[i].Style.Add("background-color", "transparent");
BtnArray[i].Style.Add("border", "none");
btn_matrix.Controls.Add(BtnArray[i]);
}
}
}
protected void getQuestion()
{
string constr = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
con.Open();
string SelectQuestion_String = "Select * from Questions where ExamName = 'Demo'";
SqlCommand com = new SqlCommand(SelectQuestion_String, con);
SqlDataAdapter da = new SqlDataAdapter(com);
DataTable dt = new DataTable();
da.Fill(dt);
btn_no = Convert.ToInt32(dt.Rows.Count.ToString());
DetailsView1.DataSource = dt;
DetailsView1.DataBind();
Ques_No_label.Text = "Question" + " : " + question_id + " <span style='font-size:15px'>of " + btn_no + "</span>";
}
protected void button_save_next_Click(object sender, ImageClickEventArgs e)
{
DetailsView1_PageIndexChanging1(sender, args);
getQuestion();
}
public DetailsViewPageEventArgs args { get; set; }
protected void DetailsView1_PageIndexChanging1(object sender, DetailsViewPageEventArgs args)
{
DetailsView1.PageIndex = args.NewPageIndex;
getQuestion();
}