473,769 Members | 6,160 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Gridview Update - cannot retrieve new values

9 New Member
It doesn't look like its possible to retrieve new values if there is a gridview without datasource.

Can someone please translate this for me from C# to VB. I can't get this to work and I was hoping this would solve my problem trying to update a gridview without datasource.

Here's the code

((TextBiox)grid .Rows[e.RowIndex].Cells[0].Controls[0]).Text

Thanks for any help on this.

~Haleigh
Dec 21 '06 #1
9 15111
bplacker
121 New Member
It doesn't look like its possible to retrieve new values if there is a gridview without datasource. However, I seen one solution on http://forums.asp.net/1012665/ShowPost.aspx.

Can someone please translate this for me from C# to VB. I can't get this to work and I was hoping this would solve my problem trying to update a gridview without datasource.

Here's the code

((TextBiox)grid .Rows[e.RowIndex].Cells[0].Controls[0]).Text

Thanks for any help on this.

~Haleigh
TextBox.Text = grid.selectedRo ws(0).Cells(0). Value.ToString
Dec 21 '06 #2
Haleigh
9 New Member
TextBox.Text = grid.selectedRo ws(0).Cells(0). Value.ToString
Thank You!
Dec 21 '06 #3
Akrabbim
3 New Member
I'm having the same issue that the original poster is having, but this trick isn't working for me. The only thing I'm doing differently (I think) is that I'm creating my grid dynamically. I've tried every method I can find to get the new value for a control, and it's continually coming back as the old method. Is this a limitation of creating the grid dynamically? I'm doing this in C#.
Apr 24 '08 #4
Frinavale
9,735 Recognized Expert Moderator Expert
I'm having the same issue that the original poster is having, but this trick isn't working for me. The only thing I'm doing differently (I think) is that I'm creating my grid dynamically. I've tried every method I can find to get the new value for a control, and it's continually coming back as the old method. Is this a limitation of creating the grid dynamically? I'm doing this in C#.
Could you explain more about your problem?
I'm not clear on what you are trying to do. Are you trying to update a DataSet through a GridView? Are you trying to update a GridView based on a DataSet?

When you are explaining your problem please post any code snippets that will help us understand what you are doing. Please remember to use [code] tags when you post code.

-Frinny
Apr 24 '08 #5
Akrabbim
3 New Member
Well, I've got my data just fine. I just need the data, and I'll then run a stored procedure to update the values, THEN re-query it. Here's most of the code-behind. I'm still learning .NET, so it's a bit ungainly. I plan on parsing out a good bit of it to other components. It wouldn't let me post the whole thing.

Expand|Select|Wrap|Line Numbers
  1.     protected void InitDataTable(DataTable dt)
  2.     {
  3.         DataColumn dcol = new DataColumn("Doff Number", typeof(System.Int64));
  4.         dt.Columns.Add(dcol);
  5.         dcol = new DataColumn("Length", typeof(System.Int64));
  6.         dt.Columns.Add(dcol);
  7.         dcol = new DataColumn("Doff Length", typeof(System.Int64));
  8.         dt.Columns.Add(dcol);
  9.         dcol = new DataColumn("Start Time", typeof(System.DateTime));
  10.         dt.Columns.Add(dcol);
  11.         dcol = new DataColumn("End Time", typeof(System.DateTime));
  12.         dt.Columns.Add(dcol);
  13.         dcol = new DataColumn("WeavingDoffId", typeof(System.Guid));
  14.         dt.Columns.Add(dcol);
  15.     }
  16.  
  17.     protected void LoadDataTable(DataTable dt)
  18.     {
  19.         CMetalsWeavingDoffs cmwd = new CMetalsWeavingDoffs();
  20.  
  21.         LoadMetalsWeavingDoffs(cmwd);
  22.         foreach (SMetalsWeavingDoffs smwd in cmwd)
  23.         {
  24.             DataRow drow = dt.NewRow();
  25.             drow["Doff Number"] = smwd.WeavingDoffNumber;
  26.             drow["Length"] = smwd.Length;
  27.             drow["Doff Length"] = GetDoffLength(smwd.WorkOrderActualId);
  28.             drow["Start Time"] = smwd.StartTime;
  29.             drow["End Time"] = smwd.EndTime;
  30.             drow["WeavingDoffId"] = smwd.WeavingDoffId;
  31.             dt.Rows.Add(drow);
  32.         }
  33.     }
  34.  
  35.     protected void InitGrid(DataTable dt)
  36.     {
  37.         ButtonField confirmField = new ButtonField();
  38.         ButtonField scrapField = new ButtonField();
  39.         CommandField editField = new CommandField();
  40.  
  41.         if (!Page.IsPostBack)
  42.         {
  43.             foreach (DataColumn col in dt.Columns)
  44.             {
  45.                 BoundField bfield = new BoundField();
  46.                 bfield.DataField = col.ColumnName;
  47.                 bfield.HeaderText = col.ColumnName;
  48.                 if (bfield.DataField != "WeavingDoffId")
  49.                     grdDynamic.Columns.Add(bfield);
  50.                 if (bfield.DataField != "Length")
  51.                     bfield.ReadOnly = true;
  52.             }
  53.             confirmField.HeaderText = "Confirm";
  54.             confirmField.Text = "Confirm";
  55.             confirmField.CommandName = "Confirm";
  56.             confirmField.ButtonType = ButtonType.Button;
  57.             grdDynamic.Columns.Add(confirmField);
  58.             scrapField.HeaderText = "Scrap";
  59.             scrapField.Text = "Scrap";
  60.             scrapField.CommandName = "Scrap";
  61.             scrapField.ButtonType = ButtonType.Button;
  62.             grdDynamic.Columns.Add(scrapField);
  63.             editField.HeaderText = "Edit";
  64.             editField.EditText = "Edit Length";
  65.             editField.UpdateText = "Update";
  66.             editField.CancelText = "Cancel";
  67.             editField.ButtonType = ButtonType.Button;
  68.             editField.ShowEditButton = true;
  69.             editField.CausesValidation = false;
  70.             grdDynamic.Columns.Add(editField);
  71.  
  72.         }
  73.         grdDynamic.DataSource = dt;
  74.         grdDynamic.DataBind();
  75.     }
  76.  
  77.     protected void CreateGrid()
  78.     {
  79.         string[] dataKeyNames = new string[2];
  80.  
  81.         grdDynamic.AutoGenerateColumns = false;
  82.         grdDynamic.SkinID = "MainGridView";
  83.         grdDynamic.RowCommand += new GridViewCommandEventHandler(grdDynamic_RowCommand);
  84.         grdDynamic.RowEditing += new GridViewEditEventHandler(grdDynamic_RowEditing);
  85.         grdDynamic.RowCancelingEdit += new GridViewCancelEditEventHandler(grdDynamic_RowCancelEditing);
  86.         grdDynamic.RowUpdating += new GridViewUpdateEventHandler(grdDynamic_RowUpdating);
  87.         dataKeyNames[0] = "WeavingDoffId";
  88.         dataKeyNames[1] = "Length";
  89.         if (!Page.IsPostBack)
  90.             grdDynamic.DataKeyNames = dataKeyNames;
  91.         Page.Form.Controls.Add(grdDynamic);
  92.     }
  93.  
  94.     protected void BindGrid()
  95.     {
  96.         DataTable dt = new DataTable();
  97.  
  98.         try
  99.         {
  100.             InitDataTable(dt);
  101.             LoadDataTable(dt);
  102.             InitGrid(dt);
  103.         }
  104.         catch(Exception ex)
  105.         {
  106.             lblError.Text += ex.Message;
  107.         }
  108.     }
  109.  
  110.     protected void Page_Load(object sender, EventArgs e)
  111.     {
  112.         Response.Expires = -1600;
  113.         lblError.Text = string.Empty;
  114.         CreateGrid();
  115.         if (!Page.IsPostBack)
  116.             BindGrid();
  117.     }
  118.  
  119.     protected void grdDynamic_RowCommand(object sender, GridViewCommandEventArgs e)
  120.     {
  121.         try
  122.         {
  123.             if (e.CommandName == "Confirm")
  124.             {
  125.                 ConfirmDoff(grdDynamic.DataKeys[Convert.ToInt32(e.CommandArgument)].Values["WeavingDoffId"].ToString(), Convert.ToInt32(grdDynamic.DataKeys[Convert.ToInt32(e.CommandArgument)].Values["Length"]));
  126.                 ConfirmDoffOld(grdDynamic.DataKeys[Convert.ToInt32(e.CommandArgument)].Values["WeavingDoffId"].ToString());
  127.             }
  128.             if (e.CommandName == "Scrap")
  129.                 ScrapDoff(grdDynamic.DataKeys[Convert.ToInt32(e.CommandArgument)].Values["WeavingDoffId"].ToString(), Convert.ToInt32(grdDynamic.DataKeys[Convert.ToInt32(e.CommandArgument)].Values["Length"]));
  130.             BindGrid();
  131.         }
  132.         catch (Exception ex)
  133.         {
  134.             lblError.Text = ex.Message;
  135.         }
  136.     }
  137.  
  138.     protected void grdDynamic_RowEditing(object sender, GridViewEditEventArgs e)
  139.     {
  140.         grdDynamic.EditIndex = e.NewEditIndex;
  141.         BindGrid();
  142.     }
  143.  
  144.     protected void grdDynamic_RowCancelEditing(object sender, GridViewCancelEditEventArgs e)
  145.     {
  146.         grdDynamic.EditIndex = -1;
  147.         BindGrid();
  148.     }
  149.  
  150.     protected void grdDynamic_RowUpdating(object sender, GridViewUpdateEventArgs e)
  151.     {
  152.         Guid weavingDoffId = new Guid(grdDynamic.DataKeys[Convert.ToInt32(e.RowIndex)].Values["WeavingDoffId"].ToString());
  153.         //DataControlFieldCell cell = new DataControlFieldCell(grdDynamic.Rows[e.RowIndex].Cells[0]);
  154.  
  155.         grdDynamic.EditIndex = -1;
  156.         lblError.Text = "I do the update on " + e.OldValues.Count + "!  Huzzah!";
  157.         //DataControlFieldCell cell = grdDynamic.Rows[e.RowIndex].Cells[1] as DataControlFieldCell;
  158.         //grdDynamic.Columns[1].ExtractValuesFromCell(e.OldValues, cell, DataControlRowState.Edit, true);
  159.         //lblError.Text = e.OldValues[0].ToString();
  160.         //lblError.Text = grdDynamic.Rows[0].Cells[0].Controls[0].ToString();
  161.         //TextBox newBox = (TextBox)grdDynamic.Rows[0].Cells[1].Controls[0];
  162.         //lblError.Text = newBox.Text;
  163.         try
  164.         {
  165.             //UpdateLength(weavingDoffId, Convert.ToInt32(grdDynamic.DataKeys[Convert.ToInt32(e.RowIndex)].Values["Length"]));
  166.         }
  167.         catch (Exception ex)
  168.         {
  169.             lblError.Text = ex.Message;
  170.         }
  171.         BindGrid();
  172.     }
  173.  
  174.     protected void btnRefresh_Click(object sender, EventArgs e)
  175.     {
  176.         BindGrid();
  177.     }
  178. }
  179.  
The HTML is very sparse:

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head runat="server">
  7.     <title>Metals Doff Confirmation</title>
  8.     <link href="PMDStyles.css" rel="stylesheet" type="text/css" />
  9. </head>
  10. <body>
  11.     <form id="form1" runat="server">
  12.     <div style="text-align: center;">
  13.         Click here to&nbsp;
  14.         <asp:Button ID="btnRefresh" runat="server" Text="Refresh" 
  15.             onclick="btnRefresh_Click" />
  16.         &nbsp; the page.
  17.     </div>
  18.     <hr />
  19.     <div style="text-align: center;">
  20.     <div style="text-align: center;">
  21.         <asp:Label ID="lblError" runat="server"></asp:Label>
  22.     </div>
  23.     </form>
  24. </body>
  25. </html>
  26.  
The main problem I'm having is with the grdDynamic_RowU pdating subroutine. I can get the current value all I want to. The commented lines are my various attempts to read the NEW data that the user inputs. None of them will retrieve anything but the old data.

The Confirm and Scrap commands all work fine, as do my refresh and display routines. The ONLY thing that won't return is the new data.
Apr 24 '08 #6
Frinavale
9,735 Recognized Expert Moderator Expert
Well, I've got my data just fine. I just need the data, and I'll then run a stored procedure to update the values, THEN re-query it. Here's most of the code-behind. I'm still learning .NET, so it's a bit ungainly. I plan on parsing out a good bit of it to other components. It wouldn't let me post the whole thing.


The main problem I'm having is with the grdDynamic_RowU pdating subroutine. I can get the current value all I want to. The commented lines are my various attempts to read the NEW data that the user inputs. None of them will retrieve anything but the old data.

The Confirm and Scrap commands all work fine, as do my refresh and display routines. The ONLY thing that won't return is the new data.
In the future just post the portion of your code that's causing problems.
Are you doing a DataBind in your PageLoad event?
When you do this your data is bound to your grid view and your newly entered information is lost...it's quite a common occurrence to GridView update problems.

-Frinny
Apr 25 '08 #7
Akrabbim
3 New Member
I do the data bind only on the first page load. From then on, I run the data bind after the update code. Can I not run them in that order?
Apr 28 '08 #8
apaluk
1 New Member
I had exactly the same problem and finally with my colleague's help we found the mistake.
I was doing databinding in my Page_Load event and when I clicked "Update" the PostBack was done, so was the Page_Load event fired. GridView was filled with the old values again, so in myGrid.RowUpdat ing event I couldn't retrieve new values.
Jul 25 '08 #9
jagdeep gupta
98 New Member
Thanks a lot Ur Reply helps me too
Jan 24 '11 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2616
by: Nalaka | last post by:
Hi, I have two questions about gridViews. 1. How can I intercept the row/column values at loading to change values? 2. After I update a row (using default update functionality), how can I re-format the updated row fields. I have looked at gridView.rowUpdated method, but cannot figure out how....
7
14819
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I want to look at that data and filter it based on what is in it. I know that this could have been done with data sets and data views in asp.net 1.1 but how is this done now in asp.net 2.0?
7
5471
by: Ken | last post by:
Hi All - I have a filtered GridView. This GridView has a check box in the first column. This check box is used to identify specific rows for delete operations. On the button click event I loop through the filtered GridView to identify the selected rows and assemble some XML to be sent to a stored proc. The problem I have is that when looping through the GridView, it doesn't
1
3250
by: Giovanni | last post by:
Dear Friends/Gurus, I have exhausted myself and have yet no solution to the following: I have an ASP.NET 2.0 Survey type application. On a page, I have placed a GridView which is bound to an SQLDataSource. The GridView contains 3 columns: QuestionNumber, QuestionText, and a TemplateField. Each row in the GridView represents a question in a table (Ex.: "18. Satisfaction Level").
0
1830
by: Mike P | last post by:
How do you get access to the values you have entered under edit mode in a gridview? I only seem to be able to access the values prior to them being edited. protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { // 1)Convert the row index stored in the CommandArgument property to an Integer int index = e.RowIndex;
2
8992
by: Greg | last post by:
Hello, I am trying to bind a GridView to a custom object I have created. First, here is what I'm trying to do: I have a wizard for adding/editing Users. When the wizard begins, a User object (custom class) is created, and properties are populated in each step of the wizard. In one of the steps, the User is assigned to 1 or more Programs. Assigned Programs are stored by the User object in a List, and displayed in a GridView in the...
3
7336
by: pvong | last post by:
VB.NET How do you change a gridview from Update mode to normal mode? I'm usually dealing for Formviews and there is a ChangeMode option but I don't see one for Gridviews.
4
6086
by: tim.cavins | last post by:
I have a GridView populated by an ObjectDataSource. I am having issues passing the parameters to the objectdatasource. I have verified that the method is being called but none of the parameters are being populated. Integers are being passed as 0 and strings are empty regardless of what I changed them to in Edit mode on the GridView. My object method to perform the update:
1
1932
by: Joe Blauth | last post by:
Hi all, I was running into a problem with a gridview under ASP.net. What I am trying to do is binding the DataSource dynamically in a way that enables me to edit the rows in the Gridview. This is basically running alright except of the fact that when I switch to "edit" in a row inside the Gridview and edit the value and hit "update" I don't find a way to retrieve the changed values. Here's what I did: I placed a DataGrid control on my...
0
9589
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
10045
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...
0
9863
tracyyun
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...
0
8872
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...
1
7409
isladogs
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...
0
6673
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();...
0
5299
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...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2815
bsmnconsultancy
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...

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.