Hello,
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....
my front end code:
GridLines="None" AllowPaging="True" OnPageIndexChanging="DetailsView1_PageIndexChanging1">
my back end code:
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 + " of " + btn_no + "";
}
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();
}
Please.....
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Vivek KumarPosted Apr 2, 2017, 8:53 AM