Changing the value of one cell when the user changes the value of another cell

I am using a standard GridView with multiple columns and a SQLDataSource.

One column is called Qty and another column is called Date.

When the user clicks the Edit button and enters a quantity into the Qty column, I would like to automatically fill in today's date into the Date column...before the user clicks Save.

Any ideas on how to do that?

Thanks in advance,




12/29/2006 9:05:38 PM 72751 articles. 3 followers. Follow

5 Replies

Similar Articles

[PageSpeed] 20

You would have to make an asych call, check out ASP.NET AJAX:
12/29/2006 9:09:13 PM

add a javascript event on the quantity textbox the onchange

On the gridviews rowdatabound add this

  Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
    If (e.Row.RowState And DataControlRowState.Edit) > 0 Then
      'We are in edit mode
      Dim txtQty As TextBox = CType(e.Row.FindControl("txtQty"), TextBox)
      Dim txtDate As TextBox = CType(e.Row.FindControl("txtDate"), TextBox)
      txtQty.Attributes.Add("onchange", "document.getElementById('" & txtDate.ClientID & "').value = '" & System.DateTime.Now.ToShortDateString & "';")
    End If
  End Sub

Jared Roberts
Lead Application Developer
12/29/2006 9:15:04 PM

Thanks for the response.  I think that I am almost there, but...

My grid ID is "grdItems".  How do I know what to put inside of the CTYPE(e.Row.Findcontrol(????),TextBox)?

When I edit the columns on the grid, I have "Order Qty" for the Header Text of one and "Req Date" for the Header Text of the second one.  I do not see a property like "ID".

I tried using "Order Qty" and "Req Date" but it is just returning "Nothing" when I hold the cursor above the txtQty and the txtDate.

I am guessing that the FindControl is not working.




12/29/2006 10:36:37 PM

You can only use that syntax if you're using TemplateField which contains a TextBox, and then you would put the Id of the TextBox in there.


12/29/2006 10:42:18 PM

Got it.

 Thanks, thanks, thanks,



12/29/2006 10:56:59 PM

Similar Artilces:

change one gridview cell text format based on another gridview cell value??
I have the following (I code in VB) in a datagrid nested inside a DataList: The hiddencolumn style prevents the CAB column/data field from showing in the browser. How do I make the "Consumer" datafield cell text be purple and italic if CAB is True or -1 in Access?? I code in VB, and I know the code has to be in the one of the row or data events of the gridview. Thank you, Tom Convert your Consumer to a template field with label, id = "Label1" then try using the RowDataBound event of the gridview and code something like: If e.Row.RowType = DataControlRowType.Data...

Update on another cell when the cell value is changed??
Hi, I am using SqlCommandbuilder for insert/update automatically to the database. How to have a calculation on another cell after the cell is changed? For example, when user changes or enter Food_Count value, I need the Food_Amount columns to be changed in database automatically: Food_Amount = Food_Count * 0.8 How to do it? ---------------------------------------- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click builder = New SqlCommandBuilder Dim DBstrQ As New SqlCommand("", conDWDb) DBstrQ.CommandText = "SELECT Bus_Date AS Bus_Da...

Changing a Cells color based on another cells value
We want to change the color of a previous cell based on the value in the current cell. For example, say we are ranking items as they are read into the datagrid. We have several columns of data we want to rank for first and second place. Once we encounter a value that is greater than the previous high value we would like to change the previous high values cell color to yellow and the new high cells color to green. For example column 1 in the following table would have 12 highlighted in green and 10 highlighted in yellow. See the following table. Column 2 would have 11 highlighted green and th...

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 ...

how to change the cell value depending on its databound value
Hi I have a small Q.. I have a datagrid with the person Information and one of the columns will have (sex) or (Gender) I used a boolean datatype in the database to store the gender information so.. something like: True= Male False= Female When I bound the dataset to the datagrid.. I will show Sex as either True or False.. What I wanted now is to replace those values in the datagrid with (Male) or (Female) here is the code of my aspx: <asp:datagrid id=DataGrid1 runat="server" DataSource="<%# DataSet11 %>" DataMember="PERSO...

change format of one control based on value of another control
Hi, I am very new to and need some help with an odd requirement.  We use Visual Web Developer for all our work and have built our corporate intranet around it.  On our home page we have a hyperlink to our IT departments status page (traffic light system), we want to change the colour of the hyperlink text to be the same as the most serious traffic light on the other page (may be even flash the text for "red" issues)? Our IT department directly edit the traffic light network status page themselves, via a text editor, so the hyperlink on the home page needs to pic...

How to change value a Cell in DataTable or Change Display in Gridview ?
Hi, Everyone !I have a issuse in the picture below:   In the Method Bind data To a GridView I have:string b_sdv = "SELECT ma_dvi, ten_dvi FROM DONVI";DataTable dt_dv = (DataTable)BindToTable("b_sdv");string b_snd = "SELECT  ma_dvi, ma_nsd, Ten_nsd FROM NSD;DataTable dt_nsd = (DataTable)BindToTable("b_snd");  // create relationshipDataset ds  = new Dataset()ds.Tables.Add(dt_dv.Copy());ds.Tables.Add(dt_nsd.Copy());DataRelation b_drl = new DataRelation("Relation_Data", ds.Tables["DONVI"].Columns["ma_dvi&qu...

Change Datagrid cell color based on cell value
I was wondering if there is a way to change the background color of an individual cell in a datagrid based on it's value. (I code in VB) Example: I have a Due Date field and the cells need to be highlighted yellow for all dates that are over 30 days old. Then for all of the dates that are over 60 days old, their cell backgrounds would need to be red. Thanks for the help in advance Dan Take a look @ Change Color of a Column Based on Column Values In your case you can use <Table> tag and change the <td> background color using helper function HTH Sushila ...

How to change value in cell into DataTable or Change display in the Gridview ?
Hi, Everyone !I have a issuse in the picture below:   In the Method Bind data To a GridView I have:string b_sdv = "SELECT ma_dvi, ten_dvi FROM DONVI";DataTable dt_dv = (DataTable)BindToTable("b_sdv");string b_snd = "SELECT  ma_dvi, ma_nsd, Ten_nsd FROM NSD;DataTable dt_nsd = (DataTable)BindToTable("b_snd");  // create relationshipDataset ds  = new Dataset()ds.Tables.Add(dt_dv.Copy());ds.Tables.Add(dt_nsd.Copy());DataRelation b_drl = new DataRelation("Relation_Data", ds.Tables["DONVI"].Columns["ma_dvi&qu...

Pass value from one User Control to another User Control
I have tried to pass value from one user control to another user control. Because of Page Auto Postback, Contrls are load before page is loaded. So I get the value in 2nd UC after one more post back operation. I have visited many suggessions but I cant solve this. Is anyone can help me to solve this. Thank U Muhmmad Fakhrul HossainEmail: mfhossain@gmail.comPhone: +88 01715 111512Web: You'd have to do that through the parent probably in it's Page_Load event handler.   userControl1.publicProperty = userControl2.publicProperty;  ...

Hello Everyone!  .NET 2.0, VS 2005 Pro I am trying to update a cell in a gridview row based on the value of another cell on the same row.  No luck so far... I have a gridview that contains three template columns, with Edit & Delete buttons.  All ITEM templates are labels.  The first EDIT template column is a dropdownlist, and the next two are text boxes.  I want to update one of the cells in the row based on the selection from the dropdown list.  For example, if the selected value in the dropdownlist is "URGENT:" then I want the value ...

help with MaskedEditExtender control changing my pre-set value into another value.
I am working on a maintenance application and I am making a use of the Ajax Control Toolkit to apply Client Side validation. This is my first time actually implementing this toolkit into my apps so would like to clear out a couple of issues. My question is that I am populating dollar amounts into a textboxes from a DB query. One of my controls is set up like this: <asp:TextBox ID="txtDollars" runat="server" Width="80"></asp:TextBox> <ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender2" ...

how to change the value of checkbox when i change the value of textbox
i want the checkbox to change its value to unchecked when the textbox doesnot have anything i.e is value is "" and as soon as i enter anything to it, the checkbox should automatically change to checked. Can you please tell me how to do this Add to the textbox: OnKeyUp="CheckValue()" Add to the html: <script language="javaScript"> function CheckValue() { if (document.getElementById('textboxid').value.length == 0) { document.getElementById('checkboxid').checked = false; } else { document.getElementById('checkboxid').checked...

how ontextchanged event in datalist fire and when that textbox value change than another textbox inside datalist value also change
 i have one datalist into which i used maskededit extender for time entry there is three textbox (1) start_time (2) end_time (3) duration so when enter  end_date value than this text box ontextchage event fire and duration will automatically calculate by(end_time - start_time) and display into datalist duration textbox. in datalist there is more than one item.i put some code so just check  <asp:DataList ID="CONTRACT_SERVICE_ITEM" runat="Server" RepeatColumns="1" RepeatDirection="Horizontal"      &nbs...

Web resources about - Changing the value of one cell when the user changes the value of another cell -

Changing room - Wikipedia, the free encyclopedia
A changing room , locker room , dressing room (usually in a sports, theater or staff context) or changeroom (regional use) is a room or area ...

Beyond Timeline: The Changing Face Of Facebook Ads
Despite the hype, timeline may not be the most exciting, or important change coming on March 30. Expanded advertising opportunities may unlock ...

Robert Scoble - Micromedia, how it's changing what we blog - Facebook
Jeremiah Owyang wrote an interesting piece about micromedia and how it's changing what we do on blogs and how we distribute media (er, ideas, ...

8 Ways the Changing Facebook Home Page Will Affect Application Virality
For developers who live and die by the changes Facebook makes to the way information flows through the service, every little Facebook tweak has ...

Changing Lanes (@chginglanes) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

Changing the way business decisions are made
We believe that social data has unlimited value, and near limitless application. Today, we’re taking an important step toward unleashing this ...

The Right and Wrong Reasons for Changing Jobs
... your profile is a clue to the folks at LinkedIn that you’re thinking of switching jobs, so don’t be The Right and Wrong Reasons for Changing ...

We're Changing Our Name (Back) to Stack Overflow
We are Stack Overflow. You may know us from such popular websites as Stack Overflow Q&A, Stack Overflow Careers, The Stack Exchange Q&A Network, ...

The Tao of Twitter: Changing your life and business 140 characters at a time - Amazon
It's time to take the mystery out of Twitter. Twitter may be the most powerful business and personal networking platform ever created but it ...

App Store - Voices 2 ~ fun voice changing!
Read reviews, get customer ratings, see screenshots, and learn more about Voices 2 ~ fun voice changing! on the App Store. Download Voices 2 ...

Resources last updated: 1/6/2016 3:57:53 PM