Hi everyone
I’m using the GridView in asp.net and populating the grid dynamically using c#.net.To edit the rows i i m using GridView1_RowUp dating(object sender, GridViewUpdateE ventArgs e).
Now if I run the application and click the “Edit” Button then the complete row is generating the textboxes to edit the data in that particular row and also the “Update” and “Cancel” buttons are generated.When I change the data in any of the textboxes in that row then how should I Update that data to the Database(Sql server) using stored procedure . and display the updated data in the grid.Plzzz provide the code for this and also Is the same thing applies to the delete button.Plzzzzz help..
i m sending my code plz tell me where is d error.. gridview.aspx - <asp:GridView ID="GridView1" AutoGenerateColumns="false" runat="server" OnRowEditing="GridView1_RowEditing"
-
OnRowUpdating="GridView1_RowUpdating" >
-
<Columns>
-
<asp:TemplateField HeaderText="userid">
-
<ItemTemplate>
-
<asp:Label runat="server" ID="uid" Text='<%# DataBinder.Eval(Container.DataItem,"uid") %>'/>
-
</ItemTemplate>
-
<EditItemTemplate>
-
<asp:TextBox runat="server" ID="Textuid" Text='<%# DataBinder.Eval(Container.DataItem,"uid") %>' EnableViewState="true" />
-
</EditItemTemplate>
-
-
</asp:TemplateField>
-
<asp:TemplateField HeaderText="password">
-
<ItemTemplate>
-
<asp:Label runat="server" ID="pwd" Text='<%# DataBinder.Eval(Container.DataItem,"pwd") %>' />
-
</ItemTemplate>
-
<EditItemTemplate>
-
<asp:TextBox runat="server" ID="txtpwd" Text='<%# DataBinder.Eval(Container.DataItem,"pwd") %>' EnableViewState="true"/>
-
</EditItemTemplate>
-
</asp:TemplateField>
-
<asp:TemplateField HeaderText="Action">
-
<ItemTemplate>
-
<asp:LinkButton ID="btnEdit" Text="Edit" runat="server" CommandName="Edit" />
-
<br />
-
<asp:LinkButton ID="btnDelete" Text="Delete" runat="server" CommandName="Delete" />
-
</ItemTemplate>
-
<EditItemTemplate>
-
<asp:LinkButton ID="btnUpdate" Text="Update" runat="server" CommandName="Update" />
-
<asp:LinkButton ID="btnCancel" Text="Cancel" runat="server" CommandName="Cancel" />
-
</EditItemTemplate>
-
</asp:TemplateField>
-
</Columns>
-
</asp:GridView>
stored procedure - Editdata
-
-
ALTER PROCEDURE [dbo].[EditData]
-
-
@name as varchar(50) ,
-
@password as varchar(20)
-
-
AS
-
BEGIN
-
-
SET NOCOUNT ON;
-
update [dbo].[Login] set [pwd]= @password where [uid]=@name
-
END
-
gridview.aspx.c s - public partial class gridview : System.Web.UI.Page
-
{
-
dbconn obj = new dbconn();
-
protected void Page_Load(object sender, EventArgs e)
-
{
-
-
bindGrid();
-
}
-
public static DataTable GetAllData()
-
{
-
DataTable alldata=new DataTable();
-
string dbcon = ConfigurationManager.AppSettings["connectioninfo"];
-
SqlConnection con = new SqlConnection(dbcon);
-
con.Open();
-
SqlCommand cmd = new SqlCommand("GetData",con);
-
cmd.CommandType = CommandType.StoredProcedure;
-
cmd.ExecuteNonQuery();
-
SqlDataAdapter da = new SqlDataAdapter(cmd);
-
da.Fill(alldata);
-
return alldata;
-
}
-
protected void bindGrid()
-
{
-
-
-
GridView1.DataSource = GetAllData();
-
GridView1.DataBind();
-
}
-
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
-
{
-
-
GridView1.EditIndex = e.NewEditIndex;
-
-
bindGrid();
-
-
}
-
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
-
-
{
-
TextBox uidtext = GridView1.Rows[e.RowIndex].FindControl("Textuid") as TextBox;
-
TextBox pwdtext = GridView1.Rows[e.RowIndex].FindControl("txtpwd") as TextBox;
-
string dbcon = ConfigurationManager.AppSettings["connectioninfo"];
-
-
SqlConnection con = new SqlConnection(dbcon);
-
con.Open();
-
SqlCommand cmd = new SqlCommand("EditData", con);
-
cmd.CommandType = CommandType.StoredProcedure;
-
cmd.Parameters.AddWithValue("@name", uidtext.Text);
-
cmd.Parameters.AddWithValue("@password", pwdtext.Text);
-
cmd.ExecuteNonQuery();
-
}
we.config - public class dbconn
-
{
-
-
public SqlConnection GetConnection()
-
{
-
SqlConnection con = default(SqlConnection);
-
string connectioninfo = ConfigurationManager.AppSettings["connectionstring"];
-
con = new SqlConnection(connectioninfo);
-
//if (con.State = ConnectionState.Closed)
-
// con.Open();
-
return con;
-
-
-
-
}
-
public DataSet ExecuteDataset(string sql)
-
{
-
SqlConnection conn = GetConnection();
-
if (conn.State== ConnectionState.Closed)
-
conn.Open();
-
DataSet ds=new DataSet();
-
-
SqlDataAdapter da = new SqlDataAdapter(sql,conn);
-
da.Fill(ds);
-
return (ds);
-
-
-
}
-
public void ExecuteCommand(string sql)
-
{
-
SqlConnection con = GetConnection();
-
if (con.State == ConnectionState.Closed)
-
con.Open();
-
SqlCommand cmd = new SqlCommand();
-
cmd.ExecuteNonQuery();
-
-
}
-
}
5 3677 tlhintoq 3,525
Recognized Expert Specialist TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out. tlhintoq 3,525
Recognized Expert Specialist
Please read the guidelines about posting a question. The use of SMS speak and unnecessary abbreviations just makes it hard to read your question. Personally when I see a bunch of this my thinking is "If it's not important enough for the poster to type the extra few characters to make a real word, then it must not be very important." But that's just me and I don't claim to have insight on how the other volunteers here think.
i m sending........ .. I am sending.
Plzzzzz........ Actually longer than "Please"
where is d error.......... .. Just makes you sound like a wannabe rapper
Frinavale 9,735
Recognized Expert Moderator Expert
Do not call the bindGrid() method in your page load without checking if it ispostback = false (the first time the page is loading).
Instead, move this method to the Page PreRender event.
What's happening is that you're binding the GridView to a "new" datasource every time the page posts back to the server.
When you bind the GridView to the new datasource when you're trying to Edit something, all of the values entered by the user (during editing) will be lost....
If you moved this function call to the PreRender event instead, then the grid will be bound to the new datasource (updated datasource) after the Edit has occurred (whereas if you do this in the PageLoad event it occurs before the edit does) and everything will work nicely....
i hve moved bindgrid method in Page_PreRender event bt the prob arising is that text boxes are containing null value instead of updated values.so update method is not having any effect.
Frinavale 9,735
Recognized Expert Moderator Expert
This should not happen if you are no longer calling the DataBind method on the GridView before the Update event.
Post your updated code so that I can see what you're doing now.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: j.zascinski |
last post by:
Hi,
i have a "simple" problem with gridview, please help me :)
i want to have gridview which is binded to a datatable (or a dataset).
i can show the data from the dataset in the gridview and i can start
editing the data, but when i click update i loose my new values. I want
this values to be saved in datatable (not straight to database with
sqldatasource - i tried this and it worked great), i tried to do this
task with objectdatasource...
|
by: P. Yanzick |
last post by:
Hello,
I've been playing with master/detail views as well as editing in the
gridview, and I ran across a strange problem that I am not exactly sure
where to go to try to solve.
I have 2 tables, a table of cars (pretty basic, an ID, a description, and a
Color ID) and a table of colors (Color ID, and a color description). I've
added a gridview and a detailsview as I'm playing with both and how to get
editing features to work the way I...
|
by: Kyle K. |
last post by:
I would like to build my data pages such that the top of the page
contains a GridView showing the data with 'Enable Select = true'.
Below that I would like to have a FormView, that by default is in
'Insert' mode for creating a new record.
If the user 'selects' a record in the GridView above, I would like to
set the FormView to 'Edit' mode with the 'selected' record data loaded
in it for editing. I would use the built-in editing...
|
by: Tomasz Jastrzebski |
last post by:
Hello Everyone,
I have a GridView control bound to a plain DataTable object.
AutoGenerateEditButton is set to true, Edit button gets displayed, and
RowEditing event fires as expected.
|
by: cpnet |
last post by:
I have a GridView which I'm populating from an ObjectDataSource (give the
GridView a DataTable). The GridView will have about 20 rows, and only one
editable column. The editable column consists of a RadioButtonList ("Yes",
"No", "Not Answered") in a TemplateColumn. I want the user to be able to
select a radio button for each row in the GridView (without having to first
put each row into edit mode). Once the user has selected the Radio...
| |
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 ID="GridView1" runat="server" OnRowEditing="RowEdit"
OnRowCancelingEdit="RowCancel" OnRowUpdating="RowUpdating"...
|
by: pieandpeas |
last post by:
he selectedindex of my gridview is always one behind
for example, if i click on the EDIT.gif on row 1, then 5 , then 7, if i break the code and check the selectedindex, it is equal to 5. if i selected a different row, and then checked the selectedindex again, it would be equal to 7. i've checked a few posts and other people seem to have a problem with the selectedindex being one behind the current selection, anyway i'm stuck :-( here is my...
|
by: =?Utf-8?B?Z3V5?= |
last post by:
How do you enable editing in a GridView programatically rather than via its
Tasks menu?
Guy
|
by: Michael |
last post by:
It seems that a gridview allows us to delete only a single row at a time.
How to extend this functionality to select multiple rows and delete all of
the selected rows in a single stroke? just like what hotmail web UI is doing
now (having the option of selecting multiple rows (using the checkbox
provided) and perform a set of operations on them)
|
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 if that's what's causing the
behavior or not. It seems like the Update button should at least do
something.
When the Edit button is clicked, the grid goes into Edit mode and the Cancel
button takes the grid out of Edit mode. So, I don't get what...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
| |
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
|
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...
| |