如何使用网格编辑数据? [英] how to use grid for edit data ?

查看:60
本文介绍了如何使用网格编辑数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<InlineFormModeTemplate>
                                  <div style="font-family: Tahoma; font-size: 12px;">
                                      Edit the values
                                      <br />
                                      <br />
                                      <table>
                                          <tr>
                                              <td>
                                                  Customer ID:
                                              </td>
                                              <td>
                                                  <%--<asp:TextBox ID="CustomerIDTB" runat="server" Enabled="<%#Container.CurrentRecord is GridRecord ? false : true%>"
                                                      Text='<%#GetFieldValue("CustomerID", Container)%>'>
                                                      </asp:TextBox>--%>
                                              </td>
                                          </tr>
                                          <tr>
                                          </tr>
                                          <tr>
                                              <td>
                                                  Contact Name:
                                              </td>
                                              <td>
                                                  <asp:TextBox ID="ContNameTB" runat="server" Text='<%#GetFieldValue("ContactName", Container)%>'>
                                                      </asp:TextBox>
                                              </td>
                                              <td>
                                                  Company Name:
                                              </td>
                                              <td>
                                                  <asp:TextBox ID="CompNameTB" runat="server" Text='<%#GetFieldValue("CompanyName", Container)%>'>
                                                      </asp:TextBox>
                                              </td>
                                          </tr>
                                          <tr>
                                              <td>
                                                  City:
                                              </td>
                                              <td>
                                                  <asp:TextBox ID="CityTB" runat="server" Text='<%#GetFieldValue("City", Container)%>'>
                                                      </asp:TextBox>
                                              </td>
                                              <td>
                                                  Country:
                                              </td>
                                              <td>
                                                  <asp:TextBox ID="CountryTB" runat="server" Text='<%#GetFieldValue("Country", Container)%>'>
                                                      </asp:TextBox>
                                              </td>
                                          </tr>
                                      </table>
                                      <br />
                                  </div>
                              </InlineFormModeTemplate>















vb ---------------










vb ---------------

Protected Function GetFieldValue(ByVal fieldName As String, ByVal container As GridFormEditCell) As String
       Dim editRecord As Record = container.CurrentRecord
       Return editRecord.GetValue(fieldName).ToString()
   End Function

   Public Sub GridGroupingControl1_BarButtonItemClicked(ByVal source As Object, ByVal e As Syncfusion.Web.UI.WebControls.Grid.Grouping.ButtonBarItemClickEventArgs)
       If Me.GridGroupingControl1.TableDescriptor.FormEditMode <> TableEditMode.UseTemplateForm AndAlso Me.GridGroupingControl1.TableDescriptor.FormEditMode <> TableEditMode.UseInlineTemplateForm Then
           Return
       End If

       If e.ButtonBarItem.ButtonBarItemType = ButtonBarItemType.Save Then
           Dim curRecord As Record = Me.GridGroupingControl1.FormEditCell.CurrentRecord

           Dim tb As TextBox = TryCast(Me.GridGroupingControl1.FormEditCell.FindControl("CustomerIDTB"), TextBox)
           ' If editing a current record, this will be disabled and the value will not be available.
           ' But this will be enabled when editing a new record, then lets go ahead and process it.
           If tb.Enabled Then
               curRecord.SetValue("CustomerID", tb.Text)
           End If

           tb = TryCast(Me.GridGroupingControl1.FormEditCell.FindControl("ContNameTB"), TextBox)
           curRecord.SetValue("ContactName", tb.Text)

           tb = TryCast(Me.GridGroupingControl1.FormEditCell.FindControl("CompNameTB"), TextBox)
           curRecord.SetValue("CompanyName", tb.Text)

           tb = TryCast(Me.GridGroupingControl1.FormEditCell.FindControl("CityTB"), TextBox)
           curRecord.SetValue("City", tb.Text)

           tb = TryCast(Me.GridGroupingControl1.FormEditCell.FindControl("CountryTB"), TextBox)
           curRecord.SetValue("Country", tb.Text)

           Me.GridGroupingControl1.Table.EndEdit()
           e.Handled = True
       End If

   End Sub









plz help

我收到错误

对象引用未设置为一个对象的实例。





plz help
i'm getting error
Object reference not set to an instance of an object.

推荐答案

Hello Neeraj,错误 - 对象引用未设置为对象的实例是一个非常常见的错误,每当生成我们尝试访问null(或没有)对象的任何属性。



换句话说,如果我们尝试设置/获取任何属性,我们会收到此错误未实例化或创建的对象。



作为 Wes Aday [ ^建议,您必须调试代码以确定问题所在。除了你自己之外别无他法。



如果您有任何疑问,请与我们联系。



- DD
Hello Neeraj, The error - "Object reference not set to an instance of an object" is a very common error which is generated whenever we try to access any property of a null (or nothing) object.

In other words, we get this error if we try to set/get any property of an object which is not instantiated or created.

As Wes Aday[^] suggested, you have to debug your code to identify where the issue is. There is no other way around and no one can solve this but yourself.

Please let me know in case you have any further query.

- DD


这篇关于如何使用网格编辑数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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