你这个需求,可以通过下面的方法来实现:
后台代码
- protected void Page_Load(object sender, EventArgs e)
- {
- if (IsPostBack)
- {
- return;
- }
- FpSpread1.ActiveSheetView.AllowPage = false;
- FpSpread1.ActiveSheetView.RowCount = 5;
- FpSpread1.ActiveSheetView.ColumnCount = 7;
- FpSpread1.ActiveSheetView.Columns[1].Visible = false;
- FpSpread1.ActiveSheetView.Columns[3].Visible = false;
- StringBuilder sb = new StringBuilder();
-
- for (int i = 0; i < FpSpread1.ActiveSheetView.Columns.Count; i++)
- {
- sb.AppendFormat("{0}:{1},", FpSpread1.ActiveSheetView.Columns[i].Label,i);
- }
- HiddenField1.Value = sb.ToString().TrimEnd(new char[]{','});
- }
复制代码
前台代码:
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- <script language="javascript" type="text/javascript">
- function Button1_onclick() {
- var columnname = "B";
- var hv = document.getElementById("HiddenField1").value;
- var columns = hv.split(",");
- for (var i = 0; i < columns.length; i++) {
- var column = columns[i].split(":");
- if (column[0] == columnname) {
- alert(columnname + "的索引值为:" + column[1].toString());
- }
- }
- }
- </script>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <input id="Button1" type="button" value="button" onclick="return Button1_onclick()" />
- <asp:HiddenField ID="HiddenField1" runat="server" />
- <FarPoint:FpSpread ID="FpSpread1" runat="server" BorderColor="Black"
- BorderStyle="Solid" BorderWidth="1px" Height="304px" Width="602px">
- <commandbar backcolor="Control" buttonfacecolor="Control"
- buttonhighlightcolor="ControlLightLight" buttonshadowcolor="ControlDark">
- </commandbar>
- <sheets>
- <FarPoint:SheetView SheetName="Sheet1">
- </FarPoint:SheetView>
- </sheets>
- </FarPoint:FpSpread>
- </div>
- </form>
- </body>
- </html>
复制代码 |