GridView event handler not working
-
Hi all, I'm still fighting with getting multiple lines in a dynamic gridview. Searching around led me to think that if I can change the data during the rowcreated handler this just might work.
gv2.RowCreated += new GridViewRowEventHandler(gv2_RowCreated);
gv2.DataBind();protected void gv2_RowCreated(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i < 5; i++)
{
e.Row.Cells[i].Text.Replace(Environment.NewLine, "
");
}
}Whenever I run the debugger, the new event handler line adds the handler, but never runs through the block of code. I'd imagine that during the DataBind, the rows are being created, so why isn't the system seeing this event?
"You're damned if you do, and you're damned if you dont" - Bart Simpson
-
Hi all, I'm still fighting with getting multiple lines in a dynamic gridview. Searching around led me to think that if I can change the data during the rowcreated handler this just might work.
gv2.RowCreated += new GridViewRowEventHandler(gv2_RowCreated);
gv2.DataBind();protected void gv2_RowCreated(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i < 5; i++)
{
e.Row.Cells[i].Text.Replace(Environment.NewLine, "
");
}
}Whenever I run the debugger, the new event handler line adds the handler, but never runs through the block of code. I'd imagine that during the DataBind, the rows are being created, so why isn't the system seeing this event?
"You're damned if you do, and you're damned if you dont" - Bart Simpson
itmaster21 wrote:
gv2.RowCreated += new GridViewRowEventHandler(gv2_RowCreated);
From where you are executing this ? If you want to execute Event handler of a runtime created controls, you need to add this event handler before
Page_Load()
cheers, Abhijit My Recent Article : Beginner's Guide to ASP.NET Application Folder
-
Hi all, I'm still fighting with getting multiple lines in a dynamic gridview. Searching around led me to think that if I can change the data during the rowcreated handler this just might work.
gv2.RowCreated += new GridViewRowEventHandler(gv2_RowCreated);
gv2.DataBind();protected void gv2_RowCreated(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i < 5; i++)
{
e.Row.Cells[i].Text.Replace(Environment.NewLine, "
");
}
}Whenever I run the debugger, the new event handler line adds the handler, but never runs through the block of code. I'd imagine that during the DataBind, the rows are being created, so why isn't the system seeing this event?
"You're damned if you do, and you're damned if you dont" - Bart Simpson
-
Why are you not using RowDataBound event?I think it'll fulfill you requirement.
Cheers!! Brij
I tried that first but it gave me the same results.
"You're damned if you do, and you're damned if you dont" - Bart Simpson
-
itmaster21 wrote:
gv2.RowCreated += new GridViewRowEventHandler(gv2_RowCreated);
From where you are executing this ? If you want to execute Event handler of a runtime created controls, you need to add this event handler before
Page_Load()
cheers, Abhijit My Recent Article : Beginner's Guide to ASP.NET Application Folder
Ah, maybe that's why! It's actually in the block of code that is being called from within the Page_Load().
"You're damned if you do, and you're damned if you dont" - Bart Simpson
-
Why are you not using RowDataBound event?I think it'll fulfill you requirement.
Cheers!! Brij
Brij wrote:
Why are you not using RowDataBound event?I think it'll fulfill you requirement.
No Brij, I Think, his problem is something different. He Needs add event handler before page_load.
cheers, Abhijit My Recent Article : Beginner's Guide to ASP.NET Application Folder
-
Ah, maybe that's why! It's actually in the block of code that is being called from within the Page_Load().
"You're damned if you do, and you're damned if you dont" - Bart Simpson
Well, after moving it to the Page_PreLoad the event fires but apparently replacing the element.newline with the "
" didn't do the trick. Dang!"You're damned if you do, and you're damned if you dont" - Bart Simpson
modified on Wednesday, December 17, 2008 1:01 PM
-
Brij wrote:
Why are you not using RowDataBound event?I think it'll fulfill you requirement.
No Brij, I Think, his problem is something different. He Needs add event handler before page_load.
cheers, Abhijit My Recent Article : Beginner's Guide to ASP.NET Application Folder
Hey Dude Adding a eventhandler with every row means he wants to execute some statements on every row addiotion.My answer was the same can be done using RowdataBound function with ease.
Cheers!! Brij
-
I tried that first but it gave me the same results.
"You're damned if you do, and you're damned if you dont" - Bart Simpson
-
itmaster21 wrote:
gv2.RowCreated += new GridViewRowEventHandler(gv2_RowCreated);
From where you are executing this ? If you want to execute Event handler of a runtime created controls, you need to add this event handler before
Page_Load()
cheers, Abhijit My Recent Article : Beginner's Guide to ASP.NET Application Folder
Here's the code:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Xml;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Collections;public partial class Subpgs_Warehouse_ShippingCalendar : System.Web.UI.Page
{
public Dictionary content1 = new Dictionary();protected void Page\_Preload(object sender, EventArgs e) { Generate\_Table(); } protected void Page\_Load(object sender, EventArgs e) { //Generate\_Table(); } protected void Generate\_Table() { try { using (Stream input = File.OpenRead(Server.MapPath("~/Subpgs/Data/Shipping/Calendar.binary"))) { BinaryFormatter bf = new BinaryFormatter(); content1 = (Dictionary)bf.Deserialize(input); } } catch { } int date = 0; switch (DateTime.Today.DayOfWeek.ToString()) { case "Sunday": date = -6; break; case "Monday": date = -7; break; case "Tuesday": date = -8; break; case "Wednesday": date = -9; break; case "Thursday": date = -10; break; case "Friday": date = -11; break; case "Saturday": date = -12; break; } int datelist = date; DataTable Table1 = new DataTable("last\_week"); DataTable Table2 = new DataTable("this\_week"); DataTable Table3 = new DataTable("next\_week"); DataRow dr1 = Table1.NewRow(); for (int i = 0; i < 5; i++) { Table1.Columns.Add(DateTime.Today.AddDays(date).DayOfWeek.ToString() + " " + DateTime.Today.AddDays(date).ToShortDateString(), typeof(string)); try{ dr1\[i\] = content1\[DateTime.Today.AddDays(date).ToShortDateString()\]; } catch{ dr1\[i\] = "No Data supplied"; } date++; } date += 2;
-
Hi all, I'm still fighting with getting multiple lines in a dynamic gridview. Searching around led me to think that if I can change the data during the rowcreated handler this just might work.
gv2.RowCreated += new GridViewRowEventHandler(gv2_RowCreated);
gv2.DataBind();protected void gv2_RowCreated(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i < 5; i++)
{
e.Row.Cells[i].Text.Replace(Environment.NewLine, "
");
}
}Whenever I run the debugger, the new event handler line adds the handler, but never runs through the block of code. I'd imagine that during the DataBind, the rows are being created, so why isn't the system seeing this event?
"You're damned if you do, and you're damned if you dont" - Bart Simpson
Hey Guys, I got it working. It was actually a combination of both your responses. I did have to move everything to the Page_PreLoad() and also do a RowDataBound event handler instead of RowCreated. I also had to change the event handler to this after it dawned on me that I'm replacing but not specifying that's what I want to be in the text area!
e.Row.Cells[i].Text = e.Row.Cells[i].Text.Replace(Environment.NewLine, "
");Thank's for taking the time to help me out!
"You're damned if you do, and you're damned if you dont" - Bart Simpson
-
Hey Guys, I got it working. It was actually a combination of both your responses. I did have to move everything to the Page_PreLoad() and also do a RowDataBound event handler instead of RowCreated. I also had to change the event handler to this after it dawned on me that I'm replacing but not specifying that's what I want to be in the text area!
e.Row.Cells[i].Text = e.Row.Cells[i].Text.Replace(Environment.NewLine, "
");Thank's for taking the time to help me out!
"You're damned if you do, and you're damned if you dont" - Bart Simpson
Nice to know our soluation helps you!!
cheers, Abhijit My Recent Article : Beginner's Guide to ASP.NET Application Folder