473,378 Members | 1,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

GridView Updating

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?

*** Sent via Developersdex http://www.developersdex.com ***
May 23 '06 #1
0 841

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: P | last post by:
Hello, I am having a difficult time updating a record via a stored procedure using the gridview and sqldatasource. I cannot seem to be able to find a way to set everything up so that I can pass...
3
by: | last post by:
Hello, I have created an ASP.NET 2.0 application that utilized a Gridview Control to display and update/delete data. The problem I am having is that the gridview control is displaying the data...
8
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my...
5
by: Brian McClellan | last post by:
Just wondering if anyone has a simple example of creating a gridview completely programmatically, i'm not doing anything terribly sophisticated. When creating the gridview declaratively evertying...
0
by: Michael Kellogg | last post by:
I have a problem wherein a query that updates a GridView doesn't seem to really stay in sync with a label I have above the GridView. I have a GridView object that I'm updating with information...
1
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
Hi, I have a gridview which I added a <asp:CommandField EditText="E" CancelText="C" UpdateText="U" ButtonType="Link" ShowEditButton="True" /> my gridview looks like this <asp:GridView...
11
by: SAL | last post by:
Hello, I have a Gridview control (.net 2.0) that I'm having trouble getting the Update button to fire any kind of event or preforming the update. The datatable is based on a join so I don't know...
0
by: steve | last post by:
I have been fighting with trying to update a GridView for a while. I don't want to use the "built-in" way to do it because I am using business layer methods for updating and deleteing and I don't...
0
by: BizWeb | last post by:
Hi, i am new to ASP.NET. I have write a very simple code to try the updating of the GridView but it is not updating the data. Below is the simple code that i have use. <%@ Page Language="vb"...
2
by: xMetalDetectorx | last post by:
Hi Everyone, I have a very simple web app that uses .Net 2.0 login control to authenticate users and allow access to an "admin" folder. Inside that admin folder I have one page that has a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.