473,785 Members | 2,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView does not update when used image buttons

Hello,

I am having a problem with GRIDVIEW IN C#.
The following code updates only the alternate rows.
When i use the edit button all the cells does get converted to textboxes
thereafter when i click on the updated button the alternate rows do not
enter the if loop mentioned in the code. So only the rows 1,3,5,7...
gets updated whereas the rows which bear the even no.s 2,4,6,8.. does
not get updated. And the smart thing is neither does it show any error

i am producing the code below

protected void GridView2_RowUp dating(object
sender,GridView UpdateEventArgs e)
{
String S1;
SqlConnection MyCon = new
SqlConnection(" Server=HEMALATH A\\SQLEXPRESS;I ntegrated
Security=SSPI;d atabase=demo");
MyCon.Open();

ImageButton b1 = new ImageButton();
TextBox t1 = new TextBox();
TextBox t2 = new TextBox();
foreach (GridViewRow gv in GridView2.Rows)
{
int k = 1;
Response.Write (k);
b1 = (ImageButton)gv .FindControl("I mageButton1");
t1 = (TextBox)gv.Fin dControl("TextB ox1");
t2 = (TextBox)gv.Fin dControl("TextB ox2");
if (gv.RowState == DataControlRowS tate.Edit)
{
int l = 2;
Response.Write (l);

S1 = "update t1 set name='" + t2.Text + "' where id=" +
t1.Text + "";
SqlCommand UpdateCmd = new SqlCommand(S1, MyCon);

UpdateCmd.Execu teNonQuery();
}
}

MyCon.Close();

}
this is the code for asp
<asp:GridView DataKeyNames="I d" ID="GridView2" runat="server"
AutoGenerateCol umns="False" Style="z-index: 104;
left: 66px; position: absolute; top: 405px" Width="581px"
OnRowEditing="G ridView2_RowEdi ting"
OnRowUpdating=" GridView2_RowUp dating"
OnRowCancelingE dit="GridView2_ RowCancelingEdi t"
OnRowDeleting=" GridView2_RowDe leting"
OnRowDataBound= "GridView2_RowD ataBound"

But if i put the command buttons i can easily update
placing the code below.
protected void GridView2_RowUp dating(object
sender,GridView UpdateEventArgs e)
{
String S1;
SqlConnection MyCon = new
SqlConnection(" Server=HEMALATH A\\SQLEXPRESS;I ntegrated
Security=SSPI;d atabase=demo");
MyCon.Open();

ImageButton b1 = new ImageButton();
TextBox t1 = new TextBox();
TextBox t2 = new TextBox();
foreach (GridViewRow gv in GridView2.Rows)
{
int k = 1;
Response.Write (k);
b1 = (ImageButton)gv .FindControl("I mageButton1");
t1 = (TextBox)gv.Fin dControl("TextB ox1");
t2 = (TextBox)gv.Fin dControl("TextB ox2");
if (gv.RowState == DataControlRowS tate.Edit)
{
int l = 2;
Response.Write (l);

S1 = "update t1 set name='" + t2.Text + "' where id=" +
t1.Text + "";
SqlCommand UpdateCmd = new SqlCommand(S1, MyCon);

UpdateCmd.Execu teNonQuery();
}
}

MyCon.Close();

}

OnSelectedIndex Changed="GridVi ew2_SelectedInd exChanged"
ShowFooter="Tru e">

*** Sent via Developersdex http://www.developersdex.com ***
Aug 4 '07 #1
0 1830

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

Similar topics

3
13754
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum. Everyone wants to do a java confirmation box when a user clicks the delete button. Fair enough, basic user design rules state that you should always confirm a delete action. There is also a consensus that the best way to do this is a template...
3
2235
by: adam222 | last post by:
hello, i have a web-form with a GridView control, i wanted to update & delete, using the AutoGenerateEditButton. when i used it with sqlDataSource (executing SP in the DB) it works like a charm, but when i want to pass the data through the application's layers (BL etc.), it did not work. it seems that the 'AutoGenerateEditButton' is capable only with sqlDataSource...
1
9356
by: Miguel Dias Moura | last post by:
Hello, I have a GridView in my page which is created in runtime. It works fine. My page has 2 Asp Buttons: - The HIDE button makes GridView.Visible = False; - The SHOW button makes GridView.Visible = True. I press HIDE and the GridView disappears as expected. After it I press SHOW and the GridView doesn't show.
3
10275
by: pblack9455 | last post by:
I have a simple requirement to bind a small ArrayList of (ItemLine) Objects to a GridView control. The Gridview renders on the page and allows me to click update/edit buttons...however the data does not change, and in the updated and updating row events the newValues collections are empty!!! I've tried various other methods such as using an ObjectDataSource, but my ArrayList does not existing in a database until after the editing and...
0
1507
by: =?Utf-8?B?QnJ5YW4=?= | last post by:
I'm using a GridView to display large search results, and in each row I display a "Select" image button to choose the record. What I've been noticing is that when users search and display the results, the images for the buttons are not displayed all at once, but as if the page was downloading each image one by one, which is an unpleasent look and feel for the users. So, I checked my temporary Internet files and sure enough the same image...
2
1579
by: fanoftvb | last post by:
Hi, I'm having problem with my rows on gridview. When i click on the approve button, only the first row of the grid will update. Does anyone know how to make it that when i click on the different button on different row different rows will update. My code is as below... Sub CustomersGridView_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) ' If multiple buttons are used in a GridView control, use the ...
1
10408
by: Evan M. | last post by:
Here's my GridView and my SqlDataSource <asp:GridView ID="ContactHistoryGrid" runat="server" AutoGenerateColumns="False" DataSourceID="ContactHistoryDS" DataKeyNames="JobHistoryID" OnRowCreated="ContactHistoryGrid_RowCreated" CssClass="GridViewTable" GridLines="None" CellSpacing="1" CellPadding="3" AllowSorting="True" AllowPaging="True"> <EmptyDataTemplate>
3
2068
by: dhaneshrs | last post by:
I have a gridview i managed to update using the edit option in the smartmenu. The problem comes when i delete a value or make a value read only. Say i have a table Employee with the following columns : EmpID, Emp Name, Password, Emp Type. Now when i remove the value EmpID, the gridview does not update. it just reloads when i hit update but no changes are made. On the other hand say i make Emp Type as Read only, when i update .. the...
4
8846
by: Peter | last post by:
I want to call a JavaScript on PageIndexChanged event, how do I do that? Thank You Peter
0
9645
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, 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...
0
9480
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,...
0
10330
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...
0
10153
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 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...
1
10093
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
8976
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
5381
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4053
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
3654
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.