李晓亮的博客

导航

公告

统计

置顶随笔 #

[置顶]jquery向.ashx文件post中文乱码问题的解决

摘要: 1.我的环境:vs2005,未装SP1补丁,不能创建Web应用程序,只能创建网站;jquery版本1.5.12.web.config中的相关配置<globalizationrequestEncoding="gb2312"responseEncoding="gb2312"/>3.jquery的Post数据的写法jquery Code $(document).ready(function(){$("#btnSend").click(function(){$.ajax({type:"POST",url:&qu阅读全文

posted @ 2011-03-25 21:55 LeeXiaoLiang 阅读(287) 评论(0) 编辑

2011年7月12日 #

自己写的一个javascript下拉列表类

摘要: 最近用javacript写了一个模拟下拉列表的类DivUlLiList.js //类名:DivUlLiList//作者:李晓亮//公司:上海兴侯科技//版本:V0.5//注意事项://1)在window.onload事件外进行对象声明//2)在window.onload事件中进行对象构建//3)附加控件仅支持文本框functionListItem(itemText,itemValue){this.itemText=itemText;this.itemValue=itemValue;}functionDivUlLiList(){//items属性this.items=newArray();//页阅读全文

posted @ 2011-07-12 00:43 LeeXiaoLiang 阅读(841) 评论(2) 编辑

2011年4月1日 #

jquery1.5.1根据元素ID获取元素对象

尽管听说jquery的大名几年了,但是一直没有使用过。这两天想在项目中使用被一些小细节折腾的够呛,看来jquery没有传说中的那么好学。在jquery1.5.1根据ID来获取对象返回的是对应数组,想不通怪不得使用document.getElementById(""ID名"")可以取到单一的对象,使用$("#ID名")却不行,悲剧呀。
View Code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 
<head>
  
<title> 选择器测试 </title>
  
<style type="text/css">
   .txtobj
{background-color: #6600FF;}
  
</style>
  
<script type="text/javascript" src="../jquery-1.5.1.min.js"></script>
  
<script language="JavaScript" type="text/javascript">
  $(document).ready(
     
function()
     {
        $(
"input[type='text']")
        .click
        (
           
function()
           {
             
this.value=$("#lblMsg")[0].innerText;
           }
        )
        .keydown(
        
function()
        {
            alert($(
"#divTest")[0].innerText);
            alert($(
"#lblMsg")[0].innerHTML);
            alert($(
"#txtTest")[0].value);
            
return false;
        }
        );
     }
  );
  
</script>
 
</head>

 
<body>
    
<table width="400" border="1" cellpadding="0" cellspacing="0">
       
<tr>
          
<td><span id="lblMsg">0123456789</span></td>
       
</tr>
       
<tr>
          
<td>
             
<input type="text" id="txtTest" class="txtobj" value="@#$message test"/>
          
</td>
       
</tr>
    
</table>
    
<div id="divTest">ABCDEFGHIJKLMNOPQRSTUVWXYZ</div>  
 
</body>
</html>

posted @ 2011-04-01 20:30 LeeXiaoLiang 阅读(159) 评论(0) 编辑

2011年3月25日 #

jquery向.ashx文件post中文乱码问题的解决

1.我的环境:vs2005,未装SP1补丁,不能创建Web应用程序,只能创建网站;jquery版本1.5.1

2.web.config中的相关配置

<globalization requestEncoding="gb2312" responseEncoding="gb2312"/>


3.jquery的Post数据的写法

jquery Code
$(document).ready(function (){
      $(
"#btnSend").click(function(){
         $.ajax({
         type: 
"POST",
         url: 
"PrecisionAHandle.ashx",
         contentType:
"application/x-www-form-urlencoded; charset=UTF-8",
         data: { 
"StudentId": $("#LblStudentId").attr("innerText"),"StudentName": $("#LblStudentName").attr("innerText"),"StudentAge": $("#txtStudentAge").attr("value")},
         success: 
function(html){
            $(
"#TabContainer").html(html);
         }
        }); 
      });
    });

其中StudentName是中文

4.在.ashx文件中接收参数的写法

string strStudentName = context.Request.Params["StudentName"];

注意:如果没有contentType:"application/x-www-form-urlencoded; charset=UTF-8",则context.Request.Params["StudentName"]是乱码。
经过在.ashx中跟踪context.Request.ContentEncoding,可知jquery所post过来的数据采用的是gb2312编码,可能context.Request在接收到数据时默认采用utf-8进行解码,但是jquery在Post数据的时候却不是用的utf-8才导致.ashx的context.Request.Params["StudentName"]显示为乱码。
感觉比较奇怪的现象:
现象1:
在不添加contentType:"application/x-www-form-urlencoded; charset=UTF-8",的情况下,在.ashx文件中使用下面的语句却可以正确显示字符串:

View Code
StreamReader steamRd = new StreamReader(HttpContext.Current.Request.InputStream);
string strPostData = steamRd .ReadToEnd(); 
strPostData 
=HttpUtility.UrlDecode(strPostData, Encoding.GetEncoding("utf-8"));

现象2:将web.config中的相关配置改为
<globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
 之后,不管是否加上contentType:"application/x-www-form-urlencoded; charset=UTF-8",后台的.ashx文件接收到的参数仍然是乱码。修改web.config之后网站编译的很慢且运行的也很慢。

参考文章:

1)http://dev.firnow.com/course/1_web/javascript/jsjs/20090303/157078.html
2)http://xyztony1985.blog.163.com/blog/static/361178201081754921150/

posted @ 2011-03-25 21:55 LeeXiaoLiang 阅读(287) 评论(0) 编辑

2010年12月7日 #

【转】通过在RowDataBound事件中把行索引绑定到控件的CommandArgument,然后在RowCommand事件中取出

代码
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    
int rowIndex = -1;
    GridViewRow row 
= null;        
    
switch (e.CommandName)
    {
        
case "Command1"// 模板列
        
// 对于模板列内的按钮,我们需要显示绑定行索引到按钮的 CommandArgument 属性
        
// 以获取触发事件的行信息
         rowIndex = Convert.ToInt32(e.CommandArgument);
         row 
= GridView1.Rows[rowIndex];                
         DisplayInfo(row, e.CommandName);
        
// your codes
        
// 
        break;
        
case "Command2"// 模板列
        
// 同样处于模板列中,但不采用 Command1 方式,而是通过 NamingContrainer 属性
        
// 直接获取当前的 GridViewRow
         Control cmdControl = e.CommandSource as Control; // 表示触发事件的 IButtonControl,保持统一性并便于后续操作,我们这里直接转化为控件基类 Control
         row = cmdControl.NamingContainer as GridViewRow;
         DisplayInfo(row, e.CommandName);
        
// your codes
        
// 
        break;
        
case "Command3"// 绑定列
        
// 对于 ButtonField 列,数据源控件内部自动以适当的项索引值填充 CommandArgument 属性。
        
// 而无需我们显示绑定其 CommandArgument 属性                
        
// 注意,我们这里无法采用 Command2 的方式,对于 BUttonField 触发的事件,
        
// GridViewCommandEventArgs.CommandSource 表示的包含此按钮的 GridView
         rowIndex = Convert.ToInt32(e.CommandArgument);
         row 
= GridView1.Rows[rowIndex];
         DisplayInfo(row, e.CommandName);
        
// your codes
        
// 
        break;
     }
}

 

posted @ 2010-12-07 01:00 LeeXiaoLiang 阅读(62) 评论(0) 编辑

【转】GridView的RowCommand事件中取得行索引

 

代码
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        
if (e.Row.RowType == DataControlRowType.DataRow)//如果是为数据行
        {
            ImageButton imgbtnup 
= (ImageButton)e.Row.Cells[1].FindControl("btnMoveUp");//找控件
            imgbtnup.CommandArgument = e.Row.RowIndex.ToString();//设置与此BUTTON关联的命令参数
            imgbtnup.Visible = e.Row.RowIndex != 0
            ImageButton imgbtndown 
= (ImageButton)e.Row.Cells[2].FindControl("btnMoveDown");
            imgbtndown.CommandArgument 
= e.Row.RowIndex.ToString();
            imgbtndown.Visible 
= e.Row.RowIndex != ((DataSet)((GridView)sender).DataSource).Tables[0].Rows.Count - 1;
        }
    }

    
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        
if (e.CommandName == "MoveUp")
        {
            
int index = Convert.ToInt32(e.CommandArgument);//取的行索引
            DataKey key = this.GridView1.DataKeys[index];
            
string keyval = key.Value;//取得主键
        }
        
else if (e.CommandName == "MoveDown")
        {
            
int index = Convert.ToInt32(e.CommandArgument);
            DataKey key 
= this.GridView1.DataKeys[index];
            
string keyval = key.Value; 
        }
    }

 

 

posted @ 2010-12-07 00:45 LeeXiaoLiang 阅读(55) 评论(0) 编辑

2010年12月4日 #

【转】GridView 实现服务器端和客户端全选的两种方法

代码很简单,这里就不累述了。看代码如下:

例子

C#

<%@ Page Language="C#" AutoEventWireup="true" EnableViewState="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> // 计算数据,完全可以从数据看取得 ICollection CreateDataSource() { System.Data.DataTable dt = new System.Data.DataTable(); System.Data.DataRow dr; dt.Columns.Add(new System.Data.DataColumn("序号", typeof(System.String))); dt.Columns.Add(new System.Data.DataColumn("学生姓名", typeof(System.String))); dt.Columns.Add(new System.Data.DataColumn("语文", typeof(System.Decimal))); dt.Columns.Add(new System.Data.DataColumn("数学", typeof(System.Decimal))); dt.Columns.Add(new System.Data.DataColumn("英语", typeof(System.Decimal))); dt.Columns.Add(new System.Data.DataColumn("计算机", typeof(System.Decimal))); for (int i = 0; i < 8; i++) { System.Random rd = new System.Random(Environment.TickCount * i); ; dr = dt.NewRow(); dr[0] = i.ToString(); dr[1] = "【孟子E章】" + i.ToString(); dr[2] = System.Math.Round(rd.NextDouble() * 100, 2); dr[3] = System.Math.Round(rd.NextDouble() * 100, 2); dr[4] = System.Math.Round(rd.NextDouble() * 100, 2); dr[5] = System.Math.Round(rd.NextDouble() * 100, 2); dt.Rows.Add(dr); } System.Data.DataView dv = new System.Data.DataView(dt); return dv; } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GridView2.DataSource = GridView1.DataSource = CreateDataSource(); GridView2.DataBind(); GridView1.DataBind(); } } protected void Button1_Click(object sender, EventArgs e) { Ret1.Text = ""; foreach (GridViewRow gvr in GridView1.Rows) { CheckBox ch = (CheckBox)gvr.FindControl("ItemCheckBox"); if (ch.Checked) { Ret1.Text += "<li>GridView1 您选择的是(键值):" + GridView1.DataKeys[gvr.DataItemIndex].Value.ToString(); } } } protected void Button2_Click(object sender, EventArgs e) { Ret2.Text = ""; foreach (GridViewRow gvr in GridView2.Rows) { CheckBox ch = (CheckBox)gvr.FindControl("ItemCheckBox"); if (ch.Checked) { Ret2.Text += "<li>GridView2 您选择的是(键值):" + GridView2.DataKeys[gvr.DataItemIndex].Value.ToString(); } } } protected void CheckAll(object sender, EventArgs e) { CheckBox cbx = (CheckBox)sender; foreach (GridViewRow gvr in GridView1.Rows) { CheckBox ch = (CheckBox)gvr.FindControl("ItemCheckBox"); ch.Checked = cbx.Checked; } } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>GridView 实现服务器端和客户端全选的两种方法</title> <script type="text/javascript"> //<![CDATA[ function CheckAll(oCheckbox) { var GridView2 = document.getElementById("<%=GridView2.ClientID %>"); for(i = 1;i < GridView2.rows.length; i++) { GridView2.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked = oCheckbox.checked; } } //]]> </script> </head> <body> <form id="Form1" runat="server"> <table style="width:800px;font-size:12px;"> <tr valign="top"> <td> <asp:GridView ID="GridView1" runat="server" Font-Size="12px" BackColor="#FFFFFF" GridLines="Both" CellPadding="4" DataKeyNames="序号" AutoGenerateColumns="false"> <headerstyle backcolor="#EDEDED" height="26px" /> <columns> <asp:TemplateField> <headertemplate> <asp:CheckBox ID="CheckBox1" runat="server" Text="全选" AutoPostBack="true" OnCheckedChanged="CheckAll" /> </headertemplate> <itemtemplate> <asp:CheckBox ID="ItemCheckBox" runat="server" /> </itemtemplate> </asp:TemplateField> <asp:BoundField datafield="学生姓名" headertext="学生姓名" /> <asp:BoundField datafield="语文" headertext="语文" /> <asp:BoundField datafield="数学" headertext="数学" /> <asp:BoundField datafield="英语" headertext="英语" /> <asp:BoundField datafield="计算机" headertext="计算机" /> </columns> </asp:GridView> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="得到选择的行值" /> </td> <td align="right"> <asp:GridView ID="GridView2" runat="server" Font-Size="12px" BackColor="#FFFFFF" GridLines="Both" CellPadding="4" DataKeyNames="序号" AutoGenerateColumns="false"> <headerstyle backcolor="#EDEDED" height="26px" /> <columns> <asp:TemplateField> <headertemplate> <input id="Checkbox2" type="checkbox" onclick="CheckAll(this)" runat="server" /><label>全选</label> </headertemplate> <itemtemplate> <asp:CheckBox ID="ItemCheckBox" runat="server" /> </itemtemplate> </asp:TemplateField> <asp:BoundField datafield="学生姓名" headertext="学生姓名" /> <asp:BoundField datafield="语文" headertext="语文" /> <asp:BoundField datafield="数学" headertext="数学" /> <asp:BoundField datafield="英语" headertext="英语" /> <asp:BoundField datafield="计算机" headertext="计算机" /> </columns> </asp:GridView> <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="得到选择的行值" /> </td> </tr> <tr valign="top"> <td> <asp:Literal ID="Ret1" runat="server"></asp:Literal> </td> <td align="right"> <asp:Literal ID="Ret2" runat="server"></asp:Literal> </td> </tr> </table> </form> </body> </html>

posted @ 2010-12-04 20:17 LeeXiaoLiang 阅读(38) 评论(0) 编辑

ASP.NET之GridView数据绑定

1.模板列的绑定
(1)在前台页面绑定
            <asp:TemplateField>
               
<ItemTemplate>
                    
<asp:TextBox ID="TextBox1" runat="server"
                     Text
='<%# Eval("数据库字段")%'></asp:TextBox>
                
</ItemTemplate>
           
</asp:TemplateField>

posted @ 2010-12-04 01:15 LeeXiaoLiang 阅读(71) 评论(0) 编辑

2010年8月19日 #

希尔排序的C语言实现(2)

摘要: 代码 Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->#include<stdio.h>#include<stdlib.h>voidShellSort(inta[],intIndex);voidPrintArray(constc...阅读全文

posted @ 2010-08-19 17:02 LeeXiaoLiang 阅读(181) 评论(0) 编辑

希尔排序的C语言实现(1)

摘要: 代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->#include<stdio.h>#include<stdlib.h>intinitialStep(intsize);voidsort(intarray[],intfrom,i...阅读全文

posted @ 2010-08-19 10:37 LeeXiaoLiang 阅读(106) 评论(0) 编辑

2010年8月17日 #

简单插入排序的C语言实现

摘要: 代码 Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->#include<stdio.h>#include<stdlib.h>voidPrintHeap(constchar*strMsg,intarray[],intnLength...阅读全文

posted @ 2010-08-17 15:29 LeeXiaoLiang 阅读(84) 评论(0) 编辑

仅列出标题  下一页