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
9 15086
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.selectedRows(0).Cells(0).Value.ToString
TextBox.Text = grid.selectedRows(0).Cells(0).Value.ToString
Thank You!
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#.
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
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. -
protected void InitDataTable(DataTable dt)
-
{
-
DataColumn dcol = new DataColumn("Doff Number", typeof(System.Int64));
-
dt.Columns.Add(dcol);
-
dcol = new DataColumn("Length", typeof(System.Int64));
-
dt.Columns.Add(dcol);
-
dcol = new DataColumn("Doff Length", typeof(System.Int64));
-
dt.Columns.Add(dcol);
-
dcol = new DataColumn("Start Time", typeof(System.DateTime));
-
dt.Columns.Add(dcol);
-
dcol = new DataColumn("End Time", typeof(System.DateTime));
-
dt.Columns.Add(dcol);
-
dcol = new DataColumn("WeavingDoffId", typeof(System.Guid));
-
dt.Columns.Add(dcol);
-
}
-
-
protected void LoadDataTable(DataTable dt)
-
{
-
CMetalsWeavingDoffs cmwd = new CMetalsWeavingDoffs();
-
-
LoadMetalsWeavingDoffs(cmwd);
-
foreach (SMetalsWeavingDoffs smwd in cmwd)
-
{
-
DataRow drow = dt.NewRow();
-
drow["Doff Number"] = smwd.WeavingDoffNumber;
-
drow["Length"] = smwd.Length;
-
drow["Doff Length"] = GetDoffLength(smwd.WorkOrderActualId);
-
drow["Start Time"] = smwd.StartTime;
-
drow["End Time"] = smwd.EndTime;
-
drow["WeavingDoffId"] = smwd.WeavingDoffId;
-
dt.Rows.Add(drow);
-
}
-
}
-
-
protected void InitGrid(DataTable dt)
-
{
-
ButtonField confirmField = new ButtonField();
-
ButtonField scrapField = new ButtonField();
-
CommandField editField = new CommandField();
-
-
if (!Page.IsPostBack)
-
{
-
foreach (DataColumn col in dt.Columns)
-
{
-
BoundField bfield = new BoundField();
-
bfield.DataField = col.ColumnName;
-
bfield.HeaderText = col.ColumnName;
-
if (bfield.DataField != "WeavingDoffId")
-
grdDynamic.Columns.Add(bfield);
-
if (bfield.DataField != "Length")
-
bfield.ReadOnly = true;
-
}
-
confirmField.HeaderText = "Confirm";
-
confirmField.Text = "Confirm";
-
confirmField.CommandName = "Confirm";
-
confirmField.ButtonType = ButtonType.Button;
-
grdDynamic.Columns.Add(confirmField);
-
scrapField.HeaderText = "Scrap";
-
scrapField.Text = "Scrap";
-
scrapField.CommandName = "Scrap";
-
scrapField.ButtonType = ButtonType.Button;
-
grdDynamic.Columns.Add(scrapField);
-
editField.HeaderText = "Edit";
-
editField.EditText = "Edit Length";
-
editField.UpdateText = "Update";
-
editField.CancelText = "Cancel";
-
editField.ButtonType = ButtonType.Button;
-
editField.ShowEditButton = true;
-
editField.CausesValidation = false;
-
grdDynamic.Columns.Add(editField);
-
-
}
-
grdDynamic.DataSource = dt;
-
grdDynamic.DataBind();
-
}
-
-
protected void CreateGrid()
-
{
-
string[] dataKeyNames = new string[2];
-
-
grdDynamic.AutoGenerateColumns = false;
-
grdDynamic.SkinID = "MainGridView";
-
grdDynamic.RowCommand += new GridViewCommandEventHandler(grdDynamic_RowCommand);
-
grdDynamic.RowEditing += new GridViewEditEventHandler(grdDynamic_RowEditing);
-
grdDynamic.RowCancelingEdit += new GridViewCancelEditEventHandler(grdDynamic_RowCancelEditing);
-
grdDynamic.RowUpdating += new GridViewUpdateEventHandler(grdDynamic_RowUpdating);
-
dataKeyNames[0] = "WeavingDoffId";
-
dataKeyNames[1] = "Length";
-
if (!Page.IsPostBack)
-
grdDynamic.DataKeyNames = dataKeyNames;
-
Page.Form.Controls.Add(grdDynamic);
-
}
-
-
protected void BindGrid()
-
{
-
DataTable dt = new DataTable();
-
-
try
-
{
-
InitDataTable(dt);
-
LoadDataTable(dt);
-
InitGrid(dt);
-
}
-
catch(Exception ex)
-
{
-
lblError.Text += ex.Message;
-
}
-
}
-
-
protected void Page_Load(object sender, EventArgs e)
-
{
-
Response.Expires = -1600;
-
lblError.Text = string.Empty;
-
CreateGrid();
-
if (!Page.IsPostBack)
-
BindGrid();
-
}
-
-
protected void grdDynamic_RowCommand(object sender, GridViewCommandEventArgs e)
-
{
-
try
-
{
-
if (e.CommandName == "Confirm")
-
{
-
ConfirmDoff(grdDynamic.DataKeys[Convert.ToInt32(e.CommandArgument)].Values["WeavingDoffId"].ToString(), Convert.ToInt32(grdDynamic.DataKeys[Convert.ToInt32(e.CommandArgument)].Values["Length"]));
-
ConfirmDoffOld(grdDynamic.DataKeys[Convert.ToInt32(e.CommandArgument)].Values["WeavingDoffId"].ToString());
-
}
-
if (e.CommandName == "Scrap")
-
ScrapDoff(grdDynamic.DataKeys[Convert.ToInt32(e.CommandArgument)].Values["WeavingDoffId"].ToString(), Convert.ToInt32(grdDynamic.DataKeys[Convert.ToInt32(e.CommandArgument)].Values["Length"]));
-
BindGrid();
-
}
-
catch (Exception ex)
-
{
-
lblError.Text = ex.Message;
-
}
-
}
-
-
protected void grdDynamic_RowEditing(object sender, GridViewEditEventArgs e)
-
{
-
grdDynamic.EditIndex = e.NewEditIndex;
-
BindGrid();
-
}
-
-
protected void grdDynamic_RowCancelEditing(object sender, GridViewCancelEditEventArgs e)
-
{
-
grdDynamic.EditIndex = -1;
-
BindGrid();
-
}
-
-
protected void grdDynamic_RowUpdating(object sender, GridViewUpdateEventArgs e)
-
{
-
Guid weavingDoffId = new Guid(grdDynamic.DataKeys[Convert.ToInt32(e.RowIndex)].Values["WeavingDoffId"].ToString());
-
//DataControlFieldCell cell = new DataControlFieldCell(grdDynamic.Rows[e.RowIndex].Cells[0]);
-
-
grdDynamic.EditIndex = -1;
-
lblError.Text = "I do the update on " + e.OldValues.Count + "! Huzzah!";
-
//DataControlFieldCell cell = grdDynamic.Rows[e.RowIndex].Cells[1] as DataControlFieldCell;
-
//grdDynamic.Columns[1].ExtractValuesFromCell(e.OldValues, cell, DataControlRowState.Edit, true);
-
//lblError.Text = e.OldValues[0].ToString();
-
//lblError.Text = grdDynamic.Rows[0].Cells[0].Controls[0].ToString();
-
//TextBox newBox = (TextBox)grdDynamic.Rows[0].Cells[1].Controls[0];
-
//lblError.Text = newBox.Text;
-
try
-
{
-
//UpdateLength(weavingDoffId, Convert.ToInt32(grdDynamic.DataKeys[Convert.ToInt32(e.RowIndex)].Values["Length"]));
-
}
-
catch (Exception ex)
-
{
-
lblError.Text = ex.Message;
-
}
-
BindGrid();
-
}
-
-
protected void btnRefresh_Click(object sender, EventArgs e)
-
{
-
BindGrid();
-
}
-
}
-
The HTML is very sparse: -
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
-
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head runat="server">
-
<title>Metals Doff Confirmation</title>
-
<link href="PMDStyles.css" rel="stylesheet" type="text/css" />
-
</head>
-
<body>
-
<form id="form1" runat="server">
-
<div style="text-align: center;">
-
Click here to
-
<asp:Button ID="btnRefresh" runat="server" Text="Refresh"
-
onclick="btnRefresh_Click" />
-
the page.
-
</div>
-
<hr />
-
<div style="text-align: center;">
-
<div style="text-align: center;">
-
<asp:Label ID="lblError" runat="server"></asp:Label>
-
</div>
-
</form>
-
</body>
-
</html>
-
The main problem I'm having is with the grdDynamic_RowUpdating 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.
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_RowUpdating 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
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?
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.RowUpdating event I couldn't retrieve new values.
Thanks a lot Ur Reply helps me too
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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.
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |