|
WebFormView如何用程式控制自行帶值的方法? |
|
|
可以使用FormView的DataBound事件來完成,如下: protected void wfvMaster_DataBound(object sender, EventArgs e) { if (wfvMaster.CurrentMode == FormViewMode.Insert) // Insert才做 { WebRefVal ctrl = (WebRefVal)wfvMaster.FindControl("WebRefVal1"); //假設名稱為WebRefVal1 ctrl.BindingValue = "001"; //設為001 WebDateTimePicker ctrl1 = (WebDateTimePicker) wfvMaster.FindControl ("WebDateTimePicker1"); ctrl1.Text = System.DateTime.Now.ToShortDateString();//如果DateTime型態 ctrl1.DateString = System.DateTime.Now.ToString("yyyyMMdd"); //如果為VarChar(8)型態. } }
|
|
|