GridView databinding event handler
-
Hi All, I'm having a problem with a gridview that I am dynamically creating with my code behind. I have a multiline textbox for users to input data that is then displayed in the gridview. When the gridview databinds with the table, it is not displaying the new lines. I've found a lot of articles online showing how to fix this by setting HTMLEncode = "false", however because I'm not using any bound fields I don't think that applies for this situation. I'm thinking I might be able to resolve this by catching the text being read in from the file during the databind and doing a Text.Replace(Environment.NewLine, "
") which would display them correctly in the cells without actually modifying the saved text in my saved file on the server.GridView gv1 = new GridView();
gv1.Width = 600;
gv1.DataSource = Table1;
gv1.DataBind();gv1.HeaderRow.Height = 50; gv1.HeaderRow.BackColor = System.Drawing.Color.Black; gv1.HeaderRow.ForeColor = System.Drawing.Color.White; gv1.RowStyle.Height = 100;
Can someone give me a quick example of how I could wire this up in the code behind? Thanks!
"You're damned if you do, and you're damned if you dont" - Bart Simpson
-
Hi All, I'm having a problem with a gridview that I am dynamically creating with my code behind. I have a multiline textbox for users to input data that is then displayed in the gridview. When the gridview databinds with the table, it is not displaying the new lines. I've found a lot of articles online showing how to fix this by setting HTMLEncode = "false", however because I'm not using any bound fields I don't think that applies for this situation. I'm thinking I might be able to resolve this by catching the text being read in from the file during the databind and doing a Text.Replace(Environment.NewLine, "
") which would display them correctly in the cells without actually modifying the saved text in my saved file on the server.GridView gv1 = new GridView();
gv1.Width = 600;
gv1.DataSource = Table1;
gv1.DataBind();gv1.HeaderRow.Height = 50; gv1.HeaderRow.BackColor = System.Drawing.Color.Black; gv1.HeaderRow.ForeColor = System.Drawing.Color.White; gv1.RowStyle.Height = 100;
Can someone give me a quick example of how I could wire this up in the code behind? Thanks!
"You're damned if you do, and you're damned if you dont" - Bart Simpson
I'd imagine an onitemdatabound event handler, and you'd find the textbox in each row and replace the NewLine with a br tag.
Christian Graus Driven to the arms of OSX by Vista.
-
I'd imagine an onitemdatabound event handler, and you'd find the textbox in each row and replace the NewLine with a br tag.
Christian Graus Driven to the arms of OSX by Vista.
Hey Christian, I really like your Quote "Driven to the arms of OSX by Vista". I'm about to that point myself using Vista x64, however I might go for one of the Linux flavors ;) Do you have an example of how I would find the textbox in each row? I'm creating the gridview dynamically because the columns will change depending on the date each week.
GridView gv1 = new GridView();
gv1.Width = 600;
gv1.DataSource = Table1;
gv1.DataBind();gv1.HeaderRow.Height = 50; gv1.HeaderRow.BackColor = System.Drawing.Color.Black; gv1.HeaderRow.ForeColor = System.Drawing.Color.White; gv1.RowStyle.Height = 100; GridView gv2 = new GridView(); gv2.Width = 780; gv2.DataSource = Table2; gv2.DataBind(); switch (DateTime.Today.DayOfWeek.ToString()) { case "Monday": gv2.Rows\[0\].Cells\[0\].BackColor = System.Drawing.Color.Aqua; break; case "Tuesday": gv2.Rows\[0\].Cells\[1\].BackColor = System.Drawing.Color.Aqua; break; case "Wednesday": gv2.Rows\[0\].Cells\[2\].BackColor = System.Drawing.Color.Aqua; break; case "Thursday": gv2.Rows\[0\].Cells\[3\].BackColor = System.Drawing.Color.Aqua; break; case "Friday": gv2.Rows\[0\].Cells\[4\].BackColor = System.Drawing.Color.Aqua; break; } gv2.HeaderRow.Height = 50; gv2.HeaderRow.BackColor = System.Drawing.Color.Black; gv2.HeaderRow.ForeColor = System.Drawing.Color.White; gv2.RowStyle.Height = 175; GridView gv3 = new GridView(); gv3.Width = 600; gv3.DataSource = Table3; gv3.DataBind(); gv3.HeaderRow.Height = 50; gv3.HeaderRow.BackColor = System.Drawing.Color.Black; gv3.HeaderRow.ForeColor = System.Drawing.Color.White; gv3.RowStyle.Height = 100; Panel1.Controls.Add(gv1); Panel1.Controls.Add(gv2); Panel1.Controls.Add(gv3);
"You're damned if you do, and you're damned if you dont" - Bart Simpson