GridView Updating

M

Mike P

I want to update my gridview, but rather than specifying the Update
Parameters etc in the GridView, I want to use my own code similar to the
way I updated the DataGrid v1.1. I also want to make a call to a
seperate data class to do this.

Here is my code :

protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{

if (e.CommandName == "Update")
{
// 1)Convert the row index stored in the CommandArgument
property to an Integer
int index = Convert.ToInt32(e.CommandArgument);

// Retrieve the row that contains the button clicked by the
user from the Rows collection
GridViewRow row = GridView1.Rows[index];

//get datakeys
int intID =
(int)GridView1.DataKeys[row.DataItemIndex].Value;

//get all other fields to be updated
DropDownList ddl1 = new DropDownList();
ddl1 =
(DropDownList)GridView1.Rows[index].FindControl("ddlTeamType");
int intTeamKey = Convert.ToInt32(ddl1.SelectedValue);

DropDownList ddl3 = new DropDownList();
ddl3 =
(DropDownList)GridView1.Rows[index].FindControl("ddlTerritoryCode");
int intTerritoryCode = Convert.ToInt32(ddl3.SelectedValue);

TextBox txt1 = new TextBox();
txt1 =
(TextBox)GridView1.Rows[index].FindControl("txtUserName");
string strUserName = Convert.ToString(txt1.Text);

TextBox txt2 = new TextBox();
txt2 =
(TextBox)GridView1.Rows[index].FindControl("txtUserLogin");
string strUserLogin = Convert.ToString(txt2.Text);

TextBox txt3 = new TextBox();
txt3 =
(TextBox)GridView1.Rows[index].FindControl("txtPassword");
string strPassword = Convert.ToString(txt3.Text);

TextBox txt4 = new TextBox();
txt4 =
(TextBox)GridView1.Rows[index].FindControl("txtEmail");
string strEmail = Convert.ToString(txt4.Text);

DropDownList ddl4 = new DropDownList();
ddl4 =
(DropDownList)GridView1.Rows[index].FindControl("ddlRegion");
string strRegion = Convert.ToString(ddl4.SelectedValue);

DropDownList ddl5 = new DropDownList();
ddl5 =
(DropDownList)GridView1.Rows[index].FindControl("ddlBusinessUnit");
string strBusinessUnit =
Convert.ToString(ddl5.SelectedValue);

//update userlogin table
DataAccess da = new DataAccess();

DBResult dbrUpdateUser =
(Xerox.DBResult)da.UpdateUserList(intID,
intTeamKey,
intTerritoryCode,
strUserName,
strUserLogin,
strPassword,
strEmail,
strRegion,
strBusinessUnit);

GridView1.EditIndex = -1;

//refresh gridview
GridView1.DataBind();
}

What do I need to change in the grdiview for this code to work, or do I
need to change my code?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top