DataGrid Edit - (TextBox)e.Item.Cells[3].Controls[0].Text returns old value

I have a DataGrid that lists items from a hardware catalog. Having edited the price of an item and selected update, the InventoryGrid_UpdateCommand()  method reads the price into a textbox: TextBox Price = (TextBox)e.Item.Cells[3].Controls[0];. The problem is that it seems to be reading the original value not the value I have entered. Any ideas?        

<code>

<asp:datagrid id="InventoryGrid" runat="server" width="536px" bordercolor="Silver" borderwidth="1px"
            cellpadding="3" autogeneratecolumns="False" allowsorting="True" onsortcommand="InventoryGrid_SortCommand"
            onselectedindexchanged="InventoryGrid_SelectedIndexChanged">
            <itemstyle font-size="8pt" font-names="Verdana" height="10px"></itemstyle>
            <headerstyle font-size="8pt" font-names="Verdana" font-bold="True" wrap="False" height="10px"
             forecolor="Black" backcolor="#FFCC00"></headerstyle>
            <columns>
             <asp:templatecolumn headertext="Product Image">
              <headerstyle width="65px"></headerstyle>
              <itemtemplate>
               <asp:Image id=Image1 Runat=Server Width="54" Height="45" ImageUrl='<%# HardwareCatalogue.Attachments.GetDisplayImageUrl((string)DataBinder.Eval(Container.DataItem, "Full_Name"),"10")%>'>
               </asp:image>
              </itemtemplate>
              <edititemtemplate>
               <asp:image id="Image2" runat=Server width="54" height="45" imageurl='<%# HardwareCatalogue.Attachments.GetDisplayImageUrl((string)DataBinder.Eval(Container.DataItem, "Full_Name"),"10")%>'>
               </asp:image>
              </edititemtemplate>
             </asp:templatecolumn>
             <asp:boundcolumn datafield="Supplier_Code" readonly="True" headertext="Supplier Code">
              <headerstyle width="65px"></headerstyle>
             </asp:boundcolumn>
             <asp:boundcolumn datafield="Full_Name" sortexpression="Full_Name" readonly="True" headertext="Product Name">
              <headerstyle width="65px"></headerstyle>
              <itemstyle width="300px"></itemstyle>
             </asp:boundcolumn>
             <asp:boundcolumn datafield="Unit_Price" sortexpression="Unit_Price" headertext="Price" dataformatstring="{0:C2}">
              <headerstyle width="65px"></headerstyle>
             </asp:boundcolumn>
             <asp:buttoncolumn text="Select" commandname="Select">
              <headerstyle width="85px"></headerstyle>
             </asp:buttoncolumn>
             <asp:editcommandcolumn edittext="Edit" canceltext="Cancel" updatetext="Update" itemstyle-wrap="false" headertext="Edit" />
            </columns>
            <pagerstyle nextpagetext="Next" height="6px" font-size="X-Small" font-names="Verdana" bordercolor="Black"
             prevpagetext="Previous" borderstyle="None" horizontalalign="Right" forecolor="Black" mode="NumericPages"></pagerstyle>
           </asp:datagrid>

 

private void InventoryGrid_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

InventoryGrid.EditItemIndex = e.Item.ItemIndex;

InventoryGrid.AllowSorting = false;

InventoryGrid.DataBind();

}

private void InventoryGrid_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

InventoryGrid.EditItemIndex = -1;

InventoryGrid.AllowSorting = true;

InventoryGrid.DataBind();

}

private void InventoryGrid_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

string SupplierCode = e.Item.Cells[1].Text;

TextBox Price = (TextBox)e.Item.Cells[3].Controls[0];

string[] Params = new string[] {SupplierCode,Price.Text};

DBAccess.GetStoredProcedure("sp_UpdatePricing", Params, "tblCatalogue");

}

 

</code>

 

 

0
meedax
4/25/2005 3:25:49 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

3 Replies
1226 Views

Similar Articles

[PageSpeed] 1

do you have the databinding code within if not ispostback event in your page_load ?
***********************
Dinakar Nethi
Life is short. Enjoy it.
***********************
0
ndinakar
4/25/2005 4:54:13 PM

How is it that u are editing the Price whn u have it in a BoundColumn. Change that into a TemplateColumn and have ItemTemplate and EditItemTemplate inside them to make this work.

<asp:TemplateColumn HeaderText="Price">
   <ItemTemplate>
         <%#String.Format("{0:C2}", DataBinder.Eval(Container.DataItem, "Unit_Price"))%>
   </ItemTemplate>
   <EditItemTemplate>
         <asp:TextBox Runat="server" Width="120" Text='<%#DataBinder.Eval(Container.DataItem, "UnitPrice")%>ID="tbxEditRemarks">
         </asp:TextBox>
   </EditItemTemplate>
</asp:TemplateColumn>

in the code behind

TextBox Price = (TextBox)e.Item.Cells[3].Controls[1];

woud get u the value in the textbox.

hth


Shravan Addaypally MCP

0
shravan79
4/25/2005 5:17:50 PM

Spot on. Big Smile [:D]

Believe it or not I realised I must have done this when I was on my way home last night.

My bound Price column is dynamically changed to a text box, I believe it must be a feature of the DataGrid.

Thanks for the help

0
meedax
4/26/2005 8:48:49 AM
Reply:

Similar Artilces:

What is the difference between e.Item.Cells[1].Controls[0] and e.Item.Cells[1].Controls[1] ?
I usually work with Datagrid but I do not understand the difference between ...Controls[0] & Controls[1] in DataGrid. Please give some suggestion ! Thanks a lot ! briefly a DataGrid is rendered as an HTML Table containing TR ( item ) and TD ( cells ) elements at runtime e.Item.Cells refer to the TableCellCollection in the current row this cells collection, like any collection in .NET, is zero-based, meaning the first cell in the Cells collection is Cells [ 0 ], and the next is Cells [ 1 ], etc. e.Item.Cells [ x ].Controls refer to the control collection within the cell. Thi...

Edit the cell text by clicking in the cell in datagrid control
Sir,In asp.net 2.0 application, I want to edit the cell text by clicking in the cell in datagrid control. By EditItemTemplate it is possible to edit the cell text but for that we need to click on Edit button and after edit we need to click on Update button. But this way is not accepted. Is it possible in datagrid (possibly without activex control) to click in cell and edit the value and click out of the cell to update just like windows application grid?I did not find any article on web related to this.Please help me.Thanks in advance.    &nbs...

[e.Item.Cells[2].Controls[0]] ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Hi, I am having problem with this line e.Item.Cells[2].Controls[0]; it give me the error Specified argument was out of the range of valid values. Parameter name: index but at the same time int temp1=e.Item.Cells.Count; gives me temp1=9 I cant understand if e.Item.Cells.Count is 9 then why its giving the error at cell index number 2. I changed the index to other smaller and bigger numbers but getting the same error i-e on e.Item.Cells[2].Controls[0]; Heres the error in detail Specified argument was out of the range of valid values. Parameter name: index D...

DNN 3.0.8 Multiple Controls and Edit Controls
I have made good progress figuring out how to use the Module Actions in conjunction woth the Control Keys to have multiple different controls for manipulating many different objects (tables) The problem that I am running into has me stymied... Here is the Scenario, I have a Menu.ascx which is the main view control for my module. In this Menu, I add 4 different actions for the Edit Role. These work as expected and show up for the users if they have edit rights on the module. I can use the actions to load the correct control for the object I am trying to manipulate. When I tr...

Datagrid(.net 1.1) to GridView(.net 2.0) and using the RowUpdating event how to extract the values from the controls.
Ok  This is the settings: I use a Viewgrid with only itemtemplate colums for example. <asp:TemplateField HeaderText="Test"><ItemTemplate><asp:Label id="LBL_Test" text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' runat="server" meta:resourcekey="LBL_TestResource1"></asp:Label></font></ItemTemplate> <EditItemTemplate><asp:TextBox ID="HDN_Test" Text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' Runat="server" meta:resourcekey="HDN_TestResource1" /></EditItemTemplate></asp:TemplateField>  The ...

e.Item.Cells[0].Controls[1]
In asp.net 1.1I have a datagrid with templatecolumn<TemplateColumn><Itemtemplate><asp:label id="empno" runat=server></asp:label></ItemTemplate>How can i retrieve the empno of Employee in ItemDatabound?e.Item.Cells[0].Controls[1] does not contain property like text or value Controls[0] is showing as literal control,Controls[2] is pointing as Labelpls help me,its very urgent req Try to use the following code to find the <asp:label/> in <asp:DataGrid/> in ItemDatabound event handler.Label lblPlus = dgPhone.Items[e.Item.ItemIndex].FindCo...

Forum 3.0.0: A control cannot modify its parents' control collections.
I'm not sure what happened, because I don't recall that I did any changes to the Forum but for some reason if I go to the DNN web page that contains the new 'core' forum I am seeing this message above the forum container: A critical error has occurred. A control cannot modify its parents' control collections. and the content of the forum container is empty. If I sign in as a regular (registered) user the forum container displays correctly. As follow-up... This may be a caching problem as the problem of some sort. The problem cleared its self after I stopped working on the site...

Returning value from composite control to more than one other controls
This is not really a problem but I was curious if there was a better way to do this. I have a Composite Control that will return its value to a server control or something when it is done. I expect that it will fill a text box or a label but I wouldn’t mind if it could fill a button or any number of things that have a simple place to store text. Is there a better way than going through all of the option by hand?   Here is an example of my code.   public class DateTimeThing : CompositeControl    {        protected DateTime dateti...

Application created in new version of .NET (3.0 or 3.5) can use the library created in older version of .NET(i.e.-1.0 or 2.0)?
Hi All, I am using Visual Studio .NET compiler for compiling my application . We have plugins (as library) which the user can write by their own in .NET . We are building our code in Visual Studio 2005 but we have already some plug-ins which are written in previous versions of Visual Studio (i.e. 2002 and 2003). Is these plug-ins will work with the new build of the application or I need to build these plug-ins as well in Visual Studio .NET 2005. These plugins are created as library. Is their any differences between .NET 1.0, 2.0 and 3.0 because of which the old libraries (created in o...

Control.Value and Control.SelectedItem.Value
Can someone explain to me the difference between say, Dropdownlist.SelectedItem.Value and Dropdownlist.SelectedValue?? Just curious, Thanks!Tim These are going to return the same thing. dropdownlist.selectedvalue is a shortcut to get the currently selected value in the dropdown. If that is all you want then you can just use that. If you want to access the currently selected item you can use dropdownlist.selecteditem and that return the item and you can then access any of the item's properties, including in this case the value property. If this post answered your question please r...

How to place a DataGrid Control with in a DataGrid Control
Hi, I want to place a DataGrid control in a DataGrid control can any one plz tell me the procedure to place the control Thanks in Advance Krisamigo <!---<asp:DataGrid ID=dg_List runat=server><Columns><asp:TemplateColumn><ItemTemplate><asp:DataGrid ID=dg_List2 Runat=server></asp:DataGrid> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:DataGrid> ---> Hardik Joshi...

Changing DataGrid cells and child controls based on other cells values... having trouble
I am trying to examine the value of one cell, then disable other controls in the same row (in other cells) based on this. Basically if this cell = Yes or No, then disable a dropdown in another cell. I have tried the ItemCreated and ItemDataBound and am intercepting the event.itemtype by (ListItemType.Item and ListItemType.AlternatingItem) but it is telling me that value of this cell when i examine it is empty. Should i wrap the value in a label or something? I have tried that as well but it doesnt work, the value is always empty when checking during these events but at render time ...

user control
testUserControl.ascx  <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="testUserControl.ascx.cs" Inherits="testUserControl.testUserControl" %> <asp:Label ID="Label1" runat="server" Text="User control label"></asp:Label> <br /> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />  testUserControl.ascx.csusing ...

How do I access control on edit item template in DataView control?
I have a DataView control. I have a Template Field named MyNewTemplateField and in it's Edit Items Template I have a text box called "txtMyTextBox", which I want to do something with the data typed in, and then take that result and put it in the Access database.  Protected Sub DataView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewCommandEventArgs) Handles dvAcct.ItemCommand Select Case e.CommandName Case "Edit" Dim txtTheText As New TextBox txtTheText = DataView1.FindControl("txtMyTextBox"...

Return in a Edit Item Template text box to cause the Edit Command button to click in a DataGrid
Hello Everyone I have a DataGrid with ItemTemplates.  What the client wants is to be able to hit return in the edit item template's text box, and as a result have the Edit Command Save button clicked. Doing a search I came across several discussions of this topic that indicated that one could do this using JavaScript, but I'm unclear about how to go about this; I'm guessing that I can trap the key press in the box and cause a postback if it's the return key but don't know what event I'm looking for. Suggestions?   Thanks in advance! I am assuming that there's only one save b...

Web resources about - DataGrid Edit - (TextBox)e.Item.Cells[3].Controls[0].Text returns old value - asp.net.presentation-controls

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

How effective are parental controls for your child's safety?
... situation. Parents need to find ways to protect their children when they are not around to monitor it themselves. The Use of Parental Controls ...

Kurt Vile, Superchunk, Deer Tick, Waxahatchee, Parquet Courts, Sonic Youth members & more celebrated ...
photos by Amanda Hatfield; words by Bill Pearis Parquet Courts & Lee Ranaldo / Rainer Maria & Meredith Graves / Kurt Vile & Kim Gordon / Waxahatche ...

San Bernardino shooting and the politics of gun control
"It's not enough to keep lamenting these things," Democratic Sen.

Kylie Jenner & her very thin Greyhounds were investigated by Animal Control
... healthy (you can see some screencaps from the Snapchats here ). So… Kylie was investigated by the LA County Department of Animal Care and Control. ...

It is rocket science: Blue Origin control room gets delirious over landing
Technically Incorrect: A new video shows the full raucous glory of the scientific experience. Watch as a packed house celebrates November's successful ...

Hillary Clinton, Bernie Sanders seek gun control reform after shootings
CNN Hillary Clinton, Bernie Sanders seek gun control reform after shootings CNN Washington (CNN) Hillary Clinton and Bernie Sanders said Thursday ...

Even Morning Joe Isn't Buying Carly Fiorina's Gun Control Plan
If you are a Republican Presidential Candidate, the issue of paramount importance, following a gun massacre, is the expression of prayer. 'The ...

Obama Planning To Pull The Trigger On Gun Control Executive Order
Obama Planning To Pull The Trigger On Gun Control Executive Order

Your opinion on gun control doesn't matter
... will die by guns than in car accidents this year. In practice, this is a public health crisis. If you still bristle at the idea of gun control, ...

Resources last updated: 12/4/2015 6:52:01 AM