using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void DataList1_CancelCommand(object source, DataListCommandEventArgs e)
    {
        DataList1.EditItemIndex = -1;
        DataList1.DataBind();
    }
    protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e)
    {
        int id = (int)DataList1.DataKeys[e.Item.ItemIndex];
        SqlDataSource1.DeleteParameters["stno"].DefaultValue = System.Convert.ToString(id);
        SqlDataSource1.Delete();

    }
    protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataList1.DataBind();

    }
    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        DataList1.SelectedIndex = -1;
        DataList1.DataBind();

    }
    protected void DataList1_EditCommand(object source, DataListCommandEventArgs e)
    {
        DataList1.EditItemIndex = e.Item.ItemIndex;
        DataList1.DataBind();

    }
    protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
    {
        int stno = (int)DataList1.DataKeys[e.Item.ItemIndex];
        String fname = ((TextBox)e.Item.FindControl("textfname")).Text;
        String lname = ((TextBox)e.Item.FindControl("textlname")).Text;
        float average = System.Convert.ToSingle(((TextBox)e.Item.FindControl("textaverage")).Text);
        bool sex = System.Convert.ToBoolean(((CheckBox)e.Item.FindControl("checkedsex")).Checked);
        String course = ((TextBox)e.Item.FindControl("textcourse")).Text;
        SqlDataSource1.UpdateParameters["stno"].DefaultValue = System.Convert.ToString(stno);
        SqlDataSource1.UpdateParameters["fname"].DefaultValue = fname;
        SqlDataSource1.UpdateParameters["lname"].DefaultValue = lname;
        SqlDataSource1.UpdateParameters["average"].DefaultValue = System.Convert.ToString(average);
        SqlDataSource1.UpdateParameters["sex"].DefaultValue = System.Convert.ToString(sex);
        SqlDataSource1.UpdateParameters["course"].DefaultValue = course;
        SqlDataSource1.Update();
        DataList1.EditItemIndex = -1;
        DataList1.DataBind();

    }
}
