473,396 Members | 1,996 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,396 software developers and data experts.

DataGrid UpdateCommand

I am trying to update data directly in a datagrid using
the UpdateCommand. However when I click the update button
in my datagrid nothing seems to happen. I keep going
round in circles and can't seem to work out whats wrong.
I've included the html code and the info from the code
behind page. Could someone please please help me work out
where i;ve went wrong.

HTML
<asp:datagrid id="DataGrid2" style="Z-INDEX: 101; LEFT:
12px; POSITION: absolute; TOP: 239px" runat="server"
CellPadding="3" BackColor="White" BorderWidth="1px"
BorderStyle="None" BorderColor="#CCCCCC" Width="653px"
AutoGenerateColumns="False" Font-Bold="True"
AllowSorting="True" DataKeyField="BANK_ID">
<Columns>
<asp:BoundColumn DataField="BANK_ID"
SortExpression="PER_LNAME" HeaderText="BankID"
ReadOnly="True">
</asp:BoundColumn>
<asp:BoundColumn DataField="PER_FNAME"
SortExpression="PER_LNAME" HeaderText="First Name"
ReadOnly="True">
</asp:BoundColumn>
<asp:BoundColumn DataField="PER_LNAME"
SortExpression="PER_LNAME" HeaderText="Surname"
ReadOnly="True">
</asp:BoundColumn>
<asp:BoundColumn DataField="PER_NIN"
SortExpression="PER_LNAME" HeaderText="NI Number">
</asp:BoundColumn>
<asp:BoundColumn DataField="BANK_TNAME"
SortExpression="PER_LNAME" HeaderText="Trading Name">
</asp:BoundColumn>
<asp:BoundColumn DataField="BANK_CDATE"
SortExpression="PER_LNAME" HeaderText="Ceased Trading">
</asp:BoundColumn>
<asp:EditCommandColumn ButtonType="LinkButton"
UpdateText="Update" HeaderText="Edit" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete" HeaderText="Delete"
CommandName="Delete"></asp:ButtonColumn>
</Columns>
</asp:datagrid>

CODE-BEHIND PAGE
private void DataGrid2_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string InBankkey = DataGrid2.DataKey
[e.Item.ItemIndex].ToString();
string TradeNames= " ";
TextBox TradeName = null;
TradeName = (TextBox)e.Item.Cells[4].Controls[0];
TradeNames = TradeName.Text.Trim();

string sqlUpdate = string.Format( "Update BANK set
BANK_TNAME='{0}' Where BANK_ID =
{1}",TradeNames,InBankkey);

SqlConnection conn = new SqlConnection("data
source=IRERESM12; initial catalog=TestDB; user
id=sa;password=rugby");
conn.Open();

SqlCommand s = new SqlCommand (sqlUpdate,conn);
s.ExecuteNonQuery ();

conn.Close();

DataGrid2.EditItemIndex = -1;
DisplayRes();
}

//Page Load and DisplayRes Below
private void Page_Load(object sender, System.EventArgs e)
{
DisplayRes();
}
private void DisplayRes()
{
SqlConnection conn = new SqlConnection("data
source=IRERESM12; " +
"initial catalog=TestDB; " +
"user id=sa; " +
"password=rugby");

DataSet ds = new DataSet();

SqlParameter @PER_LNAME = new SqlParameter
("@PER_LNAME", System.Data.SqlDbType.Char);
@PER_LNAME.Direction = ParameterDirection.Input;
@PER_LNAME.Value = Request.QueryString ["SN"];
SqlParameter @PER_FNAME = new SqlParameter
("@PER_FNAME", System.Data.SqlDbType.Char);
@PER_FNAME.Direction = ParameterDirection.Input;
@PER_FNAME.Value = Request.QueryString["FN"];
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand();
da.SelectCommand.Connection = conn;
da.SelectCommand.CommandText = "BankSearch2";
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.Add(@PER_LNAME);
da.SelectCommand.Parameters.Add(@PER_FNAME);
ds = new DataSet();

da.Fill(ds, "BANK");

DataGrid2.DataSource = ds;
DataGrid2.DataMember = "BANK";
DataGrid2.DataBind();
}
Nov 16 '05 #1
0 2721

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

Similar topics

3
by: Fortra | last post by:
I'm having trouble with the UpdateCommand event with the DataGrid control. The event is wired up in the InitializeComponents properly, this.sitesDataGrid.UpdateCommand += new...
1
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls...
0
by: Ozer | last post by:
Hi guys, I need some help. In my datagrid's updatecommand event i'm trying to get textboxes values and also do it. But when i update the values in textboxes and fire the event, I can't get the...
1
by: MrMike | last post by:
Hi. My application has dozens of datagrids but for some reason an exception occurs when one of them is updated. When a user edits a datagrid row and then clicks 'Update' the following exception...
4
by: siaj | last post by:
Hello All, If some one has faced a similar issue.. My datagrid Update command is not getting fired in fact it seems that the no event fires on clicking the update link. Although the cancel and the...
1
by: niki | last post by:
Hello. I have a problem with custom columns inside the datagrid. I've set up a datagrid that populates from a database; I can edit the datagrid values and update the db, so that's ok. (btw, it's...
2
by: Derek Vincent | last post by:
What must I do to overcome a problem with my dates becoming formatted as "2/22/2525 12:00:00 AM" in the datagrid? I want to handle all dates as short string of format "2/22/2525." Otherwise when I...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
0
by: arlie_maija | last post by:
Hey - I'm writing a control that contains a DataGrid, and I'm unable to get the update event to fire. When I click the update link, the edit event fires. heres the details... my control...
2
by: pozze | last post by:
Hi, I need to display images and other record information retrieved from an SQL 2005 database in a datagrid on a web page. I'm coding in VB .net I have recently changed over from VB ASP and i'm...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.