I have a DetailsView bound to an EntityDataSource and am trying to get the values from my TextBoxes in the EditItemTemplates.
Here is my code:
<asp:DetailsView ID="DetailsView1" DataKeyNames="Name" runat="server" AutoGenerateRows="False"
OnDataBound="DetailsView_DataBound" DataSourceID="eds2" BorderWidth="0"
OnModeChanging="OnModeChanging" AutoGenerateEditButton="true"
OnItemUpdated="DetailsView_OnItemUpdated" OnItemUpdating="DetailsView_OnItemUpdating"
EmptyDataText="N/A" OnDataBinding="DetailsView_OnDataBinding" CellPadding="0"
CellSpacing="7" GridLines="None" CssClass="Center">
<Fields>
<asp:TemplateField HeaderText="Name">
<EditItemTemplate>
<asp:TextBox ID="txtName" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblName" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<Fields>
</asp:DetailsView>
And the code behind:
protected void OnModeChanging(object sender, DetailsViewModeEventArgs e)
{
foreach (DetailsViewRow row in DetailsView1.Rows)
{
if (row.RowType != DataControlRowType.DataRow) continue;
foreach (DataControlFieldCell cell in row.Cells)
{
var textbox = cell.FindControl("txtName");
var textbox2 = row.FindControl("txtName");
}
}
}
textbox and textbox2 are always null. What am I doing wrong? How can I get either the textbox or the value inside it?
You have these textboxes declared in your edit template. These will only show up when your mode has been set to edit. I'm guessing this hasn't happened yet when the ModeChanging event is fired.
Put your code in your ModeChanged event, and check to see that you're editing.
void DetailsView1_ModeChanged(object sender, EventArgs e)
{
if (DetailsView1.CurrentMode != DetailsViewMode.Edit)
return;
foreach (DetailsViewRow row in DetailsView1.Rows)
{
var textbox = row.FindControl("txtName");
}
}
Related
Please can someone point me in the right direction, i have a radcombobox inside the radgrid, as soon as i edit the row it loses it's value
<telerik:GridTemplateColumn DataField="SupplierRegion" UniqueName="SupplierRegion" HeaderText="Region">
<ItemTemplate>
<asp:HyperLink runat="server" ID="SupplierRegionHyperlink" Text='<%# Eval("SupplierRegion")%>'></asp:HyperLink>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadComboBox runat="server" ID="SupplierRegionRadComboBox" EnableLoadOnDemand="true" AutoPostBack="true" >
<WebServiceSettings Method="GetRegions" Path="~/WebServices/SuppliersWS.asmx"></WebServiceSettings>
</telerik:RadComboBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
and the below is my C# code
if (e.CommandName == "Edit")
{
GridEditCommandColumn editColumn = (GridEditCommandColumn)SupplierSearchGrid.MasterTableView.GetColumn("EditCommandColumn");
if (!editColumn.Visible)
editColumn.Visible = true;
GridEditableItem item = (GridEditableItem)e.Item;
RadComboBox SupplierRegionValue = (RadComboBox)item.FindControl("SupplierRegionRadComboBox");
SupplierRegionValue.SelectedValue = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["RegionID"].ToString();
SupplierRegionValue.Text = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Description"].ToString();
}
in my edit it can't seem to find the Combobox as it returns null
Take a look at topic How to bind data to radcombobox inside grid EditItemTemplate
XAML
<telerik:GridTemplateColumn DataField="SupplierRegion" UniqueName="SupplierRegion" HeaderText="Region">
<ItemTemplate>
<asp:HyperLink runat="server" ID="SupplierRegionHyperlink" Text='<%# Eval("SupplierRegion")%>'></asp:HyperLink>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadComboBox runat="server" ID="SupplierRegionRadComboBox" EnableLoadOnDemand="true" AutoPostBack="true" >
<WebServiceSettings Method="GetRegions" Path="~/WebServices/SuppliersWS.asmx"></WebServiceSettings>
</telerik:RadComboBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridEditCommandColumn FooterText="EditCommand footer" UniqueName="EditCommandColumn"
HeaderText="Edit" HeaderStyle-Width="100px" UpdateText="Update">
</telerik:GridEditCommandColumn>
C#
protected void gvSupplierRegion_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem myGridItem = (GridDataItem)e.Item;
if (myGridItem.IsInEditMode)
{
RadComboBox combo = (RadComboBox)myGridItem["SupplierRegion"].FindControl("SupplierRegionRadComboBox");
combo.DataSource = GetUploadStatus();
combo.DataTextField = "Value";
combo.DataValueField = "Key";
combo.DataBind();
combo.SelectedValue = DataBinder.Eval(myGridItem.DataItem, "UploadStatus").ToString();
}
}
so for these with the same issue i found the solution
in the aspx page add the the webservice's id and description colum id in the datakeynames, then in your radcombobox in the edititemtemplate
<telerik:GridTemplateColumn DataField="SupplierRegion" UniqueName="SupplierRegion" HeaderText="Region">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem,"Description")%>'
</ItemTemplate>
<EditItemTemplate>
<telerik:RadComboBox runat="server" ID="SupplierRegionRadComboBox" AllowCustomText="false" EnableLoadOnDemand="true" AutoPostBack="true" Text='<%#Bind("Description") %>' >
<WebServiceSettings Method="GetRegions" Path="~/WebServices/SuppliersWS.asmx"></WebServiceSettings>
</telerik:RadComboBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
and in the code behind
protected void SuppliersSearchRadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item.IsInEditMode)
{
GridEditableItem editItem = (GridEditableItem)e.Item;
RadComboBox combo = (RadComboBox)editItem.FindControl("SupplierRegionRadComboBox");
combo.SelectedValue = DataBinder.Eval(editItem.DataItem, "RegionID").ToString();
}
}
I have a GridView with Template Fields and Connection String is located in the
web.config File. Data is fetched by a stored procedure. I want to retrieve a single cell value of the Gridview in protected void someMethod(object sender, EventArgs e) on OnClick="someMethod" event. But it ends up with:
Object reference not set to an instance of an object.
Code that generates the OnClick Event:
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="someMethod">Get Name</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
The value of Gridview Cell i want to get is:
<asp:TemplateField HeaderText="Name">
<EditItemTemplate>
<asp:TextBox ID="forNames" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="eForNames" runat="server" Text = '<%# Eval("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
And Code Behind is:
protected void someMethod(object sender, EventArgs e)
{
Label ename = diplayAdapter.SelectedRow.FindControl("eForNames") as Label;
Label5.Text = ename.Text;
}
.ASPX Code:
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" CommandArgument="<%# Container.DisplayIndex %>" runat="server" CommandName="FindName">Get Name</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<EditItemTemplate>
<asp:TextBox ID="forNames" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="eForNames" runat="server" Text = '<%# Eval("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
.CS Code
protected void GridView1_OnRowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
//getting rowindex which we have selected by using CommandArgument
int rowindex = Convert.ToInt32(e.CommandArgument);
if (e.CommandName == "FindName")
{
Label5.Text= GridView1.Rows[rowindex].Cells[1].FindControl("eForNames");
}
}
catch (Exception ex)
{
Response.Write(ex);
}
}
I've a ASP.NET GridView with the following data:
Rows will be disable OnRowDataBound based on the value on column3.
GridView :
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
onrowdatabound="GridView1_RowDataBound1">
<Columns>
<asp:TemplateField HeaderText="Column1">
<ItemTemplate>
<asp:HyperLink ID="hyperlink" runat="server" Text='<% #Eval("Dosage") %>' NavigateUrl='<% #Eval("Dosage") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Column2">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<% #Eval("Drug") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Column3">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<% #Eval("Patient") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Column4">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<% #Eval("Date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
RowDataBound :
protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label a = e.Row.FindControl("Label3") as Label;
if (a.Text == "Sam")
{
e.Row.Enabled = false;
e.Row.Cells[0].Enabled = true;
}
}
}
however, I want column1 always enable, hyperlink in column1 should always clickable.
I've tried get the cells and enabled it, but it is not working.
kindly advise what is the workaround for the issue above.
You can do this by enable/disable particular cell.
protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label a = e.Row.FindControl("Label3") as Label;
if (a.Text == "Sam")
{
e.Row.Cells[0].Enabled = true;
e.Row.Cells[1].Enabled = false;
e.Row.Cells[2].Enabled = false;
e.Row.Cells[3].Enabled = false;
}
}
}
I have trying to Edit and Update my GridView in bulk.
I have generated a CheckBox in the first column of my GridView. It works something like this:
If I check a particular row in the GridView, the row gets editable.
Like this I can check as many rows I want to edit the GridView.
I have given a universal button called UPDATE, once after editing all the rows, and click on this button, the GridView is updated looping in each row checking for CheckBox.Check.
The issue I am facing here is that, when I click on any CheckBox in the GridView row, I am not getting TextBox.
I am trying to convert Label to TextBox on checking a CheckBox in the GridView.
So when I check a row, the text corresponding to Label template for that cell goes invisible according to my program, but fails to get the TextBox with the value of that cell.
The code I have tried is this:
protected void OnCheckedChanged(object sender, EventArgs e)
{
bool isUpdateVisible = false;
CheckBox chk = (sender as CheckBox);
if (chk.ID == "chkAll")
{
foreach (GridViewRow row in GridView3.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
row.Cells[0].Controls.OfType<CheckBox>().FirstOrDefault().Checked = chk.Checked;
}
}
}
CheckBox chkAll = (GridView3.HeaderRow.FindControl("chkAll") as CheckBox);
chkAll.Checked = true;
foreach (GridViewRow row in GridView3.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
bool isChecked = row.Cells[0].Controls.OfType<CheckBox>().FirstOrDefault().Checked;
for (int i = 3; i < row.Cells.Count; i++)
{
row.Cells[i].Controls.OfType<Label>().FirstOrDefault().Visible = !isChecked;
if (row.Cells[i].Controls.OfType<TextBox>().ToList().Count > 0)//this condition is not satisfying when I debug the program. what is wrong in this line?
{
row.Cells[i].Controls.OfType<TextBox>().FirstOrDefault().Visible = isChecked;
}
if (isChecked && !isUpdateVisible)
{
isUpdateVisible = true;
}
if (!isChecked)
{
chkAll.Checked = false;
}
}
}
}
UpdateGrid.Visible = isUpdateVisible;
}
The aspx code is:
<asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False"
DataKeyNames="Location_Profile_Name">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkAll" runat="server" AutoPostBack="true" OnCheckedChanged="OnCheckedChanged" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="OnCheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Location_Profile_Name" SortExpression="Location_Profile_Name">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Location_Profile_Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Home_Profile" SortExpression="Label10">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Home_Profile") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Home_Profile") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
</Columns></asp:GridView>
I have commented the issue I am facing in the program above. Kindly help.
I see that you are mixing to approaches, the Template approach (ItemTemplate, EditTemplate), and some Code-Behind approach (doing things hard-coded in code behind).
For your cenario, i sugest do it in code-behind, to get full control of the situation.
i addapted your code to explain my sugestion. Here is:
<asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkAll" runat="server" AutoPostBack="true" OnCheckedChanged="OnCheckedChanged" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="OnCheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Location_Profile_Name" SortExpression="Location_Profile_Name">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Location_Profile_Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Home_Profile" SortExpression="Label10">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Home_Profile") %>'></asp:Label>
<%--Here are the controls that edit this row, we will handle this on code-behind--%>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Home_Profile") %>' Visible="false"></asp:TextBox>
<asp:Button ID="btnSave" Text="save" runat="server" Visible="false" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The "EditTemplate" was deleted, YOU will handle your own edit template.
protected void OnCheckedChanged(object sender, EventArgs e)
{
//... Your code ...
// Here we find the controls tha we will handle
CheckBox chkAll = (GridView3.HeaderRow.FindControl("chkAll") as CheckBox);
chkAll.Checked = true;
foreach (GridViewRow row in GridView3.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
CheckBox CheckBox1 = (CheckBox)row.FindControl("CheckBox1");
Label Label2 = (Label)row.FindControl("Label2");
TextBox TextBox1 = (TextBox)row.FindControl("TextBox1");
Button btnSave = (Button)row.FindControl("btnSave");
//GridView3.SetEditRow(row.RowIndex);
if (CheckBox1 != null)
{
if (CheckBox1.Checked)
{
if (TextBox1 != null && Label2 != null)
{
// Shows your "Edit Template"
btnSave.Visible = true;
Label2.Visible = false;
TextBox1.Visible = true;
TextBox1.Text = Label2.Text;
}
}
}
}
}
}
for now, you have the control of situation :)
see this post Edit Update Delete Multiple Records
basically you need to add in your gridview
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server"
AutoPostBack="true"
OnCheckedChanged="chkSelect_CheckedChanged"/>
</ItemTemplate>
and code behind:
protected void chkSelect_CheckedChanged
(object sender, EventArgs e)
{
CheckBox chkTest = (CheckBox)sender;
GridViewRow grdRow = (GridViewRow)chkTest.NamingContainer;
TextBox txtname = (TextBox)grdRow.FindControl("txtName");
if (chkTest.Checked)
{
txtname.ReadOnly = false;
}
else
{
txtname.ReadOnly = true;
}
}
if you familiar with Jquery you can easily enable the fields also in client side
Since AutoGenerateEditButton = false, therefore there should be no for Home_Profile. The TextBox template for Home_Profile should be written within and the visibility should be set to false.
The aspx code is:
<asp:TemplateField HeaderText="Home_Profile" SortExpression="Label10">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Home_Profile") %>'></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Home_Profile") %>' Visible="false"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
i don't have the code for the way i previously did it, here is a little example using similar logic that what you did, i hope it helps
here is an working example doing it the way you did it
Code Behind
public partial class _Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("Name");
for (int i = 0; i < 10; i++)
{
DataRow dr = dt.NewRow();
dr[0] = "Test " + i;
dt.Rows.Add(dr);
}
rptITem.DataSource = dt;
rptITem.DataBind();
}
}
protected void UpdateCB(object sender, EventArgs e)
{
foreach (RepeaterItem Item in rptITem.Items)
{
CheckBox cb = (CheckBox)Item.FindControl("cbTest");
TextBox tb = (TextBox)Item.FindControl("tbTest");
Label lb = (Label)Item.FindControl("lbTest");
tb.Visible = cb.Checked;
lb.Visible = !cb.Checked;
}
}
protected void UpdateAll(object sender, EventArgs e)
{
foreach (RepeaterItem Item in rptITem.Items)
{
CheckBox cb = (CheckBox)Item.FindControl("cbTest");
TextBox tb = (TextBox)Item.FindControl("tbTest");
Label lb = (Label)Item.FindControl("lbTest");
cb.Checked = true;
tb.Visible = true;
lb.Visible = false;
}
} }
Aspx Code
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Repeater ID="rptITem" runat="server">
<HeaderTemplate>
<div style="border:1px solid black">
<div style="width:50px; float:left"><asp:CheckBox ID="cbAll" runat="server" AutoPostBack="true" OnCheckedChanged="UpdateAll" /></div>
<div style="width:200px; float:left;">Name</div>
<div style="clear:both"></div>
</div>
</HeaderTemplate>
<ItemTemplate>
<div style="width:50px; float:left"><asp:CheckBox ID="cbTest" runat="server" AutoPostBack="true" OnCheckedChanged="UpdateCB" /></div>
<div style="width:200px; float:left;"><asp:Label ID="lbTest" runat="server" Text='<%# Eval("Name") %>' ></asp:Label></div>
<div style="width:200px; float:left;"><asp:TextBox ID="tbTest" runat="server" Text='<%# Eval("Name") %>' Visible="false"></asp:TextBox></div>
</ItemTemplate>
<SeparatorTemplate>
<div style="clear:both"></div>
</SeparatorTemplate>
</asp:Repeater>
</asp:Content>
Im having trouble with my update command. It finds the textbox controls but it doesn't get the new values entered into it and i can't figure out why. i've done some tutorials and im not getting far. In my Update event is a class called Pages which updates the text and that works if i add the text values manually. The problem is accessing the newly updated text from my textboxes.
<asp:GridView ID="CustomGridView1" runat="server" AutoGenerateColumns="false" DataKeyNames="Name" AutoGenerateSelectButton="true"
ShowHeaderWhenEmpty="True" ShowFooter="true" AutoGenerateEditButton="true" OnDataBound="CustomGridView_DataBound"
OnRowEditing="CustomGridView_CancelEditCommand" OnRowCommand="CustomGridView1_RowCommand"
OnLoad="CustomGridView1_Load" OnRowUpdated="CustomGridView1_RowUpdated" OnRowUpdating="CustomGridView1_RowUpdating" OnRowCancelingEdit="CustomGridView1_RowCancelingEdit"
ShowHeader="true">
<Columns>
<asp:TemplateField HeaderText="Page Name" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<%# Eval("Name") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="Name" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Path" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<%# Eval("Path") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="Path" runat="server" Text='<%# Bind("Path") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Route Value" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<%# Eval("RouteValue") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="RouteValue" runat="server" Text='<%# Bind("RouteValue") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="RegExp" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<%# Eval("RegExp") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="RegExp" runat="server" Text='<%# Bind("RegExp") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
This part here isn't firing i prefere the method RowUpdated Method in the answer is there a reason why my Updated Event is not firing
protected void CustomGridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
if (e.Exception == null && e.AffectedRows == 1)
{
Pages pages = new Pages();
SystemPage SySPage = new SystemPage();
SySPage.Name = e.NewValues[0].ToString();
SySPage.Path = e.NewValues[1].ToString();
SySPage.RouteValue = e.NewValues[2].ToString();
SySPage.RegExp = e.NewValues[3].ToString();
pages.Update(SySPage, xmlFile);
CustomGridView1.EditIndex = -1;
BindData();
}
}
protected void CustomGridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
for (int i = 0; i < CustomGridView1.Columns.Count - 1; i++)
{
DataControlFieldCell cell = CustomGridView1.Rows[CustomGridView1.EditIndex].Cells[i] as DataControlFieldCell;
CustomGridView1.Columns[i].ExtractValuesFromCell(e.Keys, cell, DataControlRowState.Edit, false);
}
Pages pages = new Pages();
SystemPage SysPage = new SystemPage();
SysPage.Name = e.NewValues[0].ToString();
SysPage.Path = e.NewValues[1].ToString();
SysPage.RouteValue = e.NewValues[2].ToString();
SysPage.RegExp = e.NewValues[3].ToString();
pages.Update(SysPage, xmlFile);
lblInsert.Text = e.NewValues[3].ToString();
CustomGridView1.EditIndex = -1;
BindData();
}
To get the values AFTER updating you should handle the GridViews RowUpdated Event http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowupdated.aspx not the RowUpdating.
<asp:GridView OnRowUpdated="GridViewUpdatedEventHandler" />
Edit
The updated fields in the GridView are exposed by a property, NewValues, in the GridViewUpdatedEventArgs which is exposed as a parameter of the RowUpdated event.
Code as requested I cannot test this code as I am not near a dev pc.
Add the following method to your code file and set the GridViews OnRowUpdated property to point to the method.
protected void CustomGridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
if ((e.Exception == null) && (e.AffectedRows == 1))
{
Pages pages = new Pages();
SystemPage SysPage = new SystemPage();
SysPage.Name = e.NewValues[0].ToString();
SysPage.Path = e.NewValues[1].ToString();
SysPage.RouteValue = e.NewValues[2].ToString(); ;
SysPage.RegExp = e.NewValues[3].ToString(); ;
pages.Update(SysPage, xmlFile);
CustomGridView1.EditIndex = -1;
BindData();
}
else
// TO DO: ALERT the user the update errored
}