由于java脚本,复选框更新问题 [英] Checkbox update issue because of java script

查看:66
本文介绍了由于java脚本,复选框更新问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在客户端有这个脚本,在网格视图中点击复选框启用复选框。但是当我在复选框的值复选后点击提交外网格视图时,复选框值没有得到更新。它保留其旧值。

I have this script on client side to enable checkboxes on click of checkbox in grid view.but when i click on submit outside gridview after chagning value of checkboxes ,checkboxes value did not get update.It is retaining its old value.

$(function () {

   //Enable Disable TextBoxes in a Row when the Row CheckBox is checked.
   $("[id*=chkRow]").live("click", function () {

      //Find and reference the GridView.
      var grid = $(this).closest("table");

      //Find and reference the Header CheckBox.
      //var chkHeader = $("[id*=chkHeader]", grid);

      //If the CheckBox is Checked then enable the TextBoxes in thr Row.
      if (!$(this).is(":checked")) {
         var td = $("td", $(this).closest("tr"));
         //                td.css({ "background-color": "#FFF" });
         $("input[type=checkbox]", td).attr("disabled", "disabled");
      }
      else {
         var td = $("td", $(this).closest("tr"));
         //                td.css({ "background-color": "#D8EBF2" });
         $("input[type=checkbox]", td).removeAttr("disabled");
      }

      $("[id*=chkRow]").removeAttr("disabled");

   });

});
</script>





这是我的代码



here is my code

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
   If Not Me.IsPostBack Then
      GetData()

   End If
End Sub
Private Sub GetData()
   Dim constr1 As String = ConfigurationManager.ConnectionStrings("constr1").ConnectionString
   Using con As New SqlConnection(constr1)
      Using cmd As New SqlCommand("select * from Test ")
         Using sda As New SqlDataAdapter()
            cmd.Connection = con
            sda.SelectCommand = cmd
            Using dt As New DataSet()
               sda.Fill(dt)
               GridView1.DataSource = dt
               GridView1.DataBind()
            End Using
         End Using
      End Using
   End Using
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
   For Each row As GridViewRow In GridView1.Rows
      If row.RowType = DataControlRowType.DataRow Then
         Dim C, L As CheckBox
         L = TryCast(row.Cells(3).FindControl("cbSelect7"), CheckBox)
         C = TryCast(row.Cells(4).FindControl("cbSelect8"), CheckBox)
         ' here C,L not taking updated value
      End If
   Next
End Sub





我尝试了什么:



i取消注释脚本然后工作正常。



What I have tried:

i uncomment script then its working fine.

推荐答案

function (){

// 选中行复选框时,启用禁用行中的文本框。


[id * = chkRow])。live( 点击 function (){

/ / 查找并引用GridView。
var grid =
("[id*=chkRow]").live("click", function () { //Find and reference the GridView. var grid =


this )。nearest( );

// 查找并引用标题复选框。
< span class =code-comment> //
var chkHeader =
(this).closest("table"); //Find and reference the Header CheckBox. //var chkHeader =


这篇关于由于java脚本,复选框更新问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆