.Net GridView异步刷新

来源:互联网 发布:善存 多维 佳维 知乎 编辑:程序博客网 时间:2024/06/11 05:57

新手能想到的方法很局限 但是能解决问题

Add.aspx:

<script>

 function Attendance(id) {
           
           $.ajax({
               type: "get",
               url: "Add.aspx",
               dataType: "html",
               data: { 'id': id , 'CCode': CCode, 'classID': classID,},
               success: function (data) {
                   var prnhtml = data.substr(data.indexOf(sprnstr) + 16);
                   prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));
                   $("#gridView").html(prnhtml);
                   addCSS();
               },
               cache: false,
               error: function (msg) {
                   alert(msg.responseText);
               }
           });

       }

</script>


GridView控件:

                    <asp:TemplateField HeaderText="点到">
                            <ItemStyle CssClass="edit" Width="40px" HorizontalAlign="Center"/>
                            <ItemTemplate>
                                <%#GetAttendance(Eval("StuNumber").ToString()) %>
                            </ItemTemplate>   
                        </asp:TemplateField>

.cs:

protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                Attendance(Request.QueryString["id"]);
            }
        }


protected string GetAttendance(string id)
        {
            if (!string.IsNullOrEmpty(id))
            {
                //写你的查询 获得一个list
                if (Attendlst.Count != 0)
                {
                    if (Attendlst[0].AttendanceDate.ToString().Substring(0, 9) != DateTime.Now.ToString().Substring(0, 9))
                    {
                        return "<a href = \"javascript:Attendance('" + id + "')\" style='color:red' >点到</a>";
                    }
                    else
                    {
                        return "<a href = \"javascript:CancelAttendance('" + Attendlst[0].AttendaceRecordID + "')\" style='color:blue' >取消点到</a>";

                    }
                }
                else
                {
                    return "<a href = \"javascript:Attendance('" + id + "')\" style='color:red' >点到</a>";
                }
            }
            else
            {
                return "错误";
            }
        }


 protected void Attendance(string id)
        {
            if (!string.IsNullOrEmpty(id))
            {

            //写入数据库数据

            }

        }


0 0
原创粉丝点击