Dart Home | PowerWEB LiveControls for ASP.NET | Custom Development | Reply | PowerWEB LiveControls for ASP.NET Topics | Forums |
Author | Forum: PowerWEB LiveControls for ASP.NET Topic: LiveDataGrid.SelectedIndex |
steveevets steve@wharfedata.co.uk From: Leeds, United Kingdom Posts: 5 Member Since: 03/08/06 |
posted March 9, 2006 8:11 AM Hello, I'm having problems with the LiveDataGrid.SelectedIndex property, I have a LiveDataGrid dg1 which gets bound on PageLoad, then never rebound. I have two LiveButtons btnUp and btnDown which I use to change the dg1.SelectedIndex. The current index is held in a LiveLable lblIndex. dg1.SelectedItemStyle is set to Red so I can keep track of it. In PageLoad dg1 is bound, & it's SelectedIndex is set to 0. The grid looks good, with only the top row (Row 0) red. When btnDown is pressed for the first time, we see only Row 1 as red, (good). When btnDown is pressed again however both Row 0 and Row 1 as red (bad I think). Could you help me with this? Regards Steve <%@ Page language="c#" Codebehind="TestDataGrid.aspx.cs" AutoEventWireup="false" Inherits="TSTracks.TestDataGrid" %> <%@ Register TagPrefix="cc1" Namespace="Dart.PowerWEB.LiveControls" Assembly="Dart.PowerWEB.LiveControls" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>TestDataGrid</title> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <cc1:LiveDataGrid id="dg1" style="Z-INDEX: 101; LEFT: 80px; POSITION: absolute; TOP: 144px" runat="server"> <AlternatingItemStyle BackColor="#80FFFF"></AlternatingItemStyle> <ItemStyle BackColor="#C0FFC0"></ItemStyle> <SelectedItemStyle BackColor="Red"></SelectedItemStyle> </cc1:LiveDataGrid> <cc1:LiveButton id="btnUp" style="Z-INDEX: 102; LEFT: 448px; POSITION: absolute; TOP: 216px" runat="server" Text="Up"></cc1:LiveButton> <cc1:LiveButton id="btnDown" style="Z-INDEX: 103; LEFT: 328px; POSITION: absolute; TOP: 216px" runat="server" Text="Down"></cc1:LiveButton> <cc1:LiveLabel id="lblIndex" style="Z-INDEX: 104; LEFT: 280px; POSITION: absolute; TOP: 144px" runat="server">0</cc1:LiveLabel> </form> </body> </HTML> using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Data; namespace TSTracks { /// <summary> /// Summary description for TestDataGrid. /// </summary> public class TestDataGrid : System.Web.UI.Page { protected Dart.PowerWEB.LiveControls.LiveDataGrid dg1; protected Dart.PowerWEB.LiveControls.LiveButton btnUp; protected Dart.PowerWEB.LiveControls.LiveButton btnDown; protected Dart.PowerWEB.LiveControls.LiveLabel lblIndex; private void Page_Load(object sender, System.EventArgs e) { System.Data.DataTable _DT = new System.Data.DataTable("Table"); _DT.Columns.Add("Col1"); for(int i = 0; i < 10; i++) { System.Data.DataRow _DR = _DT.NewRow(); _DR["Col1"] = "Row " + i.ToString(); _DT.Rows.Add(_DR); } dg1.DataSource = _DT; dg1.DataBind(); dg1.SelectedIndex = 0; } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.btnUp.Click += new System.EventHandler(this.btnUp_Click); this.btnDown.Click += new System.EventHandler(this.btnDown_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void btnDown_Click(object sender, System.EventArgs e) { int _Index = int.Parse(lblIndex.Text); _Index ++; dg1.SelectedIndex = _Index; lblIndex.Text = _Index.ToString(); } private void btnUp_Click(object sender, System.EventArgs e) { int _Index = int.Parse(lblIndex.Text); _Index --; lblIndex.Text = _Index.ToString(); dg1.SelectedIndex = _Index; } } } |
steveevets steve@wharfedata.co.uk From: Leeds, United Kingdom Posts: 5 Member Since: 03/08/06 |
posted March 9, 2006 9:21 AM OOps I forgot to check for IsPostBack. Sorry for wasting anyones time. Steve |
steveevets steve@wharfedata.co.uk From: Leeds, United Kingdom Posts: 5 Member Since: 03/08/06 |
posted March 9, 2006 9:58 AM Hey I was too hasty, OK I made a beginners mistake, but how can the LiveDataGrid display more than one SelectedItem? Regards Steve |
John Talarico![]() From: Rome, NY USA Posts: 630 Member Since: 06/01/05 |
posted March 9, 2006 4:13 PM This appears to be a side effect of rebinding and setting the index in each Page_Load. Each callback (including the Button_Click) is going to fire Page_Load again, rebinding the grid and setting the SelectedIndex, then in the event handler the SelectedIndex is fired again. This is causing conflicting scripts to be generated, resulting in what appears to be multiple selected rows. In reality, only one index is selected, but the client elements are out of sync. |
steveevets steve@wharfedata.co.uk From: Leeds, United Kingdom Posts: 5 Member Since: 03/08/06 |
posted March 10, 2006 4:31 AM Hi and thanks for the reply, The above code is just a toy to try & simply reproduce a problem I am having in a real app that I am looking to convert to using your controls. The real problem is that in certain circumstances the LiveDataGrid does not show the correct row as selected (the previously selected row remains highlit). This occurs after a rebind. I have been unable to reproduce the real problem in simple demo, but I thought that what I am seeing here is possibly related. I have altered the toy code so that every postback does a bind in Page_Load, but the SelectedIndex is only altered in the callback event. This fixes the problem in the toy app. I now need help to fix my realworld app...are you saying that the SelectedIndex should only be set once per page cycle to avoid this problem? If so that seems a difficult condition to enforce! Is there a recomended order to choosing the SelectedIndex, ie before or after binding. Looking at my real world code I see that I normally set the SelectedIndex to -1 as a default, then after binding I conditionally set the SelectedIndex to what I want it to be. Please advise me on this Steve |
John Talarico![]() From: Rome, NY USA Posts: 630 Member Since: 06/01/05 |
posted March 10, 2006 9:12 AM No, I didn't mean to imply that setting the SelectedIndex multiple times in a callback will result in multiple rows highlighted. I only meant that it appears that combining a re-bind with setting the SelectedIndex can be an issue. If you can get another sample together that demonstrates what your real-world app does, we'll take a look at it. |
steveevets steve@wharfedata.co.uk From: Leeds, United Kingdom Posts: 5 Member Since: 03/08/06 |
posted March 10, 2006 10:02 AM Hi, I've tried in vain to reproduce my real world problem in a toy. The best I can do is send you the source sent to the browser when it has misbehaved, so you can finger any conflicting script or other problem. Ive been through my code & put breakpoints on all changes to the SelectedIndex, & binds to the view & can see nothing wrong at all. Regards Steve |
Reply | PowerWEB LiveControls for ASP.NET Topics | Forums |
This site is powered by
![]() |