cancel
Showing results for 
Search instead for 
Did you mean: 

SAP.Web.UI.Controls.Table.LeadSelectEventArgs

Former Member
0 Kudos

For the LeadSelect event of a SAP table, when I go to next page and try to access the "Col" and "Row" properties I get the "Index was out of range" error.

How can I keep the "Row" with the page number in sync? Is there a SAP table equivalent of "PageIndexChanged" event for ASP.NET's DataGrid?

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

can you specify in more detail how you filled the table?

Regards,

Ofer

Former Member
0 Kudos

Hello,

I create a dataset and bind that to the datasource of the table. By handling the Table1_LeadSelect event, I can access the "Row" and "Col" properties for the first page of data displayed in the table. When I go to the next page the problem occurs.

Thanks Ofer.

Former Member
0 Kudos

Hi Yakima,

This shouldn't be happening. Make sure that when the page posts back there is data in the table, whether the post back is caused due to paging or selection. This means that there should be data in your dataset and also that you called "DataBind" on the table (or page). The best way to ensure this is to do this code in the page load.

If you're still having problems maybe you can post your code here (relevant ascx + relevant cs/vb code).

Regards,

Ofer

Former Member
0 Kudos

Thank you Ofer. Appreciate your help.

-


using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.UI;

using SAP.Portal.Web.UI;

using SAP.UI;

using SAP.Web.UI.Controls;

namespace TestSamples

{

public class google : SAP.Portal.Web.UI.PortalComponent

{

protected SAP.Web.UI.Controls.Table Table1;

protected SAP.Web.UI.Controls.Caption caption1;

protected SAP.Web.UI.Controls.TableRow Table1_ItemTemplate;

protected System.Data.DataSet dataSet1;

protected System.Data.DataTable dataTable1;

protected SAP.Web.UI.Controls.TextView textView1;

protected SAP.Web.UI.Controls.TextView textView2;

protected SAP.Web.UI.Controls.TextView textView3;

protected SAP.Web.UI.Controls.TextView textView4;

protected SAP.Web.UI.Controls.TextView textView5;

protected SAP.Web.UI.Controls.TextView textView6;

protected System.Data.DataColumn title;

protected System.Data.DataColumn summary;

protected System.Data.DataColumn URL;

protected System.Data.DataColumn snippet;

protected System.Data.DataColumn cachedSize;

protected SAP.Web.UI.Controls.Button btnSearch;

protected SAP.Web.UI.Controls.InputField InputFieldSearchText;

protected SAP.Web.UI.Controls.TableCell Table1_title;

protected SAP.Web.UI.Controls.TableCell Table1_summary;

protected SAP.Web.UI.Controls.TableCell Table1_URL;

protected SAP.Web.UI.Controls.TableCell Table1_snippet;

protected SAP.Web.UI.Controls.TableCell Table1_cachedSize;

protected SAP.Web.UI.Controls.TableCell Table1_relatedInformationPresent;

protected System.Web.UI.WebControls.Panel PanelDetail;

protected SAP.Web.UI.Controls.Label Label1;

protected SAP.Web.UI.Controls.Label Label2;

protected SAP.Web.UI.Controls.Label Label3;

protected SAP.Web.UI.Controls.Button Button1;

protected SAP.Web.UI.Controls.InputField InputFieldTitle;

protected SAP.Web.UI.Controls.InputField InputFieldSummary;

protected SAP.Web.UI.Controls.InputField InputFieldURL;

protected SAP.Web.UI.Controls.Button Button2;

protected System.Data.DataColumn relatedInformationPresent;

private void Page_Load(object sender, System.EventArgs e)

{

if (Session["SearchDataSet"] == null)

dataSet1 = PhysicalRead();

else

{

dataSet1 = (DataSet)Session["SearchDataSet"];

}

Table1.DataBind();

}

private DataSet PhysicalRead()

{

Response.Write("physical read");

ViewState["SearchText"] = InputFieldSearchText.Value;

kickapoo.Chumash r = new kickapoo.Chumash();

DataSet ds = r.GoogleSearch(InputFieldSearchText.Value);

Session["SearchDataSet"] = ds;

return ds;

}

#region Web Form Designer generated code

protected override 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.dataSet1 = new System.Data.DataSet();

this.dataTable1 = new System.Data.DataTable();

this.title = new System.Data.DataColumn();

this.summary = new System.Data.DataColumn();

this.URL = new System.Data.DataColumn();

this.snippet = new System.Data.DataColumn();

this.cachedSize = new System.Data.DataColumn();

this.relatedInformationPresent = new System.Data.DataColumn();

((System.ComponentModel.ISupportInitialize)(this.dataSet1)).BeginInit();

((System.ComponentModel.ISupportInitialize)(this.dataTable1)).BeginInit();

//

// dataSet1

//

this.dataSet1.DataSetName = "NewDataSet";

this.dataSet1.Locale = new System.Globalization.CultureInfo("en-US");

this.dataSet1.Tables.AddRange(new System.Data.DataTable[] {

this.dataTable1});

//

// dataTable1

//

this.dataTable1.Columns.AddRange(new System.Data.DataColumn[] {

this.title,

this.summary,

this.URL,

this.snippet,

this.cachedSize,

this.relatedInformationPresent});

this.dataTable1.TableName = "Table1";

//

// title

//

this.title.ColumnName = "title";

//

// summary

//

this.summary.ColumnName = "summary";

//

// URL

//

this.URL.ColumnName = "URL";

//

// snippet

//

this.snippet.ColumnName = "snippet";

//

// cachedSize

//

this.cachedSize.ColumnName = "cachedSize";

//

// relatedInformationPresent

//

this.relatedInformationPresent.ColumnName = "relatedInformationPresent";

this.Table1.Sort += new SAP.Web.UI.Controls.Table.SortEventHandler(this.Table1_Sort);

this.Table1.LeadSelect += new SAP.Web.UI.Controls.Table.LeadSelectEventHandler(this.Table1_LeadSelect);

this.btnSearch.Action += new SAP.Web.UI.Controls.AbstractButton.ActionEventHandler(this.btnSearch_Action);

this.Button2.Action += new SAP.Web.UI.Controls.AbstractButton.ActionEventHandler(this.Button2_Action);

this.Load += new System.EventHandler(this.Page_Load);

((System.ComponentModel.ISupportInitialize)(this.dataSet1)).EndInit();

((System.ComponentModel.ISupportInitialize)(this.dataTable1)).EndInit();

}

#endregion

private void btnSearch_Action(object sender, SAP.Web.UI.Controls.AbstractButton.ActionEventArgs e)

{

if (ViewState["SearchText"].ToString()!=InputFieldSearchText.Value.ToString())

dataSet1 = PhysicalRead();

}

private void Table1_Sort(object sender, SAP.Web.UI.Controls.Table.SortEventArgs e)

{

IBindingList bl = e.DataSource as IBindingList;

if (bl != null && bl.SupportsSorting && bl.Count > 0)

bl.ApplySort(TypeDescriptor.GetProperties(bl[0])[e.SortColumn.Title], e.SortDirection);

}

private void Table1_LeadSelect(object sender, SAP.Web.UI.Controls.Table.LeadSelectEventArgs e)

{

Response.Write("col" + e.Col.ToString() + "row" + e.Row.ToString());

//TableRowCollection rc = Table1.ItemTemplate[e.Row];

TableRow r = Table1.Items[e.Row];

Response.Write(r.Key);

ShowDetail(true);

}

private void ShowDetail(bool show)

{

PanelDetail.Visible = show;

}

private void Button2_Action(object sender, SAP.Web.UI.Controls.AbstractButton.ActionEventArgs e)

{

ShowDetail(false);

}

}

}

-


<%@ Register TagPrefix="sap" Namespace="SAP.Web.UI.Controls" Assembly="SAP.Web, Version=1.2.0.0, Culture=neutral, PublicKeyToken=50436dca5c7f7d23" %>

<%@ Control language="c#" Codebehind="google.ascx.cs" AutoEventWireup="false" Inherits="CookieSamples.google" targetSchema="http://schemas.microsoft.com/intellisense/ie5" %>

<!%@ PortalComponent name="google" %>

<LINK href="C:\Program Files\SAP\Portal Add-in for Visual Studio 2003\Controls\ur\ur_design.css"

type="text/css" rel="stylesheet">

<body class="prtlBody">

<P>

<sap:InputField id="InputFieldSearchText" runat="server"></sap:InputField>

<sap:Button id="btnSearch" runat="server" Text="Search"></sap:Button></P>

<P>

<sap:Table id=Table1 runat="server" VisibleRowCount="4" DataSource="<%# dataSet1 %>" SelectionMode="SINGLE" FillUpEmptyRows="False">

<sap:Caption Text="Google Search Result" ID="caption1"></sap:Caption>

<sap:TableRow ID="Table1_ItemTemplate" Key='<%# DataBinder.Eval(target.DataSourceRow.DataItem, "title") %>'>

<sap:TableCell ID="Table1_title" Title="title">

<sap:TextView ID="textView1" Wrapping="True" Text='<%# DataBinder.Eval(Container.Parent, "DataSourceRow.DataItem.title") %>'>

</sap:TextView>

</sap:TableCell>

<sap:TableCell ID="Table1_summary" Title="summary">

<sap:TextView ID="textView2" Wrapping="True" Text='<%# DataBinder.Eval(Container.Parent, "DataSourceRow.DataItem.summary") %>'>

</sap:TextView>

</sap:TableCell>

<sap:TableCell ID="Table1_URL" Title="URL">

<sap:TextView ID="textView3" Wrapping="True" Text='<%# DataBinder.Eval(Container.Parent, "DataSourceRow.DataItem.URL") %>'>

</sap:TextView>

</sap:TableCell>

<sap:TableCell ID="Table1_snippet" Visibility="NONE" Title="snippet">

<sap:TextView ID="textView4" Text='<%# DataBinder.Eval(Container.Parent, "DataSourceRow.DataItem.snippet") %>'>

</sap:TextView>

</sap:TableCell>

<sap:TableCell ID="Table1_cachedSize" Title="cachedSize">

<sap:TextView ID="textView5" Text='<%# DataBinder.Eval(Container.Parent, "DataSourceRow.DataItem.cachedSize") %>'>

</sap:TextView>

</sap:TableCell>

<sap:TableCell ID="Table1_relatedInformationPresent" Visibility="NONE" Title="relatedInformationPresent">

<sap:TextView ID="textView6" Text='<%# DataBinder.Eval(Container.Parent, "DataSourceRow.DataItem.relatedInformationPresent") %>'>

</sap:TextView>

</sap:TableCell>

</sap:TableRow>

</sap:Table></P>

<P>

<asp:Panel id="PanelDetail" runat="server" Visible="False">

<TABLE id="Table2" cellSpacing="1" cellPadding="1" width="300" border="1">

<TR>

<TD>

<sap:Label id="Label1" runat="server" Text="Title"></sap:Label></TD>

<TD>

<sap:InputField id="InputFieldTitle" runat="server"></sap:InputField></TD>

</TR>

<TR>

<TD>

<sap:Label id="Label2" runat="server" Text="Summary"></sap:Label></TD>

<TD>

<sap:InputField id="InputFieldSummary" runat="server"></sap:InputField></TD>

</TR>

<TR>

<TD>

<sap:Label id="Label3" runat="server" Text="URL"></sap:Label></TD>

<TD>

<sap:InputField id="InputFieldURL" runat="server"></sap:InputField></TD>

</TR>

<TR>

<TD colSpan="2" align="center">

<sap:Button id="Button1" runat="server" Text="Update"></sap:Button>

<sap:Button id="Button2" runat="server" Text="Cancel"></sap:Button></TD>

</TR>

</TABLE>

</asp:Panel></P>

</body>

Former Member
0 Kudos

Hi Yakima,

Now I see the problem.

The Col and Row properties of the event parameter are ok. They tell you the absolute col and row number.

The "problem" is with the Tables Items colection. When databound, the table optimizes it's creation of rows... it doesn't create TableRow items for every item in the dataset (which might be catastrophic in memory and performance), instead it only creates them for those items currently displayed.

So the items collection will only contain the displayed rows!

So instead of

TableRow r = Table1.Items[e.Row];

do this:

TableRow r = Table1.Items[e.Row - Table1.FirstVisibleRow];

That should work.

Note that if you want access to items that are not displayed, use the dataset itself.

Regards,

Ofer

P.S: you could have seen this yourself if you debugged your code... (see in the help "Debugging a Portal Component" - https://media.sdn.sap.com/html/submitted_docs/PDK_for_dotNET_10/Programming%20with%20PDK%20for%20.NE...

Former Member
0 Kudos

Have you filled the PDK for .NET survey yet? You can win an MP3 player!!!

http://feedback.sap.com/efs/vote?campaign=39c7899ecca40a6709a638bd0388ac8b&org=332

Answers (0)