Ajax:显示GridView数据时获取错误状态

时间:2014-03-28 14:25:05

标签: jquery asp.net ajax json gridview

我有一个.ajax来填充GridView。检索数据并GridView实际填充了数据,但.ajax函数调用未成功:

这是我的GridView

<div id="IsoContent">
             <asp:GridView ID="grvIsoSearchResults" runat="server"
                AutoGenerateColumns="false" PageSize="10"
                AllowPaging = "true" BorderColor="Red" GridLines="Both"                    
                style="position:absolute; top: 290px;"
                EnableViewState="False"
                EmptyDataText="no records found.">

                <PagerSettings firstpagetext="First" lastpagetext="Last" nextpagetext="Next" pagebuttoncount="50" Visible="true" />
                <PagerTemplate>
                    <table width="100%">
                        <tr>
                            <td style="width:70%" align="left">
                                <asp:Label ID="MessageLabel"
                                   ForeColor="white"
                                   Text="Select a page:"
                                   runat="server">
                                </asp:Label>
                                <asp:DropDownList ID="PageDropDownList"
                                    AutoPostBack="true"
                                    OnSelectedIndexChanged="PageDropDownList_SelectedIndexChanged"
                                    runat="server">
                                </asp:DropDownList>
                            </td>
                            <td style="width:70%; text-align:right">
                                <asp:Label ID="CurrentPageLabel"
                                    ForeColor="white"
                                    runat="server">
                                </asp:Label>     
                            </td>
                        </tr>
                    </table>

                </PagerTemplate>
                <Columns>
                   <asp:TemplateField HeaderText="ISONUM" SortExpression="isonum">
                        <ItemTemplate>
                            <asp:Label ID="txtgvIsoNum" Text = '<%# Eval("ISONUM")%>' runat="server" Width="70px" style="text-align:center" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="OFFICE NAME" SortExpression="isoofficename">
                        <ItemTemplate>
                            <asp:Label ID="txtgvIsoOfficeName" Text = '<%# Eval("ISOOFFICENAME")%>' runat="server" Width="200px" style="text-align:center" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="REGION" SortExpression="region">
                        <ItemTemplate>
                            <asp:Label ID="txtgvRegion" Text = '<%# Eval("REGION")%>' runat="server" Width="50px" style="text-align:center" />
                        </ItemTemplate>
                    </asp:TemplateField> 
                    <asp:TemplateField HeaderText="DIVISION" SortExpression="client_id">
                        <ItemTemplate>
                            <asp:Label ID="txtgvDivision" Text = '<%# Eval("CLIENT_ID")%>' runat="server" Width="50px" style="text-align:center" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="EMAIL ADDRESS">
                        <ItemTemplate>
                            <asp:TextBox ID="txtgvEmailAddress" Text = '<%# Eval("EMAIL")%>' runat="server" Width="200px" onclick="ResetMessage();"/>
                            <input type="button" value="Update" id="btnEmailUpdate" />
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <pagerstyle backcolor="#005482" ForeColor="White" height="30px" verticalalign="Bottom" horizontalalign="Center"/>
            </asp:GridView> 

</div>

然后我调用了一个.ajax调用的方法:

function PopulateGrid(option, input) {

    var ListOfData = $('#ISOData');
    ListOfData.html('');
    $.ajax({
        type: "GET",
        url: "IsoData.aspx",
        data: {'Option':option,'Input': input },
        cache:false,
        success: function (data, status) {
            var isoData = $(data);
            ListOfData.html(isoData.find("#IsoContent").html());
        },
        error: function (request, status, error) {
            $('#MainContent_lblMsg').text('Error retriving data. Please re-try');
            $('#MainContent_lblMsg').css('color', 'red');
        }
    });
}

这会在Page_Load上调用以下内容:

protected void Page_Load(object sender, EventArgs e)
{
    String option = Request.QueryString["Option"];
    String input = Request.QueryString["Input"];
    grvIsoSearchResults.DataSource = ISOProcessing.GetISOData(Request.QueryString["Option"], Request.QueryString["Input"]);
    grvIsoSearchResults.DataBind();
}

从数据库检索数据并将数据绑定到GridView时,一切正常。

但是.ajax调用会返回错误消息。

我不确定这里有什么问题。

有什么想法吗?

谢谢

---- ---- UPDATE

显示statuserror时,我得到:parsererrorInvalid JSON:

以下回复:

<!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></head>

<body>

<form method="post" action="IsoData.aspx?_=1396020642959&amp;Option=iso&amp;Input=2222" id="form1">

<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE1NTI3NzM5OTBkGAEFE2dydklzb1NlYXJjaFJlc3VsdHMPPCsADAEIAgFkGTQ2u3n53+sBuGt7K6dzJhMemQwnHBtL/zSaL0PTvxA=" />

</div>
<div class="aspNetHidden">
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBALS6sa5CALVm6TQAwLqrMbTAwL3yKLRA3fbY36YeUjQKyxkXK3bQ0wX9hLJS8sqHVwzTn28IwWT" />
</div>
   <div id="IsoContent">
   <div>
    <table cellspacing="0" rules="all" border="1" id="grvIsoSearchResults" style="border-color:Red;border-collapse:collapse;position:absolute; top: 290px;">
    <tr>
    <th scope="col">ISONUM</th><th scope="col">OFFICE NAME</th><th scope="col">REGION</th><th scope="col">DIVISION</th><th scope="col">EMAIL ADDRESS</th>
    </tr><tr>
    <td>
    <span id="grvIsoSearchResults_txtgvIsoNum_0" style="display:inline-block;width:70px;text-align:center">222222222 </span>
    </td><td>
    <span id="grvIsoSearchResults_txtgvIsoOfficeName_0" style="display:inline-block;width:200px;text-align:center">My Test, Test  </span>
    </td><td>
    <span id="grvIsoSearchResults_txtgvRegion_0" style="display:inline-block;width:50px;text-align:center">99</span>
   </td><td>
   <span id="grvIsoSearchResults_txtgvDivision_0" style="display:inline-block;width:50px;text-align:center">11111</span>
   </td><td>
   <input name="grvIsoSearchResults$ctl02$txtgvEmailAddress" type="text" value="email@life.net" id="grvIsoSearchResults_txtgvEmailAddress_0" onclick="ResetMessage();" style="width:200px;" />
   <input type="button" value="Update" id="btnEmailUpdate" />
  </td>
</tr><tr>
<td>
 <span id="grvIsoSearchResults_txtgvIsoNum_1" style="display:inline-block;width:70px;text-align:center">CB2222001 </span>
</td><td>
<span id="grvIsoSearchResults_txtgvIsoOfficeName_1" style="display:inline-block;width:200px;text-align:center">DENNIS PETROVIC          </span>
</td><td>
<span id="grvIsoSearchResults_txtgvRegion_1" style="display:inline-block;width:50px;text-align:center"></span>
</td><td>
<span id="grvIsoSearchResults_txtgvDivision_1" style="display:inline-block;width:50px;text-align:center">99801</span>
</td><td>
<input name="grvIsoSearchResults$ctl03$txtgvEmailAddress" type="text" value="dennis@dlgent.com" id="grvIsoSearchResults_txtgvEmailAddress_1" onclick="ResetMessage();" style="width:200px;" />
<input type="button" value="Update" id="btnEmailUpdate" />
</td>
</tr><tr>
<td>
<span id="grvIsoSearchResults_txtgvIsoNum_2" style="display:inline-block;width:70px;text-align:center">FT2222001 </span>
</td><td>
<span id="grvIsoSearchResults_txtgvIsoOfficeName_2" style="display:inline-block;width:200px;text-align:center">Test2</span>
</td><td>
<span id="grvIsoSearchResults_txtgvRegion_2" style="display:inline-block;width:50px;text-align:center"></span>
</td><td>
<span id="grvIsoSearchResults_txtgvDivision_2" style="display:inline-block;width:50px;text-align:center">99801</span>
</td><td>
<input name="grvIsoSearchResults$ctl04$txtgvEmailAddress" type="text" value="email2@email.com" id="grvIsoSearchResults_txtgvEmailAddress_2" onclick="ResetMessage();" style="width:200px;" />
<input type="button" value="Update" id="btnEmailUpdate" />
</td>
</tr>
</table>
</div> 
</div>
</form>

我不确定在哪里看

0 个答案:

没有答案