grid为某一AspxGridView
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DevExpress.Web.ASPxEditors;
using DevExpress.Web.ASPxGridView;
public partial class Default4 : System.Web.UI.Page
{
protected void Page_Init(object sender, EventArgs e)
{
for (int i = 0; i < 3;i++ )
{
GridViewDataTextColumn gvc = new GridViewDataTextColumn();
gvc.Caption = "asd";
gvc.DataItemTemplate = new ItemTemplate(i);
grid.Columns.Add(gvc);
}
}
public class ItemTemplate:ITemplate
{
int i;
public ItemTemplate(int i)
{
this.i = i;
}
public void InstantiateIn(Control container)
{
//ASPxSpinEdit tb = new ASPxSpinEdit();
////tb.Text = "lb";
//tb.ID = "tb"+i.ToString();
////tb.Text = DataBinder.Eval((container as GridViewDataItemTemplateContainer).DataItem, "GroupName ").ToString();
//tb.SpinButtons.ShowIncrementButtons = false;
//tb.Width = Unit.Pixel(50);
//tb.NumberType = SpinEditNumberType.Float;
//tb.AllowNull = true;
////tb.MinValue = 0;
//tb.MaxValue = 100;
//tb.Increment = 1;
//tb.LargeIncrement = 1;
ASPxTextBox tb = new ASPxTextBox();
tb.ID = "tb" + i.ToString();
container.Controls.Add(tb);
//tb.ValidationSettings.RegularExpression.ValidationExpression=@"(\d+\.\d*)|(\d*\.\d+)|(\d+)";
//tb.ValidationSettings.RegularExpression.ErrorText = "只能输入数字!";
//tb.ValidationSettings.ErrorDisplayMode = ErrorDisplayMode.Text;
//tb.ValidationSettings.ErrorTextPosition = DevExpress.Web.ASPxClasses.ErrorTextPosition.Bottom;
RegularExpressionValidator rv = new RegularExpressionValidator();
rv.ValidationExpression = @"(\d+\.\d*)|(\d*\.\d+)|(\d+)";
rv.Display = ValidatorDisplay.Dynamic;
rv.Text = "只能输入数字!";
rv.SetFocusOnError = false;
rv.EnableClientScript = true;
rv.ControlToValidate = tb.ID;
container.Controls.Add(rv);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
for(int i=0;i<3;i++)
{
ASPxTextBox tb = grid.FindRowCellTemplateControl(i, null, "tb0") as ASPxTextBox;
Response.Write(Convert.ToDouble(tb.Text).ToString() + "<br>");
}
}
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】博客园携手 AI 驱动开发工具商 Chat2DB 推出联合终身会员
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步