社区
C#
帖子详情
[**急,100分求助**]在DataGrid控件中单击一行触发什么事件,如何取到这一行的列值.
挺拔的劲松
2006-08-20 11:20:52
在DataGrid控件中单击某一行的任意位置,如何取得该行中的某一列的值.
例如我的DataGrid控件绑定一个Employee表,我单击DataGrid控件中的某一行的任意位置,就把所单击那一行的职工的Name列的值取得,可用消息框输出员工的姓名.
...全文
571
29
打赏
收藏
[**急,100分求助**]在DataGrid控件中单击一行触发什么事件,如何取到这一行的列值.
在DataGrid控件中单击某一行的任意位置,如何取得该行中的某一列的值. 例如我的DataGrid控件绑定一个Employee表,我单击DataGrid控件中的某一行的任意位置,就把所单击那一行的职工的Name列的值取得,可用消息框输出员工的姓名.
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
29 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
jinqinghai
2006-08-21
打赏
举报
回复
(个人认为自己)有些过于依赖第三方控件了。。 ,到现在vs.net默认表格控件的很多方法都不会。。
wuhuabucai
2006-08-21
打赏
举报
回复
dataGrid1.HitTest方法呢
jointan
2006-08-21
打赏
举报
回复
DataGrid无法完成此功能!
除非你单击到单元格的边框上,如果硬要实现也不是完全没有可能,不过实现的代码会让人笑掉大牙的,就是取得DataGridColumnStyle的承载控件,然后用这个承载控件的Mouse事件做相应处理,不过总感觉用了这种方法,实实在在得不偿失.可能我孤陋寡闻,也许还有更好的方法.我玩DataGrid不是一年两年了,包括定义一个新类,只要这个类包容一个DataGrid后,就可以实现模糊查询,组合查询,网格数据的所见即所得打印,动态冻结列、隐藏列,实现汇总Row,分组统计,承载ComboBox,将网格数据转换为excel,mdb,html,csv文本等等,唯一一个遇到的难题就是这个MouseEvent处理不了。我估计这个问题没答案,不过我更希望这个问题有答案。
dafeifei
2006-08-21
打赏
举报
回复
用javascript模拟,把javascript事件添加在e.item上
lindping
2006-08-21
打赏
举报
回复
楼上正解,一般还可以在 if (e.Item.ItemIndex != -1){...}内
加入这两行
//鼠标移动到该行,鼠标变成手状,提示用户可以点击,并且把该行的背景色改变
e.Item.Attributes.Add("onmouseover","this.style.cursor='hand';currentcolor=this.style.backgroundColor;this.style.backgroundColor='#ECECEC';");
//鼠标移开该行,背景色还原
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=currentcolor");
怎么样,效果很酷吧
polojojo
2006-08-21
打赏
举报
回复
写一个DtaGrid的继承类就行了
humin1906
2006-08-21
打赏
举报
回复
protected void DataGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemIndex != -1)
{
string strName = e.Item.Cell[i].Text; //i 取职工的名称
e.Item.Attributes.Add("onClick", "GetFun('"+strName+"')");
}
}
aspx 文件中加上JS脚本:
<script language="javascript">
function GetFun(param)
{
alert(param);
}
</script>
jiangna_100
2006-08-21
打赏
举报
回复
private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
DataGridViewCell[] arrays = new DataGridViewCell[2] ;
dataGridView1 .CurrentRow .Cells.CopyTo( arrays ,0);
userID = arrays[0].Value.ToString();
userTel = arrays[1].Value.ToString();
string strSQL="SELECT * FROM 销售信息表 WHERE 客户ID='"+userID +"' AND 客户电话='"+userTel+ "' AND 状态='已付款';";
dataGridView2.AutoGenerateColumns = true;
bindingSource2.DataSource = RemoteClass.newOperate.GetData(strSQL);
dataGridView2.DataSource = bindingSource2;
}
不过我这个是C/S的不知道能不能用啊,我也是初学的
zhangzhen7935
2006-08-21
打赏
举报
回复
int i = DataGrid.CurrentRow.Index;
if(i>0)
{
string name= dv.Tables["Employee"].Rows[i]["Name"].ToString();
}
挺拔的劲松
2006-08-21
打赏
举报
回复
说的详细点啊.我是初学者
挺拔的劲松
2006-08-21
打赏
举报
回复
还是没有解决啊.
我做的是B/S的,
fds2003
2006-08-21
打赏
举报
回复
e.Items.Cells[e.Item.ItemIndex].ToString()
假如某列有控件的话,你要先获取该控件!例如((TextBox)e.Item.Cells[6].Controls[0]).Text!两种方法都可以!
挺拔的劲松
2006-08-21
打赏
举报
回复
晕啊~~
spz007123
2006-08-21
打赏
举报
回复
<asp:datagrid id="DataGrid2" runat="server" BorderWidth="1px" BorderColor="#00CCFF" PageSize="5"
AllowSorting="True" AutoGenerateColumns="False" Width="632px" Height="144px" CellPadding="3">
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="OrderId" DataNavigateUrlFormatString="ddsp.aspx?OrderId={0}"
DataTextField="OrderId" HeaderText="订单编号">
<HeaderStyle Width="25%"></HeaderStyle>
</asp:HyperLinkColumn>
<asp:BoundColumn DataField="customer" HeaderText="客户">
<HeaderStyle Width="25%"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="ordertime" HeaderText="申请时间">
<HeaderStyle Width="25%"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="condition" HeaderText="当前状态">
<HeaderStyle Width="25%"></HeaderStyle>
</asp:BoundColumn>
</Columns>
<PagerStyle Mode="NumericPages"></PagerStyle>
</asp:datagrid>
给你贴一个datagrid 侃侃可以解决不~~
主要是这个:<asp:HyperLinkColumn DataNavigateUrlField="OrderId" DataNavigateUrlFormatString="ddsp.aspx?OrderId={0}"
就是传的表格里面的植。
是在属性生成里面直接设置的~
挺拔的劲松
2006-08-21
打赏
举报
回复
大家来帮帮忙啊
HSB19820706
2006-08-21
打赏
举报
回复
用DataGridView控件
挺拔的劲松
2006-08-21
打赏
举报
回复
dataGrid1[dataGrid1.CurrentCell.RowNumber,0].ToString();
这句放到哪里啊,如何能够解发你单击某一行的事件啊.
挺拔的劲松
2006-08-21
打赏
举报
回复
我试一下~
三省Ta叔
2006-08-21
打赏
举报
回复
dataGrid1[dataGrid1.CurrentCell.RowNumber,0].ToString();
当前行,第0列的值
挺拔的劲松
2006-08-21
打赏
举报
回复
在线等
加载更多回复(9)
JS
触发
服务器
控件
的
单击
事件
(详解)
如下所示: [removed][removed] [removed] $(function () { $("#a_doClick").click(function () { $("#<%=btnTest.ClientID%>").click(); }) }) [removed]
触发
Button的Click
事件
<asp:Button
ASP.NET常用代码
ASP.NET常用代码 1. 打开新的窗口并传送参数: 传送参数: response.write("<script>window.open('*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"')DataGrid.DataKeys[e.Item.ItemIndex]; string deleteCmd = "DELETE from Employee where emp_id = " + intEmpID.ToString() 4.删除表格记录警告 private void
DataGrid
_ItemCreated(Object sender,
DataGrid
ItemEventArgs e) { switch(e.Item.ItemType) { case ListItemType.Item : case ListItemType.AlternatingItem : case ListItemType.EditItem: TableCell myTableCell; myTableCell = e.Item.Cells[14]; LinkButton myDeleteButton ; myDeleteButton = (LinkButton)myTableCell.Controls[0]; myDeleteButton.Attributes.Add("onclick","return confirm('您是否确定要删除这条信息');"); break; default: break; } } 5.点击表格行链接另一页 private void grdCustomer_ItemDataBound(object sender, System.Web.UI.WebControls.
DataGrid
ItemEventArgs e) { //点击表格打开 if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) e.Item.Attributes.Add("onclick","window.open('Default.aspx?id=" + e.Item.Cells[0].Text + "');"); } 双击表格连接到另一页 在itemDataBind
事件
中
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { string OrderItemID =e.item.cells[1].Text; ... e.item.Attributes.Add("ondblclick", "location.href='../ShippedGrid.aspx?id=" + OrderItemID + "'"); } 双击表格打开新一页 if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { string OrderItemID =e.item.cells[1].Text; ... e.item.Attributes.Add("ondblclick", "open('../ShippedGrid.aspx?id=" + OrderItemID + "')"); } ★特别注意:【?id=】 处不能为 【?id =】 6.表格超连接列传递参数
' & name='<%# DataBinder.Eval(Container.DataItem, "数据字段2")%>' /> 7.表格点击改变颜色 if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem) { e.Item.Attributes.Add("onclick","this.style.backgroundColor='#99cc00';this.style.color='buttontext';this.style.cursor='default';"); } 写在
DataGrid
的_ItemDataBound里 if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem) { e.Item.Attributes.Add("onmouseover","this.style.backgroundColor='#99cc00';this.style.color='buttontext';this.style.cursor='default';"); e.Item.Attributes.Add("onmouseout","this.style.backgroundColor='';this.style.color='';"); } 8.关于日期格式 日期格式设定 DataFormatString="{0:yyyy-MM-dd}" 我觉得应该在itembound
事件
中
e.items.cell["你的列"].text=DateTime.Parse(e.items.cell["你的列"].text.ToString("yyyy-MM-dd")) 9.获取错误信息并到指定页面 不要使用Response.Redirect,而应该使用Server.Transfer e.g // in global.asax protected void Application_Error(Object sender, EventArgs e) { if (Server.GetLastError() is HttpUnhandledException) Server.Transfer("MyErrorPage.aspx"); //其余的非HttpUnhandledException异常交给ASP.NET自己处理就okay了 :) } Redirect会导致post-back的产生从而丢失了错误信息,所以页面导向应该直接在服务器端执行,这样就可以在错误处理页面得到出错信息并进行相应的处理 10.清空Cookie Cookie.Expires=[DateTime]; Response.Cookies("UserName").Expires = 0 11.自定义异常处理 //自定义异常处理类 using System; using System.Diagnostics; namespace MyAppException { ///
/// 从系统异常类ApplicationException继承的应用程序异常处理类。 /// 自动将异常内容记录到Windows NT/2000的应用程序日志 ///
public class AppException:System.ApplicationException { public AppException() { if (ApplicationConfiguration.EventLogEnabled) LogEvent("出现一个未知错误。"); } public AppException(string message) { LogEvent(message); } public AppException(string message,Exception innerException) { LogEvent(message); if (innerException != null) { LogEvent(innerException.Message); } } //日志记录类 using System; using System.Configuration; using System.Diagnostics; using System.IO; using System.Text; using System.Threading; namespace MyEventLog { ///
///
事件
日志记录类,提供
事件
日志记录支持 ///
/// 定义了4个日志记录方法 (error, warning, info, trace) ///
///
public class ApplicationLog { ///
/// 将错误信息记录到Win2000/NT
事件
日志
中
///
需要记录的文本信息 ///
public static void WriteError(String message) { WriteLog(TraceLevel.Error, message); } ///
/// 将警告信息记录到Win2000/NT
事件
日志
中
///
需要记录的文本信息 ///
public static void WriteWarning(String message) { WriteLog(TraceLevel.Warning, message); } ///
/// 将提示信息记录到Win2000/NT
事件
日志
中
///
需要记录的文本信息 ///
public static void WriteInfo(String message) { WriteLog(TraceLevel.Info, message); } ///
/// 将跟踪信息记录到Win2000/NT
事件
日志
中
///
需要记录的文本信息 ///
public static void WriteTrace(String message) { WriteLog(TraceLevel.Verbose, message); } ///
/// 格式化记录到
事件
日志的文本信息格式 ///
需要格式化的异常对象 ///
异常信息标题字符串. ///
///
格式后的异常信息字符串,包括异常内容和跟踪堆栈.
///
///
public static String FormatException(Exception ex, String catchInfo) { StringBuilder strBuilder = new StringBuilder(); if (catchInfo != String.Empty) { strBuilder.Append(catchInfo).Append("\r\n"); } strBuilder.Append(ex.Message).Append("\r\n").Append(ex.StackTrace); return strBuilder.ToString(); } ///
/// 实际
事件
日志写入方法 ///
要记录信息的级别(error,warning,info,trace). ///
要记录的文本. ///
private static void WriteLog(TraceLevel level, String messageText) { try { EventLogEntryType LogEntryType; switch (level) { case TraceLevel.Error: LogEntryType = EventLogEntryType.Error; break; case TraceLevel.Warning: LogEntryType = EventLogEntryType.Warning; break; case TraceLevel.Inf LogEntryType = EventLogEntryType.Information; break; case TraceLevel.Verbose: LogEntryType = EventLogEntryType.SuccessAudit; break; default: LogEntryType = EventLogEntryType.SuccessAudit; break; } EventLog eventLog = new EventLog("Application", ApplicationConfiguration.EventLogMachineName, ApplicationConfiguration.EventLogSourceName ); //写入
事件
日志 eventLog.WriteEntry(messageText, LogEntryType); } catch {} //忽略任何异常 } } //class ApplicationLog } 12.Panel 横向滚动,纵向自动扩展
13.回车转换成Tab <script language="javascript" for="document" event="onkeydown"> if(event.keyCode==13 && event.srcElement.type!='button' && event.srcElement.type!='submit' && event.srcElement.type!='reset' && event.srcElement.type!=''&& event.srcElement.type!='textarea'); event.keyCode=9; DataGrid超级连接列 DataNavigateUrlField="字段名" DataNavigateUrlFormatString="http://xx/inc/delete.aspx?ID={0}" 15.
DataGrid
行随鼠标变色 private void DGzf_ItemDataBound(object sender, System.Web.UI.WebControls.
DataGrid
ItemEventArgs e) { if (e.Item.ItemType!=ListItemType.Header) { e.Item.Attributes.Add( "onmouseout","this.style.backgroundColor=\""+e.Item.Style["BACKGROUND-COLOR"]+"\""); e.Item.Attributes.Add( "onmouseover","this.style.backgroundColor=\""+ "#EFF3F7"+"\""); } } 16.模板列
后台代码 protected void CheckAll_CheckedChanged(object sender, System.EventArgs e) { //改变列的选定,实现全选或全不选。 CheckBox chkExport ; if( CheckAll.Checked) { foreach(
DataGrid
Item o
DataGrid
Item in My
DataGrid
.Items) { chkExport = (CheckBox)o
DataGrid
Item.FindControl("chkExport"); chkExport.Checked = true; } } else { foreach(
DataGrid
Item o
DataGrid
Item in My
DataGrid
.Items) { chkExport = (CheckBox)o
DataGrid
Item.FindControl("chkExport"); chkExport.Checked = false; } } } 17.数字格式化 【<%#Container.DataItem("price")%>的结果是500.0000,怎样格式化为500.00?】 <%#Container.DataItem("price","{0:¥#,##0.00}")%> int i=123456; string s=i.ToString("###,###.00"); 18.日期格式化 【aspx页面内:<%# DataBinder.Eval(Container.DataItem,"Company_Ureg_Date")%> 显示为: 2004-8-11 19:44:28 我只想要:2004-8-11 】 <%# DataBinder.Eval(Container.DataItem,"Company_Ureg_Date","{0:yyyy-M-d}")%> 应该如何改? 【格式化日期】 取出来,一般是object ((DateTime)objectFromDB).ToString("yyyy-MM-dd"); 【日期的验证表达式】 A.以下正确的输入格式: [2004-2-29], [2004-02-29 10:29:39 pm], [2004/12/31] ^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[1-9])|(1[0-2]))\:([0-5][0-9])((\s)|(\:([0-5][0-9])\s))([AM|PM|am|pm]{2,2})))?$ B.以下正确的输入格式:[0001-12-31], [9999 09 30], [2002/03/03] ^\d{4}[\-\/\s]?((((0[13578])|(1[02]))[\-\/\s]?(([0-2][0-9])|(3[01])))|(((0[469])|(11))[\-\/\s]?(([0-2][0-9])|(30)))|(02[\-\/\s]?[0-2][0-9]))$ 【大小写转换】 HttpUtility.HtmlEncode(string); HttpUtility.HtmlDecode(string) 19.如何设定全局变量 Global.asax
中
Application_Start()
事件
中
添加Application[属性名] = xxx; 就是你的全局变量 20.怎样作到HyperLinkColumn生成的连接后,点击连接,打开新窗口? HyperLinkColumn有个属性Target,将器值设置成"_blank"即可.(Target="_blank") 【ASPNETMENU】点击菜单项弹出新窗口 在你的menuData.xml文件的菜单项
中
加入URLTarget="_blank" 如:
...... 最好将你的aspnetmenu升级到1.2版 21.委托讨论 http://community.csdn.net/Expert/topic/2651/2651579.xml?temp=.7183191 http://dev.csdn.net/develop/article/22/22951.shtm 22.读取
DataGrid
控件
TextBox值 foreach(
DataGrid
dgi in your
DataGrid
.Items) { TextBox tb = (TextBox)dgi.FindControl("yourTextBoxId"); tb.Text.... } 23.在
DataGrid
中
有3个模板列包含Textbox
分
别为 DG_ShuLiang (数量) DG_DanJian(单价) DG_JinE(金额)
分
别在5.6.7列,要求在录入数量及单价的时候自动算出金额即:数量*单价=金额还要求录入时限制为数值型.我如何用客户端脚本实现这个功能? 〖思归〗
<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); } datagrid选定比较底下的行时,为什么总是刷新一下,然后就滚动到了最上面,刚才选定的行因屏幕的关系就看不到了 page_load page.smartNavigation=true 25.在
Datagrid
中
修改数据,当点击编辑键时,数据出现在文本框
中
,怎么控制文本框的大小 ? private void
DataGrid
1_ItemDataBound(obj sender,
DataGrid
ItemEventArgs e) { for(int i=0;i
"; private static string ScriptEnd = "分秒 currentTime=System.DateTime.Now; 1.2 取当前年 int 年= DateTime.Now.Year; 1.3 取当前月 int 月= DateTime.Now.Month; 1.4 取当前日 int 日= DateTime.Now.Day; 1.5 取当前时 int 时= DateTime.Now.Hour; 1.6 取当前
分
int
分
= DateTime.Now.Minute; 1.7 取当前秒 int 秒= DateTime.Now.Second; 1.8 取当前毫秒 int 毫秒= DateTime.Now.Millisecond; 28.自定义
分
页代码: 先定义变量 :public static int pageCount; //总页面数 public static int curPageIndex=1; //当前页面 下一页: if(
DataGrid
1.CurrentPageIndex < (
DataGrid
1.PageCount - 1)) {
DataGrid
1.CurrentPageIndex += 1; curPageIndex+=1; } bind(); //
DataGrid
1数据绑定函数 上一页: if(
DataGrid
1.CurrentPageIndex >0) {
DataGrid
1.CurrentPageIndex += 1; curPageIndex-=1; } bind(); //
DataGrid
1数据绑定函数 直接页面跳转: int a=int.Parse(JumpPage.Value.Trim());//JumpPage.Value.Trim()为跳转值 if(a<
DataGrid
1.PageCount) { this.
DataGrid
1.CurrentPageIndex=a; } bind(); 29.
DataGrid
使用: 3.1添加删除确认: private void
DataGrid
1_ItemCreated(object sender, System.Web.UI.WebControls.
DataGrid
ItemEventArgs e) { foreach(
DataGrid
Item di in this.
DataGrid
1.Items) { if(di.ItemType==ListItemType.Item||di.ItemType==ListItemType.AlternatingItem) { ((LinkButton)di.Cells[8].Controls[0]).Attributes.Add("onclick","return confirm('确认删除此项吗?');"); } } } 3.2样式交替: 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';" ; } 3.3添加一个编号列: DataTable dt= c.ExecuteRtnTableForAccess(sqltxt); //执行sql返回的DataTable DataColumn dc=dt.Columns.Add("number",System.Type.GetType("System.String")); for(int i=0;i
DataGrid1.DataSource=dt;
DataGrid
1.DataBind(); 3.4
DataGrid
1
中
添加一个CheckBox,页面
中
添加一个全选框 private void CheckBox2_CheckedChanged(object sender, System.EventArgs e) { foreach(
DataGrid
Item thisitem in
DataGrid
1.Items) { ((CheckBox)thisitem.Cells[0].Controls[1]).Checked=CheckBox2.Checked; } } 将当前页面
中
DataGrid
1显示的数据全部删除 foreach(
DataGrid
Item thisitem in
DataGrid
1.Items) { if(((CheckBox)thisitem.Cells[0].Controls[1]).Checked) { string strloginid=
DataGrid
1.DataKeys[thisitem.ItemIndex].ToString(); Del (strloginid); //删除函数 } } 30.当文件在不同目录下,需要获取数据库连接字符串(如果连接字符串放在Web.config,然后在Global.asax
中
初始化) 在Application_Start
中
添加以下代码: Application["ConnStr"]=this.Context.Request.PhysicalApplicationPath+ConfigurationSettings.AppSettings["ConnStr"].ToString(); 31. 变量.ToString() 字符型转换 转为字符串 12345.ToString("n"); //生成 12,345.00 12345.ToString("C"); //生成 ¥12,345.00 12345.ToString("e"); //生成 1.234500e+004 12345.ToString("f4"); //生成 12345.0000 12345.ToString("x"); //生成 3039 (16进制) 12345.ToString("p"); //生成 1,234,500.00% 32、变量.Substring(参数1,参数2); 截取字串的一部
分
,参数1为左起始位数,参数2为截取几位。 如:string s1 = str.Substring(0,2); 34.在自己的网站上登陆其他网站:(如果你的页面是通过嵌套方式的话,因为一个页面只能有一个FORM,这时可以导向另外一个页面再提交登陆信息) <SCRIPT language="javascript"> <!-- function gook(pws) { frm.submit(); } //--> </SCRIPT> <body leftMargin="0" topMargin="0" onload="javascript:gook()" marginwidth="0" marginheight="0"> <form name="frm" action=" http://220.194.55.68:6080/login.php?retid=7259 " method="post"> <tr> <td> <input id="f_user" type="hidden" size="1" name="f_user" runat="server"> <input id="f_domain" type="hidden" size="1" name="f_domain" runat="server"> <input class="box" id="f_pass" type="hidden" size="1" name="pwshow" runat="server"> <INPUT id="lng" type="hidden" maxLength="20" size="1" value="5" name="lng"> <INPUT id="tem" type="hidden" size="1" value="2" name="tem"> </td> </tr> </form> 文本框的名称必须是你要登陆的网页上的名称,如果源码不行可以用vsniffer 看看。 下面是获取用户输入的登陆信息的代码: string name; name=Request.QueryString["EmailName"]; try { int a=name.IndexOf("@",0,name.Length); f_user.Value=name.Substring(0,a); f_domain.Value=name.Substring(a+1,name.Length-(a+1)); f_pass.Value=Request.QueryString["Psw"]; } catch { Script.Alert("错误的邮箱!"); Server.Transfer("index.aspx"); } 35.警告窗口 /**////
/// 服务器端弹出alert对话框 ///
///
提示信息,例子:"不能为空!" ///
Page类 public void Alert(string str_Message,Page page) { page.RegisterStartupScript("","<script>alert('"+str_Message+"');控件获得焦点 /**////
/// 服务器端弹出alert对话框,并使
控件
获得焦点 ///
///
获得焦点
控件
Id值,比如:txt_Name ///
提示信息,例子:"请输入您姓名!" ///
Page类 public void Alert(string str_Ctl_Name,string str_Message,Page page) { page.RegisterStartupScript("","<script>alert('"+str_Message+"');document.forms(0)."+str_Ctl_Name+".focus(); document.forms(0)."+str_Ctl_Name+".select(); /// 服务器端弹出confirm对话框 /// ///
提示信息,例子:"您是否确认删除!" ///
隐藏Botton按钮Id值,比如:btn_Flow ///
Page类 public void Confirm(string str_Message,string btn,Page page) { page.RegisterStartupScript("","<script> if (confirm('"+str_Message+"')==true){document.forms(0)."+btn+".click();}触发一个隐藏按钮
事件
,点击取消
触发
一个隐藏按钮
事件
/**////
/// 服务器端弹出confirm对话框,询问用户准备转向那些操作,包括“确定”和“取消”时的操作 ///
///
提示信息,比如:"成功增加数据,
单击
\"确定\"按钮填写流程,
单击
\"取消\"修改数据" ///
"确定"按钮id值 ///
"取消"按钮id值 ///
Page类 public void Confirm(string str_Message,string btn_Redirect_Flow,string btn_Redirect_Self,Page page) { page.RegisterStartupScript("","<script> if (confirm('"+str_Message+"')==true){document.forms(0)."+btn_Redirect_Flow+".click();}else{document.forms(0)."+btn_Redirect_Self+".click();} /// 使
控件
获得焦点 /// ///
获得焦点
控件
Id值,比如:txt_Name ///
Page类 public void GetFocus(string str_Ctl_Name,Page page) { page.RegisterStartupScript("","<script>document.forms(0)."+str_Ctl_Name+".focus(); document.forms(0)."+str_Ctl_Name+".select(); ///名称:redirect ///功能:子窗体返回主窗体 ///参数:url ///返回值:空 /// public void redirect(string url,Page page) { if ( Session["IfDefault"]!=(object)"Default") { page.RegisterStartupScript("","<script>window.top.document.location.href='"+url+"'; /// 名称:IsNumberic /// 功能:判断输入的是否是数字 /// 参数:string oText:源文本 /// 返回值: bool true:是 false:否 /// public bool IsNumberic(string oText) { try { int var1=Convert.ToInt32 (oText); return true; } catch { return false; } } 获得字符串实际长度(包括
中
文字符) //获得字符串oString的实际长度 public int StringLength(string oString) { byte[] strArray=System.Text .Encoding.Default .GetBytes (oString); int res=strArray.Length ; return res; } 42.将回车转换为TAB //当在有keydown
事件
的
控件
上敲回车时,变为tab public void Tab(System.Web .UI.WebControls .WebControl webcontrol) { webcontrol.Attributes .Add ("onkeydown", "if(event.keyCode==13) event.keyCode=9"); } 43.
datagrid
分
页
中
如果删除时出现超出索引 public void jumppage(System.Web.UI.WebControls.
DataGrid
dg) { int int_PageLess; //定义页面跳转的页数 //如果当前页是最后一页 if(dg.CurrentPageIndex == dg.PageCount-1) { //如果就只有一页 if(dg.CurrentPageIndex == 0) { //删除后页面停在当前页 dg.CurrentPageIndex = dg.PageCount-1; } else { //如果最后一页只有一条记录 if((dg.Items.Count % dg.PageSize == 1) || dg.PageSize == 1) { //把最后一页最后一条记录删除后,页面应跳转到前一页 int_PageLess = 2; } else //如果最后一页的记录数大于1,那么在最后一页删除记录后仍然停在当前页 { int_PageLess = 1; } dg.CurrentPageIndex = dg.PageCount - int_PageLess; } } } 发表于 2
Silverlight2.0功能展示Demo源码
Silverlight2.0功能展示Demo源码 1、Silverlight(3) - 2.0
控件
之Border, Button, Calendar, Canvas, CheckBox, ComboBox 介绍 Silverlight 2.0
控件
一览:Border, Button, Calendar, Canvas, CheckBox, ComboBox 2、Silverlight(4) - 2.0
控件
之
DataGrid
, DatePicker, Grid, GridSplitter, HyperlinkButton, Image 介绍 Silverlight 2.0
控件
一览:
DataGrid
, DatePicker, Grid, GridSplitter, HyperlinkButton, Image 3、Silverlight(5) - 2.0
控件
之ListBox, MediaElement, MultiScaleImage, PasswordBox, ProgressBar, RadioButton 介绍 Silverlight 2.0
控件
一览:ListBox, MediaElement, MultiScaleImage, PasswordBox, ProgressBar, RadioButton 4、Silverlight(6) - 2.0
控件
之ScrollViewer, Slider, StackPanel, TabControl, TextBlock, TextBox, ToggleButton 介绍 Silverlight 2.0
控件
一览:ScrollViewer, Slider, StackPanel, TabControl, TextBlock, TextBox, ToggleButton 5、Silverlight(7) - 2.0图形之Ellipse, Line, Path, Polygon, Polyline, Rectangle 介绍 Silverlight 2.0 图形: Ellipse - 椭圆 Line - 线 Path - 一系列相互连接的直线和曲线 Polygon - 多边形,闭合图形,起点与终点自动相连 Polyline - 非闭合图形,一串连接起来的线,起点与终点不会自动相连 Rectangle - 矩形 6、Silverlight(8) - 2.0图形之基类System.Windows.Shapes.Shape 介绍 Silverlight 2.0 图形:基类System.Windows.Shapes.Shape(Ellipse, Line, Path, Polygon, Polyline, Rectangle都继承自抽象类System.Windows.Shapes.Shape)。 Fill - 填充;Stroke - 笔画(边框) StrokeThickness - 笔画(边框)尺寸 Stretch - 拉伸值 StrokeDashArray - 虚线和间隙的值的集合 StrokeDashCap - 虚线两端(线帽)的类型 StrokeStartLineCap - 虚线起始端(线帽)的类型 StrokeEndLineCap - 虚线终结端(线帽)的类型 StrokeDashOffset - 虚线的起始位置。从虚线的起始端的 StrokeDashOffset 距离处开始描绘虚线 StrokeLineJoin - 图形连接点处的连接类型 StrokeMiterLimit - 斜接长度 与 StrokeThickness/2 的比值。默认值 10,最小值 1 7、Silverlight(9) - 2.0画笔之SolidColorBrush, ImageBrush, VideoBrush, LinearGradientBrush, RadialGradientBrush 介绍 Silverlight 2.0 画笔: SolidColorBrush - 单色画笔 ImageBrush - 图像画笔 VideoBrush - 视频画笔 LinearGradientBrush - 线性渐变画笔 RadialGradientBrush - 放射性渐变画笔 8、Silverlight(10) - 2.0其它之Transform详解,以及UIElement和FrameworkElement的常用属性 介绍 Silverlight 2.0 其它: RenderTransform - 呈现位置的转换(System.Windows.Media.Transform类型) RenderTransformOrigin - 位置转换的
中
心点 Clip - 容器的剪辑区域(System.Windows.Media.Geometry类型) IsHitTestVisible - 命
中
测试是否可见 Opacity - 不透明度。0 - 1之间 OpacityMask - 不透明蒙版(遮罩)(System.Windows.Media.Brush类型) UseLayoutRounding - 是否使用完整像素布局 Cursor - 鼠标移动到 FrameworkElement 上面时,鼠标指针的样式 Margin - 容器边缘与边缘之外的空白距离(像素值:上下左右;左右,上下;左,上,右,下) Tag - 保存一些额外的信息(System.Object类型) 9、Silverlight(11) - 2.0动画之ColorAnimation, DoubleAnimation, PointAnimation, 内插关键帧动画 介绍 Silverlight 2.0 动画: ColorAnimation - 在两个 Color 值之间做线性内插动画处理 DoubleAnimation - 在两个 Double 值之间做线性内插动画处理 PointAnimation - 在两个 Point 值之间做线性内插动画处理 内插关键帧动画 - 在 Color 或 Double 或 Point 动画
中
内插关键帧,以做线性, 离散, 三次贝塞尔曲线的动画处理 动态改变动画 - 通过程序控制,动态地改变动画 10、Silverlight(12) - 2.0外观之样式, 模板, 视觉状态和视觉状态管理器 介绍 Silverlight 2.0 外观控制:样式(Style), 模板(Template), 视觉状态(VisualState)和视觉状态管理器(VisualStateManager) 11、Silverlight(13) - 2.0交互之鼠标
事件
和键盘
事件
介绍 Silverlight 2.0 人机交互:响应用户的鼠标操作和键盘操作。 MouseEnter - 鼠标进入时
触发
的
事件
(显然,此
事件
不能冒泡) MouseLeave - 鼠标离开时
触发
的
事件
(显然,此
事件
不能冒泡) MouseLeftButtonDown - 鼠标左键
单击
按下时
触发
的
事件
MouseLeftButtonUp - 鼠标左键
单击
按下并放开时
触发
的
事件
MouseMove - 鼠标移动时
触发
的
事件
MouseEventArgs.GetPosition() - 鼠标相对于指定元素的坐标 MouseButtonEventArgs.Handled - 此
事件
是否已被处理 KeyDown - 鼠标按下时
触发
的
事件
KeyUp - 鼠标按下并放开时
触发
的
事件
KeyEventArgs.Key - 与
事件
相关的键盘的按键 [Input.Key枚举] KeyEventArgs.Handled - 是否处理过此
事件
Keyboard.Modifiers - 当前按下的辅助键 [Input.ModifierKeys枚举] 12、Silverlight(14) - 2.0交互之InkPresenter(涂鸦板) 介绍 Silverlight 2.0 人机交互:InkPresenter(涂鸦板)。 InkPresenter - 涂鸦板,也就是在面板上呈现墨迹。InkPresenter 可以包含子
控件
Cursor - 鼠标移动到 InkPresenter 上面时,鼠标指针的样式 Background - 涂鸦板背景 Opacity - 面板上墨迹的不透明度 Clip - InkPresenter 的剪辑区域 Stroke.DrawingAttributes - Stroke(笔划)的外观属性 UIElement.CaptureMouse() - 为 UIElement 对象启用鼠标捕捉 UIElement.CaptureMouse() - 为 UIElement 对象释放鼠标捕捉 13、Silverlight(15) - 2.0数据之一次绑定, 单向绑定, 双向绑定, INotifyPropertyChanged, 数据转换, 数据验证 介绍 Silverlight 2.0 数据绑定: Binding - 将绑定目标对象的属性与数据源联接起来 INotifyPropertyChanged - 向客户端发出某一属性值已更改的通知 IValueConverter - 值转换接口,将一个类型的值转换为另一个类型的值。它提供了一种将自定义逻辑应用于绑定的方式 BindingValidationError - 出现验证错误或解决上次验证错误则
触发
此
事件
14、Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 介绍 Silverlight 2.0 数据的独立存储(Isolated Storage): IsolatedStorageFile - 操作 独立存储 的类; IsolatedStorageFile.GetUserStoreForSite() - 按站点获取用户的独立存储 IsolatedStorageFile.GetUserStoreForApplication() - 按应用程序获取用户的独立存储 IsolatedStorageSettings - 在独立存储
中
保存的 key-value 字典表 IsolatedStorageSettings.SiteSettings - 按站点保存的 key-value 字典表 IsolatedStorageSettings.ApplicationSettings - 按应用程序保存的 key-value 字典表 15、Silverlight(17) - 2.0数据之详解
DataGrid
, 详解ListBox 介绍 Silverlight 2.0 详解
DataGrid
, 绑定数据到ListBox: AutoGenerateColumns - 是否根据数据源自动生成列 RowDetailsVisibilityMode - 显示相应的行的详细数据时所使用的显示模式
DataGrid
.RowDetailsTemplate - 用于显示相应的行的详细数据的模板 AreRowDetailsFrozen - 是否冻结 RowDetailsTemplate GridLinesVisibility - 表格
分
隔线的显示方式 RowBackground - 奇数数据行背景 AlternatingRowBackground - 偶数数据行背景 IsReadOnly - 单元格是否只读 FrozenColumnCount - 表格所冻结的列的总数(从左边开始数) SelectionMode - 行的选
中
模式 CanUserReorderColumns - 是否允许拖动列 CanUserResizeColumns - 是否允许改变列的宽度 CanUserSortColumns - 是否允许列的排序 16、Silverlight(18) - 2.0视频之详解MediaElement, 开发一个简易版的全功能播放器 介绍 Silverlight 2.0 详解MediaElement:开发一个简易版的全功能播放器。 Source - 需要播放的媒体地址 Stretch - 拉伸值 AutoPlay - 是否自动播放媒体 CurrentState - 播放状态 Position - 媒体的位置 DroppedFramesPerSecond - 媒体每秒正在丢弃的帧数 BufferingProgress - 缓冲进度 DownloadProgress - 下载进度 NaturalDuration - 媒体文件的时长; Volume - 音量大小 Balance - 音量平衡 BufferingTime - 需要缓冲的时间的长度 CurrentState - 播放状态 IsMuted - 是否静音 Play() - 播放媒体 Pause() - 暂停媒体的播放 Stop() - 停止媒体的播放 17、Silverlight(19) - 2.0通信之调用REST服务,处理JSON格式, XML格式, RSS/ATOM格式的数据 介绍 Silverlight 2.0 调用REST服务,处理JSON格式, XML格式, RSS/ATOM格式的数据。 通过 System.Net.WebClient 类调用 REST 服务 通过 System.Json 命名
控件
下的类处理 JSON 数据 通过 System.Xml.Linq 命名空间下的类(LINQ to XML)处理 XML 数据 通过 System.ServiceModel.Syndication 命名空间下的类处理 RSS/ATOM 数据 18、Silverlight(20) - 2.0通信之WebClient, 以字符串的形式上传/下载数据, 以流的方式上传/下载数据 介绍 Silverlight 2.0 详解WebClient,以字符串的形式上传、下载数据;以流的方式上传、下载数据。 WebClient - 将数据发送到指定的 URI,或者从指定的 URI 接收数据的类 DownloadStringAsync(Uri address, Object userToken) - 以字符串的形式下载指定的 URI 的资源 UploadStringAsync(Uri address, string data) - 以字符串的形式上传数据到指定的 URI。所使用的 HTTP 方法默认为 POST OpenReadAsync(Uri address, Object userToken) - 以流的形式下载指定的 URI 的资源 OpenWriteAsync(Uri address, string method, Object userToken) - 打开流以使用指定的方法向指定的 URI 写入数据 19、Silverlight(21) - 2.0通信之WebRequest和WebResponse, 对指定的URI发出请求以及接收响应 介绍 Silverlight 2.0 详解WebRequest和WebResponse,对指定的URI做GET和POST请求,以及接收其响应。 HttpWebRequest - 对指定的 URI 发出请求 Create() - 初始化一个 WebRequest BeginGetResponse() - 开始对指定 URI 资源做异步请求 EndGetResponse() - 结束对指定 URI 资源做异步请求 HttpWebResponse - 对指定的 URI 做出响应 GetResponseStream() - 获取响应的数据流 20、Silverlight(22) - 2.0通信之调用WCF服务, 对传输信息做加密 介绍 Silverlight 2.0 调用 WCF 服务,对客户端与服务端传输的消息做加密。在 Visual Studio 2008
中
使用"添加服务引用"会自动生成代理类。只支持BasicHttpBinding 21、Silverlight(23) - 2.0通信之调用WCF的双向通信(Duplex Service) 介绍 Silverlight 2.0 调用 WCF 的双向通信服务(Duplex Service) 。 开发一个服务端主动向客服端发送股票信息的程序,首先客户端先向服务端发送需要监控的股票的股票代码,然后服务端在该股信息发生变化的时候将信息推送到客户端 22、Silverlight(24) - 2.0通信之Socket, 开发一个多人聊天室 介绍 Silverlight 2.0 Socket通信。开发一个多人聊天室。 服务端:实例化Socket, 绑定, 监听, 连接, 接收数据, 发送数据 客户端:实例化Socket, 指定服务端地址, 连接, 接收数据, 发送数据 23、Silverlight(25) - 2.0线程之Thread, Timer, BackgroundWorker, ThreadPool 介绍 Silverlight 2.0 使用Thread, Timer, BackgroundWorker, ThreadPool来实现多线程开发。 Thread - 用于线程的创建和控制的类 Timer - 用于以指定的时间间隔执行指定的方法的类 BackgroundWorker - 用于在单独的线程上运行操作 ThreadPool - 线程池的管理类 24、Silverlight(26) - 2.0线程之Lock, Interlocked, EventWaitHandle, Monitor, ThreadStaticAttribute 介绍 Silverlight 2.0 使用Lock, Interlocked, EventWaitHandle, Monitor来实现线程同步。 Lock - 确保代码块完成运行,而不会被其他线程
中
断 Interlocked - 为多个线程共享的变量提供原子级的操作 EventWaitHandle - 通知其他线程是否可入的类 Monitor - 提供同步访问对象的机制 ThreadStaticAttribute - 所指定的静态变量对每个线程都是唯一的 25、Silverlight(27) - 2.0网页之可脚本化, 与DOM的交互, 与JavaScript的交互 介绍 Silverlight 2.0 使用c#开发可脚本化的代码,Silverlight与宿主页面的DOM之间的交互,Silverlight与宿主页面的JavaScript之间的交互。 ScriptableMemberAttribute - 需要脚本化的属性、方法、
事件
要标记为此 HtmlPage.RegisterScriptableObject - 将可脚本化对象注册到客户端 HtmlElement - 表示网页的文档对象模型 (DOM)
中
的 HTML 元素 HtmlWindow - 提供 JavaScript 的 window 对象的 Silverlight 端的托管表示形
为wpf
中
的
DataGrid
控件
添加鼠标
单击
事件
我们知道wpf
中
的
DataGrid
控件
是没有鼠标
单击
事件
的,使用MouseDown
事件
比较弱,要先鼠标
单击
一下,选
中
某个单元格,再鼠标
单击
才相应
事件
,这不是我们想要的 要相应鼠标
单击
事件
的列,我们采用
DataGrid
HyperlinkColumn
控件
进行代替 下面只贴出
DataGrid
对应的xaml代码,如下: <Grid > <
DataGrid
AutoGenerateColumns="False" Height="287" HorizontalAli..
WPF的
DATAGRID
中
对行添加
单击
事件
在做的一个c#的项目
中
发现
Datagrid
没办法直接对鼠标
单击
进行响应,调用MouseDown
事件
也需要点击某
一行
第二次才能响应。所以借助EventSetter来简单的实现了一个。 界面部
分
的代码 <
DataGrid
x:Name="
dataGrid
" HorizontalAlignment="Left" Margin="10,38,0,0" VerticalAlignment="Top" Height="257" FontSize="13.333"
C#
110,538
社区成员
642,577
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章