ASP.NET程序中常用的三十三种代码(3)
2007-02-07 22:29
357 查看
21.读取DataGrid控件TextBox值
foreach(DataGrid dgi in yourDataGrid.Items) { TextBox tb = (TextBox)dgi.FindControl("yourTextBoxId"); tb.Text.... } |
〖思归〗
<asp:TemplateColumn HeaderText="数量"> <ItemTemplate> <asp:TextBox id="ShuLiang" runat=’server’ Text=’<%# DataBinder.Eval(Container.DataItem,"DG_ShuLiang")%>’ onkeyup="javascript:DoCal()" /> <asp:RegularExpressionValidator id="revS" runat="server" ControlToValidate="ShuLiang" ErrorMessage="must be integer" ValidationExpression="^/d+$" /> </ItemTemplate> </asp:TemplateColumn> <asp:TemplateColumn HeaderText="单价"> <ItemTemplate> <asp:TextBox id="DanJian" runat=’server’ Text=’<%# DataBinder.Eval(Container.DataItem,"DG_DanJian")%>’ onkeyup="javascript:DoCal()" /> <asp:RegularExpressionValidator id="revS2" runat="server" ControlToValidate="DanJian" ErrorMessage="must be numeric" ValidationExpression="^/d+(/./d*)?$" /> </ItemTemplate> </asp:TemplateColumn> <asp:TemplateColumn HeaderText="金额"> <ItemTemplate> <asp:TextBox id="JinE" runat=’server’ Text=’<%# DataBinder.Eval(Container.DataItem,"DG_JinE")%>’ /> </ItemTemplate> </asp:TemplateColumn><script language="javascript"> function DoCal() { var e = event.srcElement; var row = e.parentNode.parentNode; var txts = row.all.tags("INPUT"); if (!txts.length || txts.length < 3) return; var q = txts[txts.length-3].value; var p = txts[txts.length-2].value; if (isNaN(q) || isNaN(p)) return; q = parseInt(q); p = parseFloat(p); txts[txts.length-1].value = (q * p).toFixed(2); } </script> |
page_load page.smartNavigation=true |
private void DataGrid1_ItemDataBound(obj sender,DataGridItemEventArgs e) { for(int i=0;i<e.Item.Cells.Count-1;i++) if(e.Item.ItemType==ListItemType.EditType) { e.Item.Cells[i].Attributes.Add("Width", "80px") } } |
private static string ScriptBegin = "<script language=/"JavaScript/">"; private static string ScriptEnd = "</script>"; public static void ConfirmMessageBox(string PageTarget,string Content) { string ConfirmContent="var retValue=window.confirm(’"+Content+"’);"+"if(retValue){window.location=’"+PageTarget+"’;}"; ConfirmContent=ScriptBegin + ConfirmContent + ScriptEnd; Page ParameterPage = (Page)System.Web.HttpContext.Current.Handler; ParameterPage.RegisterStartupScript("confirm",ConfirmContent); //Response.Write(strScript); } |
1.1 取当前年月日时分秒
currentTime=System.DateTime.Now; |
int 年= DateTime.Now.Year; |
int 月= DateTime.Now.Month; |
int 日= DateTime.Now.Day; |
int 时= DateTime.Now.Hour; |
int 分= DateTime.Now.Minute; |
int 秒= DateTime.Now.Second; |
int 毫秒= DateTime.Now.Millisecond; |
先定义变量 :
public static int pageCount; //总页面数 public static int curPageIndex=1; //当前页面 |
if(DataGrid1.CurrentPageIndex < (DataGrid1.PageCount - 1)) { DataGrid1.CurrentPageIndex += 1; curPageIndex+=1; } bind(); // DataGrid1数据绑定函数 |
if(DataGrid1.CurrentPageIndex >0) { DataGrid1.CurrentPageIndex += 1; curPageIndex-=1; } bind(); // DataGrid1数据绑定函数 |
int a=int.Parse(JumpPage.Value.Trim());//JumpPage.Value.Trim()为跳转值 if(a<DataGrid1.PageCount) { this.DataGrid1.CurrentPageIndex=a; } bind(); |
添加删除确认:
private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { foreach(DataGridItem di in this.DataGrid1.Items) { if(di.ItemType==ListItemType.Item||di.ItemType==ListItemType.AlternatingItem) { ((LinkButton)di.Cells[8].Controls[0]).Attributes.Add("onclick","return confirm(’确认删除此项吗?’);"); } } } |
ListItemType itemType = e.Item.ItemType; if (itemType == ListItemType.Item ) { e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor=’#FFFFFF’;"; e.Item.Attributes["onmouseover"] = "javascript:this.style.backgroundColor=’#d9ece1’;cursor=’hand’;" ; } else if( itemType == ListItemType.AlternatingItem) { e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor=’#a0d7c4’;"; e.Item.Attributes["onmouseover"] = "javascript:this.style.backgroundColor=’#d9ece1’;cursor=’hand’;" ; } |
DataTable dt= c.ExecuteRtnTableForAccess(sqltxt); //执行sql返回的DataTable DataColumn dc=dt.Columns.Add("number",System.Type.GetType("System.String")); for(int i=0;i<dt.Rows.Count;i++) { dt.Rows[i]["number"]=(i+1).ToString(); } DataGrid1.DataSource=dt; DataGrid1.DataBind(); |
private void CheckBox2_CheckedChanged(object sender, System.EventArgs e) { foreach(DataGridItem thisitem in DataGrid1.Items) { ((CheckBox)thisitem.Cells[0].Controls[1]).Checked=CheckBox2.Checked; } } |
foreach(DataGridItem thisitem in DataGrid1.Items) { if(((CheckBox)thisitem.Cells[0].Controls[1]).Checked) { string strloginid= DataGrid1.DataKeys[thisitem.ItemIndex].ToString(); Del (strloginid); //删除函数 } } |
在Application_Start中添加以下代码:
Application["ConnStr"]=this.Context.Request.PhysicalApplicationPath+ConfigurationSettings. AppSettings["ConnStr"].ToString(); |
相关文章推荐
- ASP.NET 程序中常用的三十三种代码
- ASP.NET程序中常用的三十三种代码
- ASP.NET程序中常用的三十三种代码
- ASP.NET程序中常用的三十三种代码
- ASP.NET 程序中常用的三十三种代码[收藏]
- ASP.NET程序中常用的三十三种代码 (三)
- ASP.NET程序中常用的三十三种代码(转)
- ASP.NET 程序中常用的三十三种代码(二)
- ASP.NET程序中常用的三十三种代码
- ASP.NET程序中常用的三十三种代码
- ASP.NET程序中常用的三十三种代码
- ASP.NET程序中常用的三十三种代码(四)
- ASP.NET 程序中常用的三十三种代码
- ASP.NET程序中常用的三十三种代码(1)
- ASP.NET程序中常用的三十三种代码
- ASP.NET程序中常用的三十三种代码
- ASP.NET 程序中常用的三十三种代码
- ASP.NET程序中常用的三十三种代码(1-10)
- ASP.NET 程序中常用的三十三种代码
- ASP.NET程序中常用的三十三种代码(3/3)