Popular Posts
Enable SSL connection for Jsoup import org.jsoup.Connection; import org.jsoup.Jsoup; import javax.net.ssl.*; import java.io.IOException; import java.security.KeyManagement... Word break tag : <wbr/> (HTML5) The  HTML  <wbr>  tag  is  used  defines  a  potential  line  break  point  if  needed.  This  stands  for  Word  BReak. This  is  u... Build an OpenVPN server on android device Preparation An android device, in this case, Sony xperia Z is used Root permission required Linux Deploy for deploy i...
Stats
Fill zero in front of number
SQL Server:
select replicate('0', (10-len('123')))+'123'
Oracle:
SELECT LPad('123',10,'0') FROM dual
DB2:
values char(repeat('0',10-length('123'))||'123',10)
DataList paging
//利用PageDataSource來做分頁功能
PagedDataSource pds = new PagedDataSource();
//將PageDataSource綁定SqlDataSource
pds.DataSource = SqlDataSource1.Select(DataSourceSelectArguments.Empty);
pds.AllowPaging = true;
// 分頁大小
pds.PageSize = 6;

int PageIndex;
//分頁參數
if (!string.IsNullOrEmpty(Request.QueryString["Page"]) && int.TryParse(Request.QueryString["Page"], out PageIndex))
{
    PageIndex = Convert.ToInt32(Request.QueryString["Page"]);
}
else
{
    PageIndex = 1;
}

pds.CurrentPageIndex = PageIndex - 1;

// 最後一頁
if (!pds.IsLastPage)
{
    hlNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(PageIndex + 1);
    if (Request.QueryString["type"] != null) hlNext.NavigateUrl += "&type=" + Request.QueryString["type"];
}
else
{
    hlNext.Visible = false;
}


//將DataList綁定PageDataSource
this.DataList1.DataSource = pds;
this.DataList1.DataBind();
JTable : multi line cell
table.getColumnModel().getColumn(i).setCellRenderer(new DefaultTableCellRenderer() {
    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        String v = (String) value;
        String[] vs = v.split("\n");

        JPanel p = new JPanel(new GridLayout(vs.length, 1)) {
            @Override
            public void setForeground(Color fg) {
                for (int i = 0; i < getComponentCount(); i++) {
                    getComponent(i).setForeground(fg);
                }
                super.setForeground(fg);
            }

            @Override
            public void setBackground(Color bg) {
                for (int i = 0; i < getComponentCount(); i++) {
                    getComponent(i).setBackground(bg);
                }
                super.setBackground(bg);
            }
        };

        // 內容
        for (String s : vs) {
            JLabel l = new JLabel(s, JLabel.LEFT);
            l.setOpaque(true);
            p.add(l);
        }
        // 列高
        table.setRowHeight(row, table.getRowHeight() * vs.length);

        // 顏色設定
        p.setOpaque(true);
        p.setBackground(Color.white);

        // 變更背景及字體 顏色同, 同時變更內部元件的顏色
        if (isSelected) {
            p.setBackground(UIManager.getColor("Table.selectionBackground"));
            p.setForeground(UIManager.getColor("Table.selectionForeground"));
        }

        if (hasFocus) {
            p.setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));

            if (table.isCellEditable(row, column)) {
                p.setForeground(UIManager.getColor("Table.focusCellForeground"));
                p.setBackground(UIManager.getColor("Table.focusCellBackground"));
            }
        } else {
            p.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
        }

        return p;
    }
});
focus on validating
function focusOnInvalidControl() {
    for (var i = 0; i < Page_Validators.length; i++) {
        if (!Page_Validators[i].isvalid) {
            document.getElementById(Page_Validators[i].controltovalidate).focus();
            return;
        }
    }
}