Hi-
I've been struggling with this problem and none of the fixes posted
seem to help out at all. Yet, it seems like such a simple problem...
I have a DataGrid, and load it up with data on page load. In my
EditCommand event handler I set the editItemindex. All good. Except,
the user needs to click twice to get the DataGrid to become editable.
It's obvious to me (perhaps worngly) that ASP.NET is storing the data
form my grid in the viewstate, and setting up the datagrid BEFORE the
Edit button event. That's why the grid appears editable the next page
load.
So, how do I refresh the grid to show the editability? Predictably,
calling DataBind makes all the data go away... String the data set in
the session seems redundantg, since the page is definitely storing the
data for me in the viewstate. Not that I can get to it...
Any ideas?
Diane
<PRE>
private void Page_Load(objec t sender, System.EventArg s e)
{
if (this.IsPostBac k == false)
{
sqlConnection1. ConnectionStrin g = "..pubs..";
string query = "SELECT * FROM stores";
this.sqlDataAda pter1.SelectCom mand.CommandTex t = query;
this.sqlDataAda pter1.SelectCom mand.Connection =
sqlConnection1;
this.sqlConnect ion1.Open();
this.sqlDataAda pter1.Fill(this .dataSet1, "storesAll" );
this.DataGrid1. DataSource =
this.dataSet1.T ables["storesAll"];
this.DataGrid1. DataBind();
this.sqlConnect ion1.Close();
}
}
private void DataGrid1_EditC ommand(object source,
System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
this.DataGrid1. EditItemIndex = e.Item.ItemInde x;
} 7 2301
Diane,
I'm not certain but this may be a different problem all together. I've
noticed this type of behaviour with dynamically created controls. If your
datagrid is being created dynamically or is part of a user control being
placed on a main page dynamically then try this:
Give your control an id when it's created. E.g. if this is a dynamic user
control in the control's page load routine put: Me.Id = "MyDynamicContr ol1"
Something in the framework looks for a control's user id to hook up the code
and doesn't work the first time through if that id isn't there... I'm still
not positive what causes the behaviour though, but giving it the Id fixes
it.
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Diane" <so************ *@yahoo.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com... Hi-
I've been struggling with this problem and none of the fixes posted seem to help out at all. Yet, it seems like such a simple problem...
I have a DataGrid, and load it up with data on page load. In my EditCommand event handler I set the editItemindex. All good. Except, the user needs to click twice to get the DataGrid to become editable.
It's obvious to me (perhaps worngly) that ASP.NET is storing the data form my grid in the viewstate, and setting up the datagrid BEFORE the Edit button event. That's why the grid appears editable the next page load.
So, how do I refresh the grid to show the editability? Predictably, calling DataBind makes all the data go away... String the data set in the session seems redundantg, since the page is definitely storing the data for me in the viewstate. Not that I can get to it...
Any ideas?
Diane
<PRE> private void Page_Load(objec t sender, System.EventArg s e) { if (this.IsPostBac k == false) { sqlConnection1. ConnectionStrin g = "..pubs.."; string query = "SELECT * FROM stores"; this.sqlDataAda pter1.SelectCom mand.CommandTex t = query;
this.sqlDataAda pter1.SelectCom mand.Connection = sqlConnection1;
this.sqlConnect ion1.Open(); this.sqlDataAda pter1.Fill(this .dataSet1, "storesAll" ); this.DataGrid1. DataSource = this.dataSet1.T ables["storesAll"]; this.DataGrid1. DataBind();
this.sqlConnect ion1.Close(); } }
private void DataGrid1_EditC ommand(object source, System.Web.UI.W ebControls.Data GridCommandEven tArgs e) { this.DataGrid1. EditItemIndex = e.Item.ItemInde x;
}
S Justin -
In my case, the DataGrid is created at design time, not dynamically.
So it already has an ID. My guess is that it is a timing issue: the
button click event happens after the DataGrid has been bound already,
and so the effects don;t show up til the next page load...
Thanks,
Diane
Diane,
You should only need to bind your datagrid on pageload:
If Not IsPostBack Then
'---First page load
'---Call routine to bind grid
Else
'---Post back only
End If
Then, as long as viewstate is on for the grid your button should work the
first time.
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Diane" <so************ *@yahoo.com> wrote in message
news:11******** *************@g 47g2000cwa.goog legroups.com... S Justin -
In my case, the DataGrid is created at design time, not dynamically. So it already has an ID. My guess is that it is a timing issue: the button click event happens after the DataGrid has been bound already, and so the effects don;t show up til the next page load...
Thanks, Diane
Justin-
Yes, I agree, if the viewstate is on the Edit button should work the
first time. That is the behavior I would expect, which makes it all
the more puzzling that things don't behave that way.
I don't suppose I can expect my users to click twice on the edit
button, so I guess I will have to settle for making another trip to the
databse in the event handler for the edit command. It would be cool to
be able to work with disconnected data until the update command, but
there seems to be no solution to this problem. Oh well, technology
can't be perfect.
Thanks for the support!
Diane
Justin-
Well, I've looked around at lots of examples on MS and other sites, and
everyone seems to load up the data from the DB again after the
EditCommand, or they call the Page DataBind method (which in my case
makes all the data dissapear, as I would expect. Not sure how folks
get it to behave otherwise).
Anyhow, it looks like in posted examples, people avoid this issue be
making an extra trip to the DB, or by saving the datagrid the session.
Tantalizingly, though, it almost works without a second trip to the DB.
Sigh,
Diane
Diane,
Too bad you didn't get it working with a single trip.
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Diane" <so************ *@yahoo.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. . Justin-
Well, I've looked around at lots of examples on MS and other sites, and everyone seems to load up the data from the DB again after the EditCommand, or they call the Page DataBind method (which in my case makes all the data dissapear, as I would expect. Not sure how folks get it to behave otherwise).
Anyhow, it looks like in posted examples, people avoid this issue be making an extra trip to the DB, or by saving the datagrid the session.
Tantalizingly, though, it almost works without a second trip to the DB.
Sigh,
Diane
This article may explain the problem you are having http://west-wind.com/weblog/posts/3016.aspx
-----------------------------------------------------------
I would much rather chew on tinfoil than try and code in C#. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: JD |
last post by:
How do i get rid of the 1st column that appears in a
datagrid? I do not want this?
Also how do i change the colour of the background of a
cell when the user selects it. i.e for the first coloumn
i have made this non-editable and therefore i do not want
the graey colour that appears when the user clicks on a
cell in the first row.
As only my second row is editable, i only want a click
colour for this coloumn
|
by: Arno |
last post by:
Hi
I am using a dataset to populate a editable datagrid. When I apply a table
style however, the datagrid seems to become read-only... How can I make the
datagrid editable again? Is there a method I need to call perhaps?
Regards,
Arno
|
by: Dalibor Kusic |
last post by:
The DataTable contains, for example, only one column of lets say
Person class.
Person class has three fields, and a constructor that takes a single
string and parses it over those three fields.
Now, how do I modify the Person class (which interfaces to implement)
so I can bind my DataTable to a DataGrid and then add, modify and
delete records through it?
|
by: Stephan Bour |
last post by:
Hi,
I have a datagrid databound to a SQL query. I'd like to allow editing of
some columns but not all. Is there a way to turn off the conversion of the
datagrid cells to textboxes for some columns when the Edit button is
pressed?
Thank you,
Stephan.
|
by: J McD |
last post by:
Hi
I have a DataGrid with an ImageButton column. When I click on an imagebutton I get a postback but it doesn't run the OnImgBtnClick method. I can actually comment out the line where I add this Click event to the ImageButton Column and it makes no difference, I still get a postback. This is driving me crazy...something seems to be causing an OnClick postback and it isn't my Click event
I've included the code below....any help will be...
| |
by: DaveR |
last post by:
I have a webform with a two-column datagrid based on an Arraylist. The
Arraylist draws the data for the two columns from two different tables
in an SQL database. The data is displayed in datagrid as expected but
when user clicks the Edit link, the cells do NOT turn into editable
text boxes. I actually need only the first column to be editable but
any ideas on getting the whole row editable would help at first.
Apologies for the amount of...
|
by: Angela Chen |
last post by:
Hi,
I have a readOnly textbox. I want to be able to double click it to make it
editable?
How to implement it?\
Thanks a lot
|
by: zambizzi |
last post by:
....I can't seem to get my hands on a control I'm loading in an editable
datagrid.
Here's my datagrid control:
<asp:datagrid
id="GLRulesGrid"
runat="server"
autogeneratecolumns="False"
oneditcommand="GLRulesGrid_Edit"
|
by: julian.tklim |
last post by:
Hi,
I need to build an editable Datagrid with add & delete buttons on each
row using javascript.
DataGrid need not be pre-populated with values.
To make the thing complicated, one of the column need to be a date
picker field.
I know things will be easier with ASPX datagrid.
|
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: 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,...
|
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: 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...
|
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: 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...
|
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...
| |