473,512 Members | 14,457 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 #1
12 65611
shweta123
692 Recognized Expert Contributor
Hi,

Can you please refer this

Link
Jul 14 '07 #2
singh79
16 New Member
Hi,

Can you please refer this

Link

I know how to update with HTML, But I want in C# How To Update

protected void PriceEp_RowUpdating(object sender, GridViewUpdateEventArgs e)
{

}
How to Update with The Help Of Csharp.Pls Any one Give Me Proper Solutions.


Regards
atul singh
Jul 16 '07 #3
thaj
3 New Member
Dear Sir.


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


Regards
atul singh

in gridview property go to Events there doublic click of RowUpdating Event which will automaticall redirect into code behind...Inside the RowUpdating event u can code for updation

ex:
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating

int i ;
i = e.RowIndex;

so i contain rowindex now u can update appropriate row according to u r Stored Procedure
Jul 16 '07 #4
srilakshmim
22 New Member
I know how to update with HTML, But I want in C# How To Update

protected void PriceEp_RowUpdating(object sender, GridViewUpdateEventArgs e)
{

}
How to Update with The Help Of Csharp.Pls Any one Give Me Proper Solutions.


Regards
atul singh
Hi
In the rowupdating event
you write like this

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox txtName = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtName");



TextBox txtCity = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtCity");

//Your updation query pass the values like set city=' "+txtCity.Text+" '

GridView1.EditIndex = -1; //converts to normal mode from edit mode
// If having any bind method call here to see the updated rows

BindData();//(in this method write binding datasource to GridView1)


}
Thanks & Regards
Srilaskhmi.Mopidevi
Jul 16 '07 #5
singh79
16 New Member
I am written This Code Pls tell Me where Is problem...
Pls Give me Full Code...

pls help me
protected void PriceEp_RowUpdating(object sender, GridViewUpdateEventArgs e)
{

TextBox t1 = (TextBox)PriceEp.Rows[e.RowIndex].FindControl("t1");
PriceEp.EditIndex = -1;
string str = "Update EpTrans set EpCharge='"+t1.Text+"'";
EPCharge();
}

Regards
atul singh
Jul 17 '07 #6
shweta123
692 Recognized Expert Contributor
Hi,

Can you Please refer this Link
Jul 17 '07 #7
cmrhema
375 Contributor
Hi
In the rowupdating event
you write like this

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox txtName = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtName");



TextBox txtCity = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtCity");

//Your updation query pass the values like set city=' "+txtCity.Text+" '

GridView1.EditIndex = -1; //converts to normal mode from edit mode
// If having any bind method call here to see the updated rows

BindData();//(in this method write binding datasource to GridView1)


}
Thanks & Regards
Srilaskhmi.Mopidevi
Thank you very much SriLakshmi
Infact i had posted a query regarding the same a few backs ago.
i went through for loop and if loop and did all things which were of total failure
i came across this right now.
My problems solved.
The code which you provided roughly a fortnight has done wonders for me.
Thanks a bunch to you and the scripts.com
Regards
Hema
Aug 6 '07 #8
Brianbk
1 New Member
Dear Sir.


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


Regards
atul singh
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''
reply From Brianbk
Briankorobele@webmail.co.za
The code it update Datagridview
believe me was running try this one

Dim constr As String = "Data Source=localhost;Integrated Security=True"
Dim sqlstr As String = "select * from Customers"
Dim dt As New DataTable()
Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
'Display the Table with data in the gridview
'clear the current content of the Table
dt.Clear()
'fill the datatable with data in the Database
Dim dpt As New SqlDataAdapter(sqlstr, constr)
dpt.Fill(dt)
dpt.Dispose()
'display the Table in the datagrid
datagridview1.DataSource =dt
End Sub

End Class
Aug 18 '07 #9
britzer01
4 New Member
Hi
In the rowupdating event
you write like this

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox txtName = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtName");



TextBox txtCity = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtCity");

//Your updation query pass the values like set city=' "+txtCity.Text+" '

GridView1.EditIndex = -1; //converts to normal mode from edit mode
// If having any bind method call here to see the updated rows

BindData();//(in this method write binding datasource to GridView1)


}
Thanks & Regards
Srilaskhmi.Mopidevi

Good day... i have a problem with this code which i used it before and it really works. But when i used it again this code it returns the old value... but i dont know why?

In the gridview i set the column for example City column into a template and set the name to txtCity. Then i add the in edit column GridView1.EditIndex = -1; and bind it again.

Now the code of GridView rowupdating events is:

TextBox txtCity = (TextBox)GridView1.(TextBox)GridView1.Rows[e.RowIndex].FindControl("txtCity");


and i assume that the txtCity.Text was the updated value but the old value returns. i dont know why it happen. i compared also my source code into the other which is working but there is no difference from it. Can you help me from this?
Aug 22 '07 #10
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 programmatically 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.findcontrol("txtcity");"

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_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int index = GridView1.EditIndex;
GridViewRow row = GridView1.Rows[index];
string nametxt = GridView1.DataKeys[e.RowIndex].Value.ToString(); //row.Cells[2].Text; //GridView1.Rows[e.RowIndex].Cells[2].Text;
TextBox txtmyname = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtmyname"); //((TextBox)row.FindControl("txtmyname")).Text;
string txtbname = ((TextBox)row.FindControl("txtbname")).Text;
string txtmobile = ((TextBox)row.FindControl("txtmobile")).Text;
string txtemail = ((TextBox)row.FindControl("txtemail")).Text;
con.Open();
cmd = new OleDbCommand("update reg_table set myname='" + txtmyname.Text + "',bname = '" + txtbname + "',mobile = '" + txtmobile + "', email = '" + txtemail + "' where myname='" + nametxt + "' ", con);
int i = cmd.ExecuteNonQuery();
if (i > 0)
Response.Write("<h3> updated successfully");
else
Response.Write("<h3> Not updated");
con.Close();
//ds = (DataSet)Session["ds1"];
//ds.Tables["reg_table"].Rows[e.RowIndex]["myname"] = txtmyname;
}

please help me.

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

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

Similar topics

3
7197
by: Guru | last post by:
How do I refresh GridView using CallBack? I am populating the grid at runtime using OLEDB.
1
3258
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...
6
4096
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...
1
7194
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
5344
by: gopim | last post by:
gridview inside another gridview using Asp.net C#
0
2615
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
900
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...
0
1208
by: panindra | last post by:
HI how can i update particular item of an itemrenderer of a list in flex dynamically?
1
2562
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)...
0
7254
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
7153
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...
1
7094
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
7519
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...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4743
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...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1585
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 ...
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.