473,842 Members | 1,835 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How To Update Particular Row In GridView Using C#

16 New Member
Dear Sir.


Pls Give Me any One Ans how to update particular Row in GridView using C#


Regards
atul singh
Jul 14 '07
12 65677
Strika Amaru
19 New Member
Related to this problem, but much worse:

I have a GridView, which isn't bound in the ways mentioned above; I need to use a custom data source, and create the data grid cells programmaticall y from it. So far so good; output works without a glitch.

But within the RowUpdate event handler, everything goes null. A Row[ i].Cells[ j] prints nothing, event.OldValues and NewValues both have length 0, and the TextBox approach described above gives a null reference after conversion.

Long story short, I'm out of ideas.

I've posted the ASP Code, and decided to skip the actual binding code, since it works great; checked it with the debugger.
Expand|Select|Wrap|Line Numbers
  1.       <asp:GridView
  2.          ID="grdContacts" runat="server" ForeColor="#111111" BackColor="#eeeeee"
  3.          AllowPaging="True" AllowSorting="True" PageSize="3" PageIndex="0"
  4.          OnPageIndexChanging="GridView_PageIndexChanging" 
  5.          OnPageIndexChanged ="GridView_PageIndexChanged"
  6.          OnRowEditing       ="GridView_RowEditing"
  7.          OnRowUpdated       ="GridView_RowUpdated"
  8.          OnRowUpdating      ="GridView_RowUpdating"
  9.          OnRowDeleted       ="GridView_RowDeleted"
  10.          OnRowDeleting      ="GridView_RowDeleting"
  11.          OnSorting          ="GridView_Sorting"
  12.          OnRowCancelingEdit ="GridView_RowCancelingEdit"
  13.          OnRowCommand       ="GridView_RowCommand">
  14.          <emptydatarowstyle backcolor="Silver" forecolor="Red"/>                    
  15.             <emptydatatemplate>
  16.             No Data Found.
  17.             </emptydatatemplate>
  18.          <Columns>
  19.              <asp:CommandField ShowInsertButton="true" ShowDeleteButton="True" ShowSelectButton="True" ShowEditButton="True" />
  20.          </Columns>
  21.       </asp:GridView>
Aug 22 '07 #11
Strika Amaru
19 New Member
It won't let me edit, so I made a new post.

I bugged some acquaintances and I managed to nail it. The code below works for my grid, and the commented code doesn't (prints nothing)

Expand|Select|Wrap|Line Numbers
  1. // all these 3 values are 0; despite what MSDN says, OldValues and NewValues
  2. // hold only air when the grid isn't bound to a standard (for them!) data
  3. // source, in a standard way.
  4.          //Response.Write(String.Format(
  5.          //   @"Updating: <br>
  6.          //   OldValues.Count = {0}<br>
  7.          //   NewValues.Count = {1}<br>
  8.          //   Keys.Count = {2} <br>"
  9.          //   , e.OldValues.Count, e.NewValues.Count, e.Keys.Count));
  10.  
Expand|Select|Wrap|Line Numbers
  1. // in my code, j=0 would try to read the CommandField; instant death.
  2.          for (int j = 1; j < grdContacts.Rows[e.RowIndex].Cells.Count; j++)
  3.          {
  4.             //Response.Write(String.Format(" From cells:: {0} /// ", grdContacts.Rows[ e.RowIndex].Cells[j].Text)); // <- shows ""
  5.             TextBox textB = (TextBox)(grdContacts.Rows[e.RowIndex].Cells[j].Controls[0]);
  6.             Response.Write(String.Format(" {0}, {1}:: {2} <br>", e.RowIndex, j, textB.Text)); // <- shows modified values.
  7.          }
  8.  
Sorry for the wrapping in the second snippet, I just don't think there's a way to make it more eye-friendly, even if I'd raze the leading spaces.

EDIT: I made a little mistake in the previous post: the event handler is RowUpdating; RowUpdated won't trigger for the life of me.
Aug 22 '07 #12
Singamalai
1 New Member
@srilakshmim

<from singamalai>
Hello madam, my name is singamalai.
in the above code in "TextBox txtcity = (textbox)row.fi ndcontrol("txtc ity");"

i'm getting the default value which is not updated, but not updated value. please help me to update a record.

this is my code.
protected void GridView1_RowUp dating(object sender, GridViewUpdateE ventArgs e)
{
int index = GridView1.EditI ndex;
GridViewRow row = GridView1.Rows[index];
string nametxt = GridView1.DataK eys[e.RowIndex].Value.ToString (); //row.Cells[2].Text; //GridView1.Rows[e.RowIndex].Cells[2].Text;
TextBox txtmyname = (TextBox)GridVi ew1.Rows[e.RowIndex].FindControl("t xtmyname"); //((TextBox)row.F indControl("txt myname")).Text;
string txtbname = ((TextBox)row.F indControl("txt bname")).Text;
string txtmobile = ((TextBox)row.F indControl("txt mobile")).Text;
string txtemail = ((TextBox)row.F indControl("txt email")).Text;
con.Open();
cmd = new OleDbCommand("u pdate reg_table set myname='" + txtmyname.Text + "',bname = '" + txtbname + "',mobile = '" + txtmobile + "', email = '" + txtemail + "' where myname='" + nametxt + "' ", con);
int i = cmd.ExecuteNonQ uery();
if (i > 0)
Response.Write( "<h3> updated successfully");
else
Response.Write( "<h3> Not updated");
con.Close();
//ds = (DataSet)Sessio n["ds1"];
//ds.Tables["reg_table"].Rows[e.RowIndex]["myname"] = txtmyname;
}

please help me.

Thanks and regards,
singamalai.
simhamalai@indi a.com
Apr 12 '12 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

3
7215
by: Guru | last post by:
How do I refresh GridView using CallBack? I am populating the grid at runtime using OLEDB.
1
3281
by: =?Utf-8?B?SmF5Qw==?= | last post by:
I am trying to understand how to use an arraylist that contains data in a structure and bind the results to a gridview. Using vs2008 I have looked at the examples 315784 HOW TO: Bind a DataGrid Control to an Array of Objects or Structures by http://support.microsoft.com/?id=315784 316302 HOW TO: Bind a DataGrid Control to an ArrayList of Objects or Structures http://support.microsoft.com/?id=316302
6
4115
by: Garima12 | last post by:
There is a update panel,gridview and update progress. fetching the data from database and filling in gridview. at the time of processing update progress is working and showing processing........ My problem is : when once data is not found and i display in emptydatatext="no result" and again i search something, then updateprogreee shows processing...........as well as "no result" is displayed. I want to remove this "no result" as returned by...
1
7207
by: tina2626 | last post by:
how can i pass textbox value to gridview using C#.net at runtime not using database values. i m hving textbox1 and gridview1. can anyone suggest me to do this coding in ASP.NET(C# language).
1
5376
by: gopim | last post by:
gridview inside another gridview using Asp.net C#
0
2641
by: baburmm | last post by:
Hai, I want to get the footer textbox value in gridview using javascript any one help me Regards, Babu.K
0
912
by: bala venkata siva ram kum | last post by:
Hi friends, this is balu . I need to display values from sqldatabase to gridview.here in my database there are a lot of values.so i want to use gridview using cache.please tell me the code.
0
1223
by: panindra | last post by:
HI how can i update particular item of an itemrenderer of a list in flex dynamically?
1
2581
by: sakura | last post by:
Hi. I'm using asp.net and c# language. How can i display a GridView using select statement of two column in one table? This is my coding: if (sdr.Read()) { if(namaPembekal.Equals(sdr) && tarikhRo.Equals(sdr)) {
0
10940
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10670
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10308
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9451
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7030
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4499
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4087
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3141
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.