2011-12-07 76 views
1

這裏是我的場景,我已經實現了一個gridview,當用戶按下頁面上的添加按鈕時,使用javascript的空輸入文本生成一個新行,然後用戶填寫輸入並按下保存按鈕,從而全部值作爲對象發送到處理數據插入的web服務。之後,我想刷新網格,綁定(刷新)我的GridView,因爲我插入的HTML按鈕的數據沒有回傳。我知道,當你從javascript訪問gridview它呈現爲一個HTML表有一種方式,我可以將數據綁定到它,有沒有解決方案?使用javascript綁定gridview?

+0

有一個解決方案,我認爲也許會工作,但我將不得不嘗試它,這是空的gridview表,並通過添加每個單元格再次構建它。 –

回答

2

這件事情取決於你的GridView結構,當然你可以使用HTML DOM模型來修改它並在gridview結尾插入新行。但是需要大量的手工努力來實現這個目標,並且有更多的錯誤發生。

另一種方法可以使用UpdatePanel。

<ajax:UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Conditional"> 
          <ContentTemplate> 
            <asp:GridView ID="GridView" Visible="false" runat="server" HeaderStyle-Width="200" HeaderStyle-BackColor="#2B6292" HeaderStyle-ForeColor="White" 
            AllowSorting="true" AllowPaging="true" Width="600" AutoGenerateColumns="False" OnRowCreated="GridView_OnRowCreated" 
            DataKeyNames="Id" onsorting="GridView_OnSort"> 
              <Columns> 
                ... 
              </Columns> 
            </asp:GridView> 
          </ContentTemplate> 
          <Triggers> 
            <ajax:AsyncPostBackTrigger ControlID="CreateButton"/> 
          </Triggers> 
        </ajax:UpdatePanel> 

請參閱http://blogs.microsoft.co.il/blogs/dorony/archive/2008/05/23/using-updatepanel-to-disable-gridview-view-state.aspx瞭解更多信息。

+0

我實際上想使用HTMl,但是我在如何在javascript中檢索一個對象數組到一個數組對象。每當我檢索它說的對象未定義的數據。 students = GetAllStudents(); –

+0

是否可以發佈代碼,在哪裏製作ajax請求和webmethod,它將返回GetAllStudents?基本上有.d或.data屬性是學生的數組。 – codeSetter

+0

我提出了一個關於它的問題:http://stackoverflow.com/questions/8429363/retrive-value-from-webservice-called-from-javascipt –