2012-05-09 58 views
-1

我必須在jqModal彈出框中綁定asp.net gridview和jquery 我做了一個ajax post調用並獲取一個列表。 我需要將此列表綁定到asp.net網格,以便成功回調ajax調用。 請在下面找到我使用的代碼,在bindGrid方法中,我需要將列表綁定到asp.net gridview。 請幫忙!如何使用jQuery綁定asp.net gridview控件?

功能頁面加載(發件人,參數){

  var param = null; 
     $(function() { 
      var myBlock = $('#myBlock'); // cache jq obj 
      $().ajaxStart(function() { 
       $.blockUI(myBlock); 
      }).ajaxStop($.unblockUI); 
     }); 

     var showModalPopup = function (container, path, leftMargin, topMargin, triggerElement, postData) { 
      // alert('in popup'); 
      //(container, path, leftMargin, topMargin, triggerElement, postData) { 
      ///<summary>This method is used for displaying remote pages in modal popup.</summary> 
      ///<param name="container">ID of the div which is displayed as popup.</param> 
      ///<param name="path">URL of the page which will be displayed as popup.</param> 
      ///<param name="leftMargin">Width of left margin in "%". Used for alignment of popup.</param> 
      ///<param name="topMargin">Width of top margin in "%". Used for alignment of popup</param> 
      ///<param name="triggerElement">Element which triggered the popup. Used for contexts.</param> 
      ///<returns></returns> 
      var divBlock = '#' + container; 
      if (typeof leftMargin === 'undefined') { 
       leftMargin = '20%'; 
      } 

      if (typeof topMargin === 'undefined') { 
       topMargin = '10%'; 
      } 
      //if the 3rd parameter type is object,we would treat it as postdata 
      if (typeof leftMargin === 'object') { 
       postData = leftMargin; 
       leftMargin = '10%'; 
      } 
      if (typeof triggerElement !== 'undefined') { 
       //Select the id of immediate fieldset of the element which opened popup. 
       //e.g., if "NameSearchButton" is the trigger element, find the fieldset containing this button. 
       var parentFieldsetId = triggerElement.parents('fieldset')[0].id; 
       //Store the fieldset by adding it as custom attribute to divPopup. 
       $(divBlock).attr('parentContext', parentFieldsetId); 
      } 


      $.blockUI({ message: $(divBlock), 
       css: { 
        padding: 10, 
        margin: 0, 
        left: leftMargin, 
        top: topMargin, 
        width: '', 
        height: '', 
        centerX: true, 
        centerY: true, 
        textAlign: 'center', 
        color: '#000', 
        opacity: '80', 
        border: '3px solid #aaa' 
       }, 
       overlayCSS: { 
        backgroundColor: '#000', 
        opacity: 0.7 
       }, 
       fadeIn: 0, 
       fadeOut: 0 
      }); 

      if (path !== 'local') { 
       $(document).data('formInstance', false); 
       if (postData) { 
        $.post(path, postData, function (response) { 

         $(divBlock).html(response); 
        }); 
       } 
       else { 

        $(divBlock).load(path); 
       } 
      } 


      $(divBlock).attr('IsPopupDiv', 1); 


     }; 


     var bind = function (success) { 
      if (success !== null || success !== undefined) { 
       //Bind to the grid #ContentPlaceHolder1_grdPopUpGrid 
      } 

     }; 
     var bindGrid = function() { 
      var objBind = '06'; //$('#ContentPlaceHolder1_txtBeginsWithText').val(); 
      var conStrBind = $('#ContentPlaceHolder1_ConnStrHidden').val(); 

      if (param == null || param == '' || param == undefined) { 

       drpParamBind = $('#ContentPlaceHolder1_drpSearchBy').val(); 
      } 
      else { 
       drpParamBind = param; 
      } 
      var webMethodURL = 'testPage.aspx/HitMethod'; 
      var newobj = { 'obj': objBind, 'conStr': conStrBind, 'drpParam': drpParamBind }; 
      $.ajax({ 
       type: "POST", 
       url: webMethodURL, 
       contentType: "application/json; charset=utf-8", 
       data: JSON.stringify(newobj), 
       dataType: "json", 
       success: function (response) { 

        var success = ''; 
        if (response !== undefined) { 
         if (response.d !== null || response.d !== '') { 
          success = response.d; 
          bind(success); 



         } 
        } 
       } 
       //   ,error: function(XHR, errStatus, errorThrown) { 
       //   } 
      }); 
     }; 
     var con = $('#imgSearchSpouse').parent(); 
     var test = $('#txtPartnerNo').val(); 

     $("#ContentPlaceHolder1_imgSearchSpouse").click(function() { 
      // alert('hello'); 

      showModalPopup('ContentPlaceHolder1_Spousepopupdiv', 'local', '13%', '15%'); 


     }); 
     $('#ContentPlaceHolder1_btnSearchpopup').click(function() { 

      bindGrid(); 
     }); 



    } 
</script> 

回答

-1

我在同樣的事情工作了Jquery的Ajax的方法

函數GetDetails(pk){

 var paramList = '{"Foreignkey":"' + pk + '"}'; 
     alert(paramList); 
     $.ajax({ 
      type: "POST", 
      url: "GetData.aspx/getDetails", 
      dataType: "json", 
      contentType: "application/json", 
      processData: false, 
      data: paramList, 
      success: function (msg) { 
       alert('success'); 
       for (var i = 0; i < msg.d.length; i++) 
       { 
        $("#NamesGridView").append("<tr><td>"+ msg.d.id+"</td><td>"+msg.d.GraduatedYear+"</td><td>"+msg.d.SchoolName+"</td></tr>"); 
       } 
       //Show the Dialog 
       OpenDialog_Details(); 
       //closeDialog_Details(); 
      }, 
      error: function (msg) { 
       alert("error " + msg.responseText); 
      } 
     }); 
     return false; 
    } 

,這裏是將WebMethod

[WebMethod] 
    public static Details[] getDetails(string Foreignkey) 
    { 

     SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["RepeaterDBConnection"].ConnectionString); 
     SqlCommand comm = new SqlCommand(); 
     DataTable dt = new DataTable(); 
     List<Details> list = new List<Details>(); 
     try 
     { 

      comm.Connection = con; 
      comm.CommandType = CommandType.StoredProcedure; 
      comm.CommandText = "[dbo].[GetDetail]"; 
      comm.Parameters.Add(new SqlParameter("@PIFK", SqlDbType.Int)).Value = Convert.ToInt32(Foreignkey); 
      SqlDataAdapter da = new SqlDataAdapter(comm); 
      da.Fill(dt); 

      foreach (DataRow row in dt.Rows) 
      { 
       Details detobj = new Details(); 
       detobj.id = Convert.ToInt32(row["id"].ToString()); 
       detobj.GraduatedYear = row["GraduatedYear"].ToString(); 
       detobj.SchoolName = row["SchoolName"].ToString(); 
       list.Add(detobj); 
      } 
     } 
     catch (SqlException Ex) 
     { 
      //lblResultMessage.Text = Ex.Message; 
     } 
     return list.ToArray(); 
    } 

,這裏是我的 類public class詳細 { 私人詮釋_id;

public int id 
    { 
     get { return _id; } 
     set { _id = value; } 
    } 
    private string _GraduatedYear; 

    public string GraduatedYear 
    { 
     get { return _GraduatedYear; } 
     set { _GraduatedYear = value; } 
    } 
    private string _SchoolName; 

    public string SchoolName 
    { 
     get { return _SchoolName; } 
     set { _SchoolName = value; } 
    } 


} 

我希望它給你的想法,以達到您的解決方案

-1

公衆詮釋ID { 得到{_id; } set {_id = value; } } 私人字符串_GraduatedYear;

public string GraduatedYear 
{ 
    get { return _GraduatedYear; } 
    set { _GraduatedYear = value; } 
} 
private string _SchoolName; 

public string SchoolName 
{ 
    get { return _SchoolName; } 
    set { _SchoolName = value; } 
} 

}

相關問題