Update Event not getting new values - c#

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
}

Related

Fetching Cell Value From GridView in Custom Method ASP.NET using C#

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);
}
}

Datagrid conditional row editing based on row data

I have an ASP.NET datagrid with a few rows in it. I'd like some of the rows to be editable, but not all of them (based on a particular data item in that row).
Originally, I was doing this with a ButtonColumn, but I wasn't able to turn that on or off for specific rows.
Here's what I have now:
<asp:DataGrid ID="grid1" runat="server" AutoGenerateColumns="false" EnableViewState="true" CssClass="GridviewControlStyle" CellSpacing="0" CellPadding="4" HeaderStyle-CssClass="HeaderStyle"
OnEditCommand="grid1_EditCommand" OnUpdateCommand="grid1_UpdateCommand" OnCancelCommand="grid1_CancelCommand" OnItemDataBound="grid1d_ItemDataBound">
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<strong><%# Resources.Status %></strong>
</HeaderTemplate>
<ItemTemplate>
<%# DataBinder.Eval(Container, "DataItem.STATUS") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderTemplate>
<strong><%# Resources.Amount %></strong>
</HeaderTemplate>
<ItemTemplate>
<%# DataBinder.Eval(Container, "DataItem.AMT") %>
</ItemTemplate>
<EditItemTemplate>
<asp:CustomValidator ID="cvAmountGrid" OnServerValidate="cvAmountGrid_ServerValidate" Display="None" runat="server" ControlToValidate="txtAmount" />
<asp:TextBox ID="txtAmount" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.AMT") %>' CssClass="small" />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Button runat="server" Text="Edit" ID="btnEdit" Visible='<%# IsRowEditable(Eval("STATUS").ToString()) %>' CommandName="Edit" />
<asp:Button runat="server" Text="Update" ID="btnUpdate" Visible="false" CommandName="Update" />
<asp:Button runat="server" Text="Cancel" ID="btnCancel" Visible="false" CommandName="Cancel" />
</ItemTemplate>
</asp:TemplateColumn>
</asp:DataGrid>
Code Behind:
public bool IsRowEditable(string status)
{
return !status.Equals("Locked", StringComparison.OrdinalIgnoreCase);
}
protected void grid1_EditCommand(object source, DataGridCommandEventArgs e)
{
grid1.EditItemIndex = e.Item.ItemIndex;
grid1.DataBind();
TextBox t = e.Item.FindControl("txtAmount") as TextBox;
t.Visible = true; //this can't be found
Button b = e.Item.FindControl("btnEdit") as Button;
b.Visible = false;
Button u = e.Item.FindControl("btnUpdate") as Button;
u.Visible = true;
Button c = e.Item.FindControl("btnCancel") as Button;
c.Visible = true;
}
There are a few problems I've run into with this approach. Firstly, calling DataBind seems to reset the visibility status I've set on any buttons. If I don't databind, then my editable column doesn't show as editable. So, I try to set the textbox to be editable manually; but findcontrol returns null so I can't. What am I doing wrong here?
Another way to achieve it;
There I removed data validation and column name data binders to avoid
complexities. You can try below with them.
Update and cancel buttons are under EditItemTemplate so they will appear at edit event.
.ASPX
<asp:DataGrid ID="grid1" runat="server" AutoGenerateColumns="false" EnableViewState="true" CssClass="GridviewControlStyle" CellSpacing="0" CellPadding="4" HeaderStyle-CssClass="HeaderStyle"
OnEditCommand="grid1_EditCommand" OnUpdateCommand="grid1_UpdateCommand" OnCancelCommand="grid1_CancelCommand" OnItemDataBound="grid1d_ItemDataBound">
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<strong>Status</strong>
</HeaderTemplate>
<ItemTemplate>
<%# DataBinder.Eval(Container, "DataItem.STATUS") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderTemplate>
<strong>Amount</strong>
</HeaderTemplate>
<ItemTemplate>
<%# DataBinder.Eval(Container, "DataItem.AMT") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtAmount" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.AMT") %>' CssClass="small" ReadOnly="false"/>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Button runat="server" Text="Edit" ID="btnEdit" Visible='<%# IsRowEditable(Eval("STATUS").ToString()) %>' CommandName="Edit" />
</ItemTemplate>
<EditItemTemplate>
<asp:Button runat="server" Text="Update" ID="btnUpdate" CommandName="Update" />
<asp:Button runat="server" Text="Cancel" ID="btnCancel" CommandName="Cancel" />
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
Code Behind
There you don't have set the visibility manually. EditItemTemplate will handle it at the edit event and when the user clicks cancel or update the Edit template will be replaced with the view.
I used some hardcoded list of Data Items and you can replace it with actual data source and try.
List<DataItem> t;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadData();
}
}
private void LoadData()
{
t = new List<DataItem>();
DataItem t1 = new DataItem() { AMT = 5, STATUS = "LOCKED" };
DataItem t2 = new DataItem() { AMT = 15, STATUS = "OPEN" };
DataItem t3 = new DataItem() { AMT = 25, STATUS = "OPEN" };
DataItem t4 = new DataItem() { AMT = 35, STATUS = "LOCKED" };
t.Add(t1);
t.Add(t2);
t.Add(t3);
t.Add(t4);
grid1.DataSource = t;
grid1.DataBind();
}
protected void grid1_UpdateCommand(object sender, DataGridCommandEventArgs e)
{
string newAmount = (e.Item.Cells[1].FindControl("txtAmount") as TextBox).Text;
//Update the data source with edited data
grid1.EditItemIndex = -1;
//Load Data with updated data
LoadData();
}
protected void grid1_CancelCommand(object sender, DataGridCommandEventArgs e)
{
grid1.EditItemIndex = -1; //Bring back the previous state
LoadData();
}
public bool IsRowEditable(string status)
{
return !status.Equals("Locked", StringComparison.OrdinalIgnoreCase);
}
protected void grid1_EditCommand(object source, DataGridCommandEventArgs e)
{
grid1.EditItemIndex = e.Item.ItemIndex;
LoadData();
}
protected void grid1d_ItemDataBound(object sender, DataGridItemEventArgs e)
{
}
DataItem.cs
public class DataItem
{
public int AMT { get; set; }
public string STATUS { get; set; }
}
Okay, I figured out a better way to do this. I added the code below to my markup for all three buttons:
Visible='<%# IsRowEditing(Container.ItemIndex) %>'
In my code behind, I checked to see if the row was currently being edited, and used that to control the visibility of the buttons:
protected bool IsRowEditing(int index)
{
return index > 0 && index == grid1.EditItemIndex;
}
This fixed all my issues and was much simpler than what I was trying to do previously. Databinding also works with this method.

GridView header text not showing when binded dynamically for first time

I have a GridView, which is populated using a linq query on button click.
I have to populate the header text dynamically, fetching from the database. The first time I click the button, the header text is not binding. But, if I click on the button a second time, the header texts are bound.
Markup:
<asp:GridView ID="grdresult" runat="server" AutoGenerateColumns="false"
OnRowDataBound="grdresult_RowDataBound">
<Columns>
<asp:TemplateField HeaderStyle-Width="10%">
<ItemTemplate>
<asp:Label ID="lblCol1" runat="server" Text=' <%#Eval("Col1") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="10%">
<ItemTemplate>
<asp:Label ID="lblCol2" runat="server" Text='<%#Eval("Col2") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="10%">
<ItemTemplate>
<asp:Label runat="server" Text='<%#Eval("Col3") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="10%">
<ItemTemplate>
<asp:Label ID="lblCol4" runat="server" Text=' <%#Eval("Col4") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="10%">
<ItemTemplate>
<asp:Label ID="lblCol5" runat="server" Text='<%#Eval("Col5") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="10%">
<ItemTemplate>
<asp:Label ID="lblCol6" runat="server" Text=' <%#Eval("Col6") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="10%">
<ItemTemplate>
<asp:Label ID="lblCol7" runat="server" Text=' <%#Eval("Col7") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="10%">
<ItemTemplate>
<asp:Label ID="lblCol8" runat="server" Text=' <%#Eval("Col8") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
No Records Found
</EmptyDataTemplate>
</asp:GridView>
Codebehind:
protected void btnreport_Click(object sender, EventArgs e)
{
BindGrid();
}
protected void BindGrid()
{
var results = "LINQ select query from database";
}).Distinct().ToList();
for (int i = 0; i < grdresult.Columns.Count; i++)
{
grdresult.Columns[i].Visible = true;
}
grdresult.DataSource = results;
grdresult.DataBind();
}
protected void grdresult_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
var getColumnHeader = "LINQ query to get header text";
if (getColumnHeader != null)
{
grdresult.Columns[5].HeaderText = getColumnHeader.HCol3;
grdresult.Columns[6].HeaderText = getColumnHeader.HCol4;
grdresult.Columns[7].HeaderText = getColumnHeader.HCol5;
grdresult.Columns[8].HeaderText = getColumnHeader.HCol6;
grdresult.Columns[9].HeaderText = getColumnHeader.HCol7;
grdresult.Columns[10].HeaderText = getColumnHeader.HCol8;
grdresult.Columns[11].HeaderText = getColumnHeader.HCol9;
grdresult.Columns[12].HeaderText = getColumnHeader.HCol10;
}
}
//based on some condition i have set visibility of gridview columns
int TotalColumnCount = (int)ViewState["colcount"];
for (int i = grdresult.Columns.Count - 1; i > TotalColumnCount + 4; i--)
{
grdresult.Columns[i].Visible = false;
}
}
Instead of using the below line for binding header text
grdresult.Columns[5].HeaderText = getColumnHeader.HCol3;
i used below line which solved the issue.
e.Row.Cells[5].Text = getColumnHeader.HCol3;
This error can also occur if you are dumping an integer value into varchar() but the size of varchar is not enough. For example I was getting this error as I was cast sum() to varchar(10), and hence the error.
I changed varchar(10) to varchar(20) and the error got resolved.
In Gridview control set ClientIDMode = "Static"

How to enable column in GridView?

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;
}
}
}

Changing the footer text in GridView

I can't seem to be able to change the footer text. I've tried the sorted event as well but nothing happens. All I want to do is display status messages. Here is my code:
protected void PageSettings_Sorting(object sender, GridViewSortEventArgs e)
{
if (((GridView)sender).EditIndex > -1)
{
e.Cancel = true;
}
else
{
// tried this on sorted aswell but can't change footer text
GridViewRow row = ((GridView)sender).FooterRow as GridViewRow;
Label lblStatus = new Label{ ID="lblStatus", Text="Sorting Column <b>\"" + e.SortExpression + "\" " + e.SortDirection + "</b>"};
row.Cells[0].Text = "Hello World"; //.Controls.Add(lblStatus);
}
}
protected void PageSettings_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row != null && e.Row.RowType == DataControlRowType.Header)
{
}
else if (e.Row != null && e.Row.RowType == DataControlRowType.Footer)
{
int count = e.Row.Cells.Count;
for (int i = count - 1; i >= 1; i += -1)
{
e.Row.Cells.RemoveAt(i);
}
e.Row.Cells[0].ColumnSpan = count;
e.Row.Cells[0].Controls.Add(new Literal { ID = "lblStatus" });
// can't FindControl or change Literals either
e.Row.Cells[0].Text = "Hello World"; // works here but not on sorting event
}
}
<asp:GridView ID="PageSettings" runat="server"
AllowPaging="true" AllowSorting="true"
AutoGenerateColumns="false"
AutoGenerateDeleteButton="true"
AutoGenerateEditButton="true"
ShowFooter="true"
DataSourceID="ObjectDataSourcePages"
OnLoad="PageSettings_Load"
OnRowDataBound="PageSettings_DataBound"
OnRowCreated="PageSettings_RowCreated"
OnRowEditing="PageSettings_RowEditing"
OnRowCancelingEdit="PageSettings_RowCancelingEdit"
OnPageIndexChanging="PageSettings_PageIndexChanging"
OnSorting="PageSettings_Sorting"
OnSorted="PageSetting_Sorted"
PageSize="2">
<Columns>
<asp:TemplateField HeaderText="Page Name" HeaderStyle-HorizontalAlign="Left" SortExpression="Name">
<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" SortExpression="Path">
<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" SortExpression="RouteValue">
<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" SortExpression="RegExp">
<ItemTemplate>
<%# Eval("RegExp") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="RegExp" runat="server" Text='<%# Bind("RegExp") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
This will change the text of the first FooterRow cell:
protected void gv_Sorting(object sender, GridViewSortEventArgs e)
{
gv.FooterRow.Cells[0].Text = "Hello";
}
Of course you'll need to make sure your GridView's ShowFooter property is true.
Or alternatively, by casting sender and adding a control:
protected void Sorting(object sender, GridViewSortEventArgs e)
{
Label label = new Label();
label.Text = gv_s.Rows.Count.ToString() + " records";
((GridView)sender).FooterRow.Cells[0].Controls.Add(label);
}

Categories