我对JavaScript有些新意。我正在使用一个名为Spread的网格控件,在该网格中我有三行和三列组合框。我还有一个原生的ASP文本框。我想要的是在文本框中显示组合框的值,一旦客户端更改了它。为此,我正在使用Spread控件的DataChanged事件。 但是,当我在本地运行并更改任何Spread的组合框中的值时,没有任何反应。
这是我的代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<FarPoint:FpSpread ID="FpSpread1" runat="server" ActiveSheetViewIndex="0"
BorderColor="Black" BorderStyle="Solid" BorderWidth="1px"
DesignString="<?xml version="1.0" encoding="utf-8"?><Spread />"
Height="200px" Width="400px">
<ClientEvents DataChanged="dataChanged" />
<commandbar backcolor="Control" buttonfacecolor="Control"
buttonhighlightcolor="ControlLightLight" buttonshadowcolor="ControlDark">
<Background BackgroundImageUrl="SPREADCLIENTPATH:/img/cbbg.gif">
</Background>
</commandbar>
<Pager Font-Bold="False" Font-Italic="False" Font-Overline="False"
Font-Strikeout="False" Font-Underline="False" />
<HierBar Font-Bold="False" Font-Italic="False" Font-Overline="False"
Font-Strikeout="False" Font-Underline="False" />
<sheets>
<FarPoint:SheetView DesignString="<?xml version="1.0" encoding="utf-8"?><Sheet><Data><RowHeader class="FarPoint.Web.Spread.Model.DefaultSheetDataModel" rows="3" columns="1"><AutoCalculation>True</AutoCalculation><AutoGenerateColumns>True</AutoGenerateColumns><ReferenceStyle>A1</ReferenceStyle><Iteration>False</Iteration><MaximumIterations>1</MaximumIterations><MaximumChange>0.001</MaximumChange></RowHeader><ColumnHeader class="FarPoint.Web.Spread.Model.DefaultSheetDataModel" rows="1" columns="4"><AutoCalculation>True</AutoCalculation><AutoGenerateColumns>True</AutoGenerateColumns><ReferenceStyle>A1</ReferenceStyle><Iteration>False</Iteration><MaximumIterations>1</MaximumIterations><MaximumChange>0.001</MaximumChange></ColumnHeader><DataArea class="FarPoint.Web.Spread.Model.DefaultSheetDataModel" rows="3" columns="4"><AutoCalculation>True</AutoCalculation><AutoGenerateColumns>True</AutoGenerateColumns><ReferenceStyle>A1</ReferenceStyle><Iteration>False</Iteration><MaximumIterations>1</MaximumIterations><MaximumChange>0.001</MaximumChange><SheetName>Sheet1</SheetName><Cells><Cell row="0" column="0"><Data type="System.String">Pippo</Data></Cell><Cell row="0" column="1"><Data type="System.String">din</Data></Cell><Cell row="0" column="2"><Data type="System.String">a</Data></Cell><Cell row="1" column="0"><Data type="System.String">pippo</Data></Cell><Cell row="1" column="1"><Data type="System.String">din</Data></Cell><Cell row="1" column="2"><Data type="System.String">a</Data></Cell><Cell row="2" column="0"><Data type="System.String">pippo</Data></Cell><Cell row="2" column="1"><Data type="System.String">din</Data></Cell><Cell row="2" column="2"><Data type="System.String">a</Data></Cell></Cells></DataArea><SheetCorner class="FarPoint.Web.Spread.Model.DefaultSheetDataModel" rows="1" columns="1"><AutoCalculation>True</AutoCalculation><AutoGenerateColumns>True</AutoGenerateColumns><ReferenceStyle>A1</ReferenceStyle><Iteration>False</Iteration><MaximumIterations>1</MaximumIterations><MaximumChange>0.001</MaximumChange></SheetCorner><ColumnFooter class="FarPoint.Web.Spread.Model.DefaultSheetDataModel" rows="1" columns="4"><AutoCalculation>True</AutoCalculation><AutoGenerateColumns>True</AutoGenerateColumns><ReferenceStyle>A1</ReferenceStyle><Iteration>False</Iteration><MaximumIterations>1</MaximumIterations><MaximumChange>0.001</MaximumChange></ColumnFooter></Data><Presentation><AxisModels><Column class="FarPoint.Web.Spread.Model.DefaultSheetAxisModel" orientation="Horizontal" count="4"><Items><Item index="-1"><SortIndicator>Ascending</SortIndicator></Item></Items></Column><RowHeaderColumn class="FarPoint.Web.Spread.Model.DefaultSheetAxisModel" defaultSize="40" orientation="Horizontal" count="1"><Items><Item index="-1"><SortIndicator>Ascending</SortIndicator><Size>40</Size></Item></Items></RowHeaderColumn><ColumnHeaderRow class="FarPoint.Web.Spread.Model.DefaultSheetAxisModel" defaultSize="22" orientation="Vertical" count="1"><Items><Item index="-1"><Size>22</Size></Item></Items></ColumnHeaderRow><ColumnFooterRow class="FarPoint.Web.Spread.Model.DefaultSheetAxisModel" defaultSize="22" orientation="Vertical" count="1"><Items><Item index="-1"><Size>22</Size></Item></Items></ColumnFooterRow></AxisModels><StyleModels><RowHeader class="FarPoint.Web.Spread.Model.DefaultSheetStyleModel" Rows="3" Columns="1"><AltRowCount>2</AltRowCount><DefaultStyle class="FarPoint.Web.Spread.NamedStyle" Parent="RowHeaderDefault" /><ConditionalFormatCollections /></RowHeader><ColumnHeader class="FarPoint.Web.Spread.Model.DefaultSheetStyleModel" Rows="1" Columns="4"><AltRowCount>2</AltRowCount><DefaultStyle class="FarPoint.Web.Spread.NamedStyle" Parent="ColumnHeaderDefault"><Background class="FarPoint.Web.Spread.Background"><BackgroundImageUrl>SPREADCLIENTPATH:/img/chbg.gif</BackgroundImageUrl><SelectedBackgroundImageUrl>SPREADCLIENTPATH:/img/chm.png</SelectedBackgroundImageUrl></Background></DefaultStyle><ConditionalFormatCollections /></ColumnHeader><DataArea class="FarPoint.Web.Spread.Model.DefaultSheetStyleModel" Rows="3" Columns="4"><AltRowCount>2</AltRowCount><DefaultStyle class="FarPoint.Web.Spread.NamedStyle" Parent="DataAreaDefault" /><ColumnStyles><ColumnStyle Index="0"><CellType class="FarPoint.Web.Spread.ComboBoxCellType"><AutoPostBack>True</AutoPostBack><ShowButton>True</ShowButton><UseValue>True</UseValue><OnClientChanged>updatedcell</OnClientChanged><Items><Item text="pippo" value="pippo" /><Item text="pluto" value="pluto" /><Item text="paperino" value="paperino" /></Items></CellType><TabStop>True</TabStop></ColumnStyle><ColumnStyle Index="1"><CellType class="FarPoint.Web.Spread.ComboBoxCellType"><AutoPostBack>True</AutoPostBack><ShowButton>True</ShowButton><UseValue>True</UseValue><Items><Item text="din" value="din" /><Item text="don" value="don" /><Item text="dan" value="dan" /></Items></CellType><TabStop>True</TabStop></ColumnStyle><ColumnStyle Index="2"><CellType class="FarPoint.Web.Spread.ComboBoxCellType"><AutoPostBack>True</AutoPostBack><ShowButton>True</ShowButton><UseValue>True</UseValue><Items><Item text="a" value="a" /><Item text="b" value="b" /><Item text="c" value="c" /></Items></CellType><TabStop>True</TabStop></ColumnStyle></ColumnStyles><CellStyles><CellStyle Row="0" Column="0"><c class="FarPoint.Web.Spread.ComboBoxCellType"><p>True</p><s>True</s><u>True</u><h><d t="Pippo" v="pippo" /><d t="Pluto " /><d t="Paperino" /></h></c><ts>True</ts></CellStyle></CellStyles><ConditionalFormatCollections /></DataArea><SheetCorner class="FarPoint.Web.Spread.Model.DefaultSheetStyleModel" Rows="1" Columns="1"><AltRowCount>2</AltRowCount><DefaultStyle class="FarPoint.Web.Spread.NamedStyle" Parent="CornerDefault"><Background class="FarPoint.Web.Spread.Background"><BackgroundImageUrl>SPREADCLIENTPATH:/img/chbg.gif</BackgroundImageUrl><SelectedBackgroundImageUrl>SPREADCLIENTPATH:/img/chm.png</SelectedBackgroundImageUrl></Background></DefaultStyle><ConditionalFormatCollections /></SheetCorner><ColumnFooter class="FarPoint.Web.Spread.Model.DefaultSheetStyleModel" Rows="1" Columns="4"><AltRowCount>2</AltRowCount><DefaultStyle class="FarPoint.Web.Spread.NamedStyle" Parent="ColumnFooterDefault" /><ConditionalFormatCollections /></ColumnFooter></StyleModels><MessageRowStyle class="FarPoint.Web.Spread.Appearance"><BackColor>LightYellow</BackColor><ForeColor>Red</ForeColor></MessageRowStyle><SheetCornerStyle class="FarPoint.Web.Spread.NamedStyle" Parent="CornerDefault"><Background class="FarPoint.Web.Spread.Background"><BackgroundImageUrl>SPREADCLIENTPATH:/img/chbg.gif</BackgroundImageUrl><SelectedBackgroundImageUrl>SPREADCLIENTPATH:/img/chm.png</SelectedBackgroundImageUrl></Background></SheetCornerStyle><AllowLoadOnDemand>false</AllowLoadOnDemand><LoadRowIncrement >10</LoadRowIncrement ><LoadInitRowCount >30</LoadInitRowCount ><AllowVirtualScrollPaging>false</AllowVirtualScrollPaging><TopRow>0</TopRow><PreviewRowStyle class="FarPoint.Web.Spread.PreviewRowInfo" /></Presentation><Settings><Name>Sheet1</Name><Categories><Appearance><GridLineColor>#d0d7e5</GridLineColor><SelectionBackColor>#eaecf5</SelectionBackColor><SelectionBorder class="FarPoint.Web.Spread.Border" /></Appearance><Behavior><EditTemplateColumnCount>2</EditTemplateColumnCount><GroupBarText>Drag a column to group by that column.</GroupBarText></Behavior><Layout><ColumnHeaderRowCount>1</ColumnHeaderRowCount><RowHeaderColumnCount>1</RowHeaderColumnCount></Layout></Categories><ActiveRow>0</ActiveRow><ActiveColumn>0</ActiveColumn><ColumnHeaderRowCount>1</ColumnHeaderRowCount><ColumnFooterRowCount>1</ColumnFooterRowCount><PrintInfo><Header /><Footer /><ZoomFactor>0</ZoomFactor><FirstPageNumber>1</FirstPageNumber><Orientation>Auto</Orientation><PrintType>All</PrintType><PageOrder>Auto</PageOrder><BestFitCols>False</BestFitCols><BestFitRows>False</BestFitRows><PageStart>-1</PageStart><PageEnd>-1</PageEnd><ColStart>-1</ColStart><ColEnd>-1</ColEnd><RowStart>-1</RowStart><RowEnd>-1</RowEnd><ShowBorder>True</ShowBorder><ShowGrid>True</ShowGrid><ShowColor>True</ShowColor><ShowColumnHeader>Inherit</ShowColumnHeader><ShowRowHeader>Inherit</ShowRowHeader><ShowColumnFooter>Inherit</ShowColumnFooter><ShowColumnFooterEachPage>True</ShowColumnFooterEachPage><ShowTitle>True</ShowTitle><ShowSubtitle>True</ShowSubtitle><UseMax>True</UseMax><UseSmartPrint>False</UseSmartPrint><Opacity>255</Opacity><PrintNotes>None</PrintNotes><Centering>None</Centering><RepeatColStart>-1</RepeatColStart><RepeatColEnd>-1</RepeatColEnd><RepeatRowStart>-1</RepeatRowStart><RepeatRowEnd>-1</RepeatRowEnd><SmartPrintPagesTall>1</SmartPrintPagesTall><SmartPrintPagesWide>1</SmartPrintPagesWide><HeaderHeight>-1</HeaderHeight><FooterHeight>-1</FooterHeight></PrintInfo><TitleInfo class="FarPoint.Web.Spread.TitleInfo"><Style class="FarPoint.Web.Spread.StyleInfo"><BackColor>#e7eff7</BackColor><HorizontalAlign>Right</HorizontalAlign></Style></TitleInfo><LayoutTemplate class="FarPoint.Web.Spread.LayoutTemplate"><Layout><ColumnCount>4</ColumnCount><RowCount>1</RowCount></Layout><Data><LayoutData class="FarPoint.Web.Spread.Model.DefaultSheetDataModel" rows="1" columns="4"><AutoCalculation>True</AutoCalculation><AutoGenerateColumns>True</AutoGenerateColumns><ReferenceStyle>A1</ReferenceStyle><Iteration>False</Iteration><MaximumIterations>1</MaximumIterations><MaximumChange>0.001</MaximumChange><Cells><Cell row="0" column="0"><Data type="System.Int32">0</Data></Cell><Cell row="0" column="1"><Data type="System.Int32">1</Data></Cell><Cell row="0" column="2"><Data type="System.Int32">2</Data></Cell><Cell row="0" column="3"><Data type="System.Int32">3</Data></Cell></Cells></LayoutData></Data><AxisModels><LayoutColumn class="FarPoint.Web.Spread.Model.DefaultSheetAxisModel" orientation="Horizontal" count="4"><Items><Item index="-1"><SortIndicator>Ascending</SortIndicator></Item></Items></LayoutColumn><LayoutRow class="FarPoint.Web.Spread.Model.DefaultSheetAxisModel" orientation="Vertical" count="1"><Items><Item index="-1" /></Items></LayoutRow></AxisModels></LayoutTemplate><LayoutMode>CellLayoutMode</LayoutMode><CurrentPageIndex type="System.Int32">0</CurrentPageIndex></Settings></Sheet>"
SheetName="Sheet1">
</FarPoint:SheetView>
</sheets>
<ClientEvents DataChanged="dataChanged" EditStopped="dataChanged" />
<TitleInfo BackColor="#E7EFF7" ForeColor="" HorizontalAlign="Center"
VerticalAlign="NotSet" Font-Size="X-Large" font-bold="False"
font-italic="False" font-overline="False" font-strikeout="False"
font-underline="False">
</TitleInfo>
</FarPoint:FpSpread>
<br />
<asp:TextBox ID="TextBox1" runat="server" BackColor="#0000CC" BorderColor="Red"
ForeColor="White" Height="16px"></asp:TextBox>
<br />
</div>
</form>
<script language="javascript" type="text/javascript">
window.onload = function () {
var spread1 = document.getElementById("FpSpread1");
if (document.all) {
// IE
if (spread1.addEventListener) {
// IE9
// spread1.addEventListener("DataChanged", dataChanged, false);
spread1.addEventListener("DataChanged", function () {return dataChanged("FpSpread1","1")}, false);
} else {
// Other versions of IE and IE9 quirks mode (no doctype set)
spread1.onDataChanged = dataChanged("FpSpread1","1");
}
else {
// Firefox
// spread1.addEventListener("DataChanged", dataChanged, false);
spread1.addEventListener("DataChanged", function () {return dataChanged("FpSpread1","1")}, false);
}
}
function dataChanged(elementID, combo) {
var tb = document.getElementById("TextBox1");
var s = document.getElementById(elementID);
tb.value = v.value;
tb.value = tb.value;
}
</script>
答案 0 :(得分:0)
ASP.NET服务器控件ID不是客户端(javascript)ID。
关于事件和一切。
所有FarPoint:FpSpread
处理都应该在C#(或VB?)代码隐藏中进行。
可以在JS中处理某些事件,但服务器控件应该以某种方式支持它。
详细了解asp.net controls