1個Gridview,數據是從Excel中讀出來的.Excel中有幾欄它是這樣寫的.
L1   L2    ……
01   02
02   03
10   01
我查了查網上的資料,發現這樣寫沒效果,數字前面的0毅然沒有去掉,請問誰有這方面的經驗,教一下。<asp:TemplateField HeaderText="L1">
                        <ItemTemplate>
                            <asp:TextBox ID="txtL1" Width="20px" Text='<%#DataBinder.Eval(Container.DataItem,"L1","{0:N0}")%>' runat="server"></asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>
OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn);
            DataSet myDataSet = new DataSet();
            myCommand.Fill(myDataSet);
            dt = myDataSet.Tables[0];

解决方案 »

  1.   

    因为在excel中,这个列是文本列,所以这个格式化对它是没有用的,自己用模板列写个函数格式化吧
      

  2.   

    打开excel文件,选中这一列,Ctrl+1 将单元格式格式设为数字也可.
      

  3.   

    THX,問題已解決,模板列調用后臺轉型函數,方法供后人:<asp:TemplateField HeaderText="L1">
                            <ItemTemplate>
                                <asp:TextBox ID="txtL1" Width="20px" Text='<%# FormatStr(DataBinder.Eval(Container.DataItem,"L1").ToString())%>' runat="server"></asp:TextBox>
                            </ItemTemplate>
                        </asp:TemplateField>
    public string FormatStr(string oldStr)
        {
            string newStr = "";
            try
            {
                newStr = int.Parse(oldStr).ToString();
            }
            catch (Exception ex)
            {
                newStr = ex.Message;
            }
            return newStr;
        }