user2326715
user2326715

Reputation: 1

Asp.net listview does not display data correctly

My problem is that when i display data in listview for first time then it show correctly but when i display data second time then listview does not update the data correctly. I have made a function for databinding with listview which i have called in pageLoad and some other method. Can anyone please give me a solution about this ?

I have also uploaded my source code for more detail.

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        LoadDataIntoListView();
    }
}

protected void LoadDataIntoListView()
{
    Users objQuery = new Users();
    string adminID = "Here is my query to get the data from MS-SQL";
    objQuery.ExecuteSql(str);
    if (objQuery.RowCount > 0)
    {
        Title = "Row affected";
        lstAppointments.Items.Clear();
        lstAppointments.DataSource = objQuery.DefaultView;
        lstAppointments.DataBind();
    }
    else
    {
        Title = "None Row affected";
    }
}

protected void btnDelete_Click(object sender, EventArgs e)
{
    string caseID = (string)Session["caseID"];
    //string updateQuery = "update Cases set sCaseStatus='cancel' where iCaseID= '" + caseID + "'";
    Cases objCases = new Cases();
    objCases.LoadByPrimaryKey(Convert.ToInt32(caseID));
    if (String.Equals(objCases.SCaseStatus, "cancel"))
    {
        Page.Title = "No Update";
        ModalPopupExtender1.Hide();
    }
    else
    {
        objCases.SCaseStatus = "cancel";
        objCases.Save();
        Page.Title = "No Update";

        ModalPopupExtender1.Hide();
        lstAppointments.Items.Clear();
        LoadDataIntoListView();
    }
}

Thanks in advance.

Upvotes: 0

Views: 608

Answers (1)

Veer
Veer

Reputation: 1593

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        LoadDataIntoListView();
    }
}

You are binding data in not Postback. That means it does not binds data when you postback to same page. If you want to bind that on every page load, call the function LoadDataIntoListView() in Page_Load

Upvotes: 1

Related Questions