Forms Data Controls :: Why Wasn't GridView's RowDataBound Event Fired

Apr 21, 2010

Why wasn't my GridView's RowDataBound event fired? I have a masterpage on whick i have a query button, and I have a content page on which i have a customized GridView(named cgvEmployees,derived from GridView). The logic is when user click the button, the button click event triggered that search the underlying database and populate the GridView.

Everything runs great except that RowDataBound event isn't triggered. Because I have to change some cells' representations in RowDataBound event handler. I have surfed so much pages to find the answer but failed. Below is what i have already done:

1. set the autoeventwireup to true;
2. i have a cgvEmployees.bind() sentence in the button click event handler;
3. i have OnRowDataBound="cgvEmployees_OnRowDataBound" in the content page GridView tag attribute

by the way, the database query is coded by Linq Dynamic Query (please google 'dynamic Linq').

void Master_QueryButton_Click(object sender, EventArgs e)
{
RetiredEmployeeDataContext db = new RetiredEmployeeDataContext();
NameValueCollection nvcQueryKeyValue = getNVCQueryKeyValue();
Expression<Func<RetiredEmployee, bool>> searchPredicate = getLambdaExpr(nvcQueryKeyValue);
IQueryable<RetiredEmployee> retireds = db.RetiredEmployees;
Expression expr = Expression.Call(typeof(Queryable), "Where",
new Type[] { typeof(RetiredEmployee) }, Expression.Constant(retireds), searchPredicate);
IQueryable<RetiredEmployee> query = db.RetiredEmployees.AsQueryable().Provider.CreateQuery<RetiredEmployee>(expr);
List<RetiredEmployee> employeeList = new List<RetiredEmployee>(query);
List<RetiredEmployeeEO> employees = new List<RetiredEmployeeEO>();
foreach (RetiredEmployee employee in employeeList)
{
RetiredEmployeeEO employeeEO = new RetiredEmployeeEO();
employeeEO.MapEntityToProperties(employee);
employees.Add(employeeEO);
}
cgvEmployees1.ListClassName = typeof(RetiredEmployeeEOList).AssemblyQualifiedName;
cgvEmployees1.LoadMethodName = "LoadFromQuery";
cgvEmployees1.LoadMethodParameters.Clear();
cgvEmployees1.LoadMethodParameters.Add(employees);
cgvEmployees1.DataBind();
}
protected void cgvEmployees1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//Add the edit link to the action column.
HyperLink editLink = new HyperLink();
if (((BasePage)this.Page).ReadOnly)
{
editLink.Text = "View";
}
else
{
editLink.Text = "Edit";
}
editLink.NavigateUrl = "employee.aspx" + EncryptQueryString("id=" + ((RetiredEmployeeEO)e.Row.DataItem).ID.ToString());
if(e.Row.Cells[0].Controls.Count==0)
e.Row.Cells[0].Controls.Add(editLink);
//Add checkbox to display the isactive field.
CheckBox chkActive = new CheckBox();
chkActive.Checked = ((RetiredEmployeeEO)e.Row.DataItem).liveOrDead;
chkActive.Enabled = false;
if(e.Row.Cells[24].Controls.Count==0)
e.Row.Cells[24].Controls.Add(chkActive);
if (((RetiredEmployeeEO)e.Row.DataItem).gender.Equals((byte)1))
e.Row.Cells[2].Text = "Male";
else
e.Row.Cells[2].Text = "Female";
if (((RetiredEmployeeEO)e.Row.DataItem).retiredOr.Equals((byte)1))
e.Row.Cells[14].Text = "Retired1";
else
e.Row.Cells[14].Text = "Retired2";
if (((RetiredEmployeeEO)e.Row.DataItem).birthday.Equals("1753-01-01"))
e.Row.Cells[3].Text = "";
if (((RetiredEmployeeEO)e.Row.DataItem).dayToEmployed.Equals("1753-01-01"))
e.Row.Cells[6].Text = "";
if (((RetiredEmployeeEO)e.Row.DataItem).dayRetired.Equals("1753-01-01"))
e.Row.Cells[7].Text = "";
if (((RetiredEmployeeEO)e.Row.DataItem).dayParty.Equals("1753-01-01"))
e.Row.Cells[13].Text = "";
if (((RetiredEmployeeEO)e.Row.DataItem).daytoassign.Equals("1753-01-01"))
e.Row.Cells[17].Text = "";
}
}

View 22 Replies


Similar Messages:

Forms Data Controls :: The Gridview Fired Event RowEditing Which Wasn't Handled

Aug 5, 2010

I've got a gridview that returns student order history which works just fine. It pulls the StudentId from a hidden field on page load. I have a link button that ADDS AN ORDER when clicked. It calls a stored procedure, inserts the record, then rebinds the gridview and displays the new record at the top of the list.

Problem is when I go to EDIT it, i get this error... "The GridView 'GridViewOrderHistory' fired event RowEditing which wasn't handled." But the interesting thing is the error doesn't occur if I close the browser and reload the page and then click on that new record that was created. Obviously I'm missing something in my code when the new order is created. Here are the 2 subs involved in the process.

[Code]....

View 8 Replies

Forms Data Controls :: Update Record - Gridview Fired Event RowEditing Which Wasn't Handled

Dec 20, 2010

I am populating the gridview on the basis of listbox selection . However, I am setting the datasource in the click event after listbox entry. When i am trying to update any record in the gridview this error gets thrown because the datasourceid from the aspx page has been removed. Code for reference -

protected void btn_save_Click(object sender, EventArgs e)
{
ArrayList list = new ArrayList();
foreach (object o in ListBox2.Items)
{
list.Add(o);
}
string str2 = null, str, host;
string str1 = "SELECT SYSTEMNAME, DATETIME, PDOWNTIME, UDOWNTIME, SYSDOWNMINS, REASON FROM PLANNED_DOWNTIME where ";
host = Convert.ToString(list[0]);
str2 = " ( SYSTEMNAME like '" + host + "'";
for (int i = 1; i < list.Count; i++)
{
host = Convert.ToString(list[i]);
str2 = str2 + " or SYSTEMNAME LIKE'" + host + "'";
}
str = str1 + str2 + " )";
string connectstring = "Data Source=SRCPA035\ovops;Initial Catalog=reporter;Persist Security Info=True;User ID=sa;Password=ril123";
DataTable dt = new DataTable();
SqlConnection connection = new SqlConnection(connectstring);
try
{
connection.Open();
SqlCommand sqlCmd = new SqlCommand(str, connection);
SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
sqlDa.Fill(dt);
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
GridView1.DataSource = SqlDataSource1;
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Fetch Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
connection.Close();
}
}

View 6 Replies

Data Controls :: GridView 1 Fired Event Row Deleting Which Wasn't Handled

Dec 26, 2012

i have a problem in my gridview control,actually i am having a gridview and bind the gridview with the database,in that gridview i provide a link button called delete,when i click the delete button its shows an error,after reloading the page the current record is deleted,but whenever the delete button is pressed its shows the following error..The GridView 'GridView1' fired event RowDeleting which wasn't handled.but whenever i reload the project the record will be deleted,here is my code

<asp:GridView runat="server" AutoGenerateColumns="false" ID="GridView1"> <Columns>  
<asp:BoundField DataField="empname" HeaderText="EMPLOYEE NAME"  SortExpression="empname" />   
<asp:TemplateField> <ItemTemplate>                   
<asp:LinkButton runat="server" ID="lnkDelete" Text="Delete" CommandName="delete"     

[code]....

View 1 Replies

Forms Data Controls :: GridView's RowDataBound Event Fired Twice?

Apr 20, 2010

I have a very simple asp.net page, just some buttons and one GridView on it. The logic is a user click the QUery button,then the button click event was trigured to populate the gridview with data queried from database via LINQ. for a user friendly interface, in RowDataBound event, I visit every row, change a boolean value into checkbox represention. But it seem that the RowDataBound run twice, because the checkboxs were inserted twice for every row in one cell. so why? the source code snippet as follow:

protected void btnSelect_Click(object sender, EventArgs e)
{
RetiredEmployeeDataContext db = new RetiredEmployeeDataContext();
GridView1.DataSource = db.ENTUserAccountSelectAll();//userAccounts;
GridView1.DataBind();
}
protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
CheckBox chkActive = new CheckBox();
chkActive.Checked = ((ENTUserAccount)e.Row.DataItem).IsActive;
chkActive.Enabled = false;
e.Row.Cells[5].Controls.Add(chkActive);
}
}

View 9 Replies

Forms Data Controls :: The GridView "gridData" Fired Event PageIndexChanging Which Wasn't Handled

Feb 11, 2011

I Read This [URL] but when i click next page mygird be Empty and blank

<asp:GridView ID="grdData" runat="server" AutoGenerateColumns="False" GridLines="None"

View 1 Replies

Forms Data Controls :: The GridView "GridView1" Fired Event Sorting Which Wasn't Handled

Mar 23, 2010

I googled and found this post : [URL] I have never had this problem b4. I just started a new job, do i need a service pack update or something?

DataTable dt;
DbCommand cmd = GenericDataAccess.CreateCommand_SP("rptPlannedActivity");
GenericDataAccess.AddParameter(cmd, "@Outstanding", DbType.Int16, 1);
GenericDataAccess.AddParameter(cmd, "@Period", DbType.Int16, 45);
dt = GenericDataAccess.ExecuteSelectCommand(cmd);
GridView1.DataSource = dt ;
GridView1.DataBind();

View 3 Replies

Forms Data Controls :: Error - Gridview Fired Event "Sorting" Which Wasn't Handled Using Visual Studio 2008

Feb 21, 2010

I have a gridview in an update panel which is declared in an ASPX page, and bound to a SQLDataSource in code. The gridview's 'allowsorting' attribute is set to true, and because it is bound to a SQLDataSource, I expect the sorting to be automatically handled.

Yet I am getting the "Message: Sys.WebForms.PageRequestManagerServerErrorException: The GridView 'grdStatusItems' fired event Sorting which wasn't handled" error. I am using Visual Studio 2008, IE8, IIS7. What am I doing wrong? I have done anextensive search for this error, but it seems in most cases where this error occurs, the people are not using a SQLDatasource, so have to handle the sorting event themselves. Is this the case here? Here is the updatepanel and gridview declaration in the aspx file:

[Code]....

View 1 Replies

Forms Data Controls :: Gridview / Adding CheckBox In RowDataBound - CheckedChanged Event Not Fired - Page Lifecycle

Jan 5, 2011

I have a page on which everything is loaded dynamically.

There is a Gridview (AutoGenerateColumns=true) and in the RowDataBound I check every column for a boolean datatype. If found I add a checkbox (autopostback=true) to the cell and register the CheckedChanged event.
The problem is, that I only get the CheckedChanged event, if I reload the grid in Page_Load:

protected void Page_Load(object sender, EventArgs e) {
LoadGrid();
}

But this is very expensive and causes that the db request will be executed twice. If I changed the code to what I want:

protected void Page_Load(object sender, EventArgs e) {
if (!this.IsPostBack)
loadGrid();
}

I get no CheckedChanged event.

Is there a possibility to get:

- Adding a Checkbox in RowDataBound
- Only "LoadGrid()" if it is no PostBack
- Getting the CheckedChanged event of the relevant row

View 2 Replies

Forms Data Controls :: GridView1 Fired Event PageIndexChanging Which Wasn't Handled

Feb 8, 2011

GridView1 fired event PageIndexChanging which wasn't handled

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class View_Project : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["USERNAME"] == null)
{
Response.Redirect("Home.aspx");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
fillgrid();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
fillgrid();
}
private void fillgrid()
{
if (TextBox1.Text == "*")
{
SqlCommand cmd;
SqlConnection con = new SqlConnection("Data Source=SUNTECH-812ECD7\SQLEXPRESS;Initial Catalog=suntech;Integrated Security=True;");
cmd = new SqlCommand("Select * from " + DropDownList3.SelectedItem + " where project_name like '" + TextBox1.Text + "'");
con.Open();
cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
else
{
SqlCommand cmd;
SqlConnection con = new SqlConnection("Data Source=SUNTECH-812ECD7\SQLEXPRESS;Initial Catalog=suntech;Integrated Security=True;");
cmd = new SqlCommand("Select * from " + DropDownList3.SelectedItem + " where project_name like '" + TextBox1.Text + "'");
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
}
}

View 4 Replies

Forms Data Controls :: GridView1 On First Page Fired Event PageIndexChanging Which Wasn't Handled

Feb 8, 2011

I am getting this error when click on page no 2 of grid view on first page it is working correctly My source code of grid view is

<asp:GridView ID="GridView1" runat="server" Width="738px" CellPadding="4" ForeColor="#333333" AllowPaging="True" >
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
And c# code is
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Time_keeping_system : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private void Page_PreInit(object sender, EventArgs e)
{
if (Session["USERNAME"] == null)
{
this.MasterPageFile = "MasterPage.master";
}
else
{
this.MasterPageFile = "MasterPage2.master";
}
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
//TextBox1.Text = Calendar1.SelectedDate.ToShortDateString();
TextBox1.Text = Calendar1.SelectedDate.ToString("dd/MM/yyyy");
}
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "*")
{
SqlCommand cmd;
SqlConnection con = new SqlConnection("Data Source=SUNTECH-812ECD7\SQLEXPRESS;Initial Catalog=suntech;Integrated Security=True;");
cmd = new SqlCommand("select ld.username, ld.login_date,ld.login_time,wp.Project_Id,wp.Project_Of,wp.Project_Name,wp.Start_time,wp.end_time, bd.break_for,bd.break_time,bd.break_over_time,l.logout_time from login_details ld inner join working_projects
wp on ld.login_date= wp.Date join break_details bd on ld.login_date = bd.login_date join logout l on bd.login_date= l.logout_date where ld.username ='" + DropDownList1.SelectedValue + "'");
//cmd = new SqlCommand("Select * from " + DropDownList3.SelectedItem + " where project_name like ''" + TextBox1.Text + "''");
//cmd.ExecuteNonQuery();
con.Open();
cmd.Connection = con;
//SqlDataReader reader = cmd.ExecuteReader();
//GridView1.DataSource = reader;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
// reader.Close();
}
else
{
SqlCommand cmd;
SqlConnection con = new SqlConnection("Data Source=SUNTECH-812ECD7\SQLEXPRESS;Initial Catalog=suntech;Integrated Security=True;");
cmd = new SqlCommand("select ld.username, ld.login_date,ld.login_time,wp.Project_Id,wp.Project_Of,wp.Project_Name,wp.Start_time,wp.end_time, bd.break_for,bd.break_time,bd.break_over_time,l.logout_time from login_details ld inner join working_projects
wp on ld.login_date= wp.Date join break_details bd on ld.login_date = bd.login_date join logout l on bd.login_date= l.logout_date where ld.username = '" + DropDownList1.SelectedValue + "' AND ld.login_date = '" + TextBox1.Text + "'");
//cmd = new SqlCommand("Select * from " + DropDownList3.SelectedItem + " where project_name like ''" + TextBox1.Text + "''");
//cmd.ExecuteNonQuery();
con.Open();
cmd.Connection = con;
//SqlDataReader reader = cmd.ExecuteReader();
//GridView1.DataSource = reader;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
// reader.Close();
}
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
}

View 10 Replies

Forms Data Controls :: Default Sort "The GridView "GridView1" Fired Event Sorting Which Wasn't Handled

Feb 19, 2010

I have a page displays CRM data (with CrmService) in GridView. Everything run ok until I tried to sort out one field by default and I received the following exception: The GridView 'GridView1' fired event Sorting which wasn't handled. The reason I am using GridView to do the sorting because:

1) Cannot do it with SQL "ORDER BY" since date retrieval from CRM Web Service

2) Cannot use OrderExpression for QueryExpression from CRM because the column I want to sort is generated by my algorithm

GridView1.Sort("ColumnName" SortDirection.Descending);
in Page_Load, or Button1_Sort(object sender, GridViewSortEventArgs e), they all trigger the above execption!

I also added the method to the following method to handle exception, but didn't work:

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
GridView1.Sort("ColumnName" SortDirection.Descending);
}

View 2 Replies

Cancel Row In Grid View The GridView 'GridView1' Fired Event RowCancelingEdit Which Wasn't Handled?

Oct 27, 2010

this error apear when I try to cancel row in grid view The GridView 'GridView1' fired event RowCancelingEdit which wasn't handled

View 3 Replies

Forms Data Controls :: Gridview RowDataBound Event Fires On Every Command Event?

Jul 19, 2010

why the gridview RowDataBound event fires during a select command. I only expect it to run when the gridview is being populated with data. Is there some way to stop it from running when the select command is triggered?

View 3 Replies

Forms Data Controls :: RowDataBound Event Of Gridview Not Firing

Feb 17, 2010

protected void grdMain_RowDataBound(object sender, GridViewRowEventArgs e)
{
}
<asp:GridView ID="grdMain"
runat="server"
OnRowDataBound="grdMain_RowDataBound"

View 6 Replies

Forms Data Controls :: Gridview RowDataBound Event - Set Default Value

May 17, 2010

When a Gridview row is in edit, I need to default an empty textbox to today's date. I am close, but the defaulted date is is not saved to the database. I can key in the date and the date is displayed and saved to the database. Even more interesting:

1. The date is defaulted to - 5/17/2010
2. If I erase the month and key the "5" back in the data is not saved.
3. If I erase the month and then change the month to "6", the data is saved to the database. If any value is changed in the date the save works.

[Code]....

View 6 Replies

Forms Data Controls :: Cannot Linq In Gridview RowDataBound Event

Mar 16, 2010

I use linq query as below and bind it to listview. I have 2 label control (name,remain).I want to check in code behind if p.count<200 then remain ="Sample text1"if price <300 then "sample text2".I know that I could do it before linq in gridview RowDataBound event

Dim prod= From p In db.products _
Select New With {p.name p.category, p.count}
postlist.DataSource = prod
postlist.DataBind()

View 1 Replies

Forms Data Controls :: Get The DataKey Value In RowDataBound Event For GridView?

Feb 22, 2010

How to get the DataKey value in RowDataBound event for GridView

View 3 Replies

Forms Data Controls :: How To Format E.Row.DataItem In RowDataBound Event Of GridView Using C#

Mar 3, 2010

I am NOT formatting at DECLARATIVE time

The following code works perfectly

[Code]....

Can I directly format e.RowDataItem.

I don't want to format by using e.Row.Cells[4].Text

View 3 Replies

Forms Data Controls :: Access GridView PageIndex In Rowdatabound Event?

Feb 5, 2010

How do I access GridView Page Index in RowDataBound event? I am assigning PageIndex to hyperlink on the gridview, for this I was planning to use "GridView1.PageIndex" in rowdatabound event. Problem is when I got second page in gridview (10 rows per page), the first row in the page shows page index as "0" and from second row it becomes 1. And if I goto third page, the first row in the page shows page index as "1" and from second row it becomes 2.

View 13 Replies

Forms Data Controls :: Rowdatabound Event Of A Gridview Loses Its Value While Editing?

Feb 5, 2011

I have a Gridview with edit and update feature enabled. It displays the data correctly but when I click on the Edit linkbutton(to edit the data), I get the error "Object reference not set to an instance of an object".

I tried debugging and found that the row which I click (say editindex is 1) loses its value. I could identify this while debugging the code, when the code flow moves to the rowdatabound event, the label (or for that matter any control in the rowdatabound event) shows a null value and eventually errors out.

I am unable to figure out as to why the control specified in the rowdatabound event loses its value when editing. Note: The lost valueow data is the one which I tried editing.

I am attaching the code which I have written for the rowdatabound event.

[Code]....

View 6 Replies

Forms Data Controls :: Calling A Javascript Function In RowDatabound Event Of The Gridview?

Feb 4, 2010

Can I call a javascript function in the RowDatabound event of the Gridview?

I am currently enabling/disabling buttons in each of my gridview rows based on a status value from the database.I need to fire a javascript function (say alert('current status')) when the status is 0,else dont fire that function.Can I achieve this in the row databound event?

View 9 Replies

Forms Data Controls :: Add Duration Total In Gridview Foot Using Timespan And Rowdatabound Event

Dec 19, 2010

I want to have a total in the gridview footer of the duration of the employees. As the rowdatabound goes through the cycles I can see it reading the correct times from each row but it is not totalling in totalTime and I get 0:00:00 in the footer.

[Code]....

View 2 Replies

Data Controls :: RowDataBound Event In GridView

Aug 18, 2015

How to generate "Gridview1.row_bound" event in gridview?

View 1 Replies

Forms Data Controls :: Gridview Status Column Data Bind In RowDataBound Event

Mar 7, 2010

I have database status field Bit(0/1) this values binding to gridview column. i want to show record status instead of 0 and 1 display open or close

View 5 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved