Tuesday, 13 May 2014

Gridview using WebService

using System.ServiceModel;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
    BLL b = new BLL();
    PROperty _Pro = new PROperty();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            viewdata();
        }
    }
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Edit")
        {
            int index = Convert.ToInt32(e.CommandArgument);
            Session["UserId"] = GridView1.DataKeys[index].Value.ToString();
            txtuser.Text = GridView1.Rows[index].Cells[0].Text.Trim();
            //txtpwd.Text = GridView1.Rows[index].Cells[2].Text.Trim();
            txtfname.Text = GridView1.Rows[index].Cells[2].Text.Trim();
            txtlname.Text = GridView1.Rows[index].Cells[3].Text.Trim();
            txtphone.Text = GridView1.Rows[index].Cells[4].Text.Trim();
            txtlocation.Text = GridView1.Rows[index].Cells[5].Text.Trim();

            btnsubmit.Text = "Update";
        }

        else if (e.CommandName == "Delete")
        {
            int index = Convert.ToInt32(e.CommandArgument);
            Session["UserId"] = GridView1.DataKeys[index].Value.ToString();
           // b.delete(Convert.ToInt32(Session["UserId"]));
            localhost.Service s = new localhost.Service();
            s.delete(Convert.ToInt32(Session["UserId"]));
            viewdata();
            clear();
        }
    }

protected void btnsubmit_Click(object sender, EventArgs e)
    {
        if (btnsubmit.Text == "Save")
        {
            _Pro.un = txtuser.Text;
            _Pro.pwd = txtpwd.Text;
            _Pro.fn = txtfname.Text;
            _Pro.ln = txtlname.Text;
            _Pro.mobno = txtphone.Text;
            _Pro.city = txtlocation.Text;
            localhost.Service s = new localhost.Service();
            s.insert(txtuser.Text, txtpwd.Text, txtfname.Text, txtlname.Text, txtphone.Text, txtlocation.Text);
         
           // b.insert(_Pro);
            Response.Write("The Record has been created");
            clear();

           
           
        }

        else
        {
            _Pro.uid = Convert.ToInt32(Session["UserId"]);
            _Pro.un = txtuser.Text;
            _Pro.pwd = txtpwd.Text;
            _Pro.fn = txtfname.Text;
            _Pro.ln = txtlname.Text;
            _Pro.mobno = txtphone.Text;
            _Pro.city = txtlocation.Text;
            //b.update(_Pro);
            localhost.Service s = new localhost.Service();
            s.update(Convert.ToInt32(Session["UserId"]), txtuser.Text, txtpwd.Text, txtfname.Text, txtlname.Text, txtphone.Text, txtlocation.Text);
            Response.Write("The Record has been Updated");
            clear();

        }
        viewdata();
    }

    public DataSet viewdata()
    {
        DataSet ds = new DataSet();
        ds = b.viewdata();
        GridView1.DataSource = ds;
        GridView1.DataBind();
        return ds;
        clear();
    }

    public void clear()
    {
        txtuser.Text = string.Empty;
        txtpwd.Text = string.Empty;
        txtphone.Text = string.Empty;
        txtlocation.Text = string.Empty;
        txtlname.Text = string.Empty;
        txtfname.Text = string.Empty;

    }

}

No comments:

Post a Comment