Results 1 to 26 of 26

Thread: Search + Sum + GridView + Edit

  1. #1

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Search + Sum + GridView + Edit

    Hi,

    I would like to have your opinion on how how i should do this.
    I would like to run a search and show the result on the grid view from my database.
    The search have many criteria , means user can search by first name and last name and amount ....
    Then i would like the user to be able to be able to edit and delete the records.
    And finally i would like to show a row showing the sum of some fields.

    Can you please tell me how i should proceed, and which system i don't have to use?

    Thanks

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Search + Sum + GridView + Edit

    Hey,

    From the ground up, you are going to need something like the following:

    1) Create a connection to your database
    2) Create a command object, and set the CommandText property to the query or stored procedure that you want to use
    3) Create parameters for each of the "where" clauses that the user can choose from
    4) Execute the command
    5) Prepare the results, and set the result to the DataSource Property of the GridView
    6) Edit the GridView to include a sum of the necessary fields:
    http://msdn.microsoft.com/en-us/library/ms972833.aspx

    Gary

  3. #3

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Search + Sum + GridView + Edit

    Hi,

    For the edit and delete button, how should i include that?

    thanks

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Search + Sum + GridView + Edit

    Hey,

    Handle the RowDeleting and RowEditing events of the GridView, and do the necessary query on the database to update the underlying table.

    Gary

  5. #5

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Search + Sum + GridView + Edit

    Ok, I have wrote the code "it's a bit big to post" but if required i will, and whenever i turn on the edit mode, and then click on the edit button i get the following error
    Code:
    The GridView 'GridView1' fired event RowEditing which wasn't handled.

    thanks

  6. #6
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Search + Sum + GridView + Edit

    Hey,

    That error would suggest that you have not implemented the RowEditing event. Have you?

    Gary

  7. #7

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Search + Sum + GridView + Edit

    Hi,

    Ok, I added the the rowediting event, but it's empty, what code should i write in it?

    thanks

  8. #8

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Search + Sum + GridView + Edit

    I tried to use the following code under the rowediting event, but nothing it's happening

    vb Code:
    1. GridView1.EditIndex = e.NewEditIndex
    2.         'Bind data to the GridView control.
    3.         GridView1.DataBind()

  9. #9
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Search + Sum + GridView + Edit

    Hey,

    The code necessary to edit the underlying table.

    i.e. a query that will take all the changes to the values, and update the database table.

    Gary

  10. #10
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Search + Sum + GridView + Edit

    Quote Originally Posted by met0555 View Post
    I tried to use the following code under the rowediting event, but nothing it's happening

    vb Code:
    1. GridView1.EditIndex = e.NewEditIndex
    2.         'Bind data to the GridView control.
    3.         GridView1.DataBind()
    What exactly are you expecting that to do?

    You need to take a step back and understand exactly what you are trying to achieve before writing any code!

    Gary

  11. #11

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Search + Sum + GridView + Edit

    I guess what i need now, is to be in the edit mode when the button is clicked. :S

  12. #12
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Search + Sum + GridView + Edit

    Set the GridView's AutoGenerateEditButton property to true. That should give you a button. Click on it, it goes into Edit Mode.

  13. #13

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Search + Sum + GridView + Edit

    Hi,
    It just redirect be to a blank page.

    thanks

  14. #14

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Search + Sum + GridView + Edit

    ok, here is my code

    vb Code:
    1. Dim sqlstr As String
    2.         sqlstr = "select * from trackmain where " + pwhereClause + "ORDER BY datee DESC"
    3.         Dim dt As DataTable
    4.         Dim datatable1 As DataTable
    5.  
    6.         Dim command As New DbCommand(sqlstr, CommandType.Text, Nothing)
    7.  
    8.  
    9.         datatable1 = command.ExecuteDataTable()
    10.  
    11.  
    12.         dt = GetCustDT()
    13.         If (datatable1.Rows.Count > 0) Then
    14.  
    15.  
    16.             Dim str As String()
    17.  
    18.             str = (datatable1.Rows.Count / _rowCount).ToString().Split(".")
    19.             If (str.Count > 1) Then
    20.  
    21.                 hfPageCount.Value = Convert.ToInt32(str(0)) + 1
    22.                 hflastpagecount.Value = datatable1.Rows.Count Mod _rowCount
    23.             Else
    24.                 hfPageCount.Value = Convert.ToInt32(str(0))
    25.                 hflastpagecount.Value = datatable1.Rows.Count Mod _rowCount
    26.             End If
    27.  
    28.  
    29.  
    30.  
    31.  
    32.  
    33.             If (hfCurrentPage.Value = 1) Then
    34.                 hfStartIndex.Value = 0
    35.                 If (hfPageCount.Value = hfCurrentPage.Value) Then
    36.                     hfEndIndex.Value = hflastpagecount.Value - 1
    37.                     btnNext.Enabled = False
    38.                     btnPrevious.Enabled = False
    39.                 Else
    40.                     hfEndIndex.Value = _rowCount - 1
    41.                     btnNext.Enabled = True
    42.                     btnPrevious.Enabled = False
    43.                 End If
    44.  
    45.             Else
    46.                 If (Convert.ToInt32(hfPageCount.Value) > Convert.ToInt32(hfCurrentPage.Value)) Then
    47.                     hfStartIndex.Value = (hfCurrentPage.Value - 1) * _rowCount
    48.                     hfEndIndex.Value = hfStartIndex.Value + _rowCount - 1
    49.                     btnNext.Enabled = True
    50.                     btnPrevious.Enabled = True
    51.                 ElseIf (Convert.ToInt32(hfPageCount.Value) = Convert.ToInt32(hfCurrentPage.Value)) Then
    52.                     hfStartIndex.Value = (hfCurrentPage.Value - 1) * _rowCount
    53.                     If (Convert.ToInt32(hflastpagecount.Value) = 0) Then
    54.                         hfEndIndex.Value = Convert.ToInt32(hfStartIndex.Value) + _rowCount - 1
    55.                     Else
    56.                         hfEndIndex.Value = Convert.ToInt32(hfStartIndex.Value) + Convert.ToInt32(hflastpagecount.Value - 1)
    57.                     End If
    58.  
    59.                     btnNext.Enabled = False
    60.                     btnPrevious.Enabled = True
    61.                 End If
    62.             End If
    63.  
    64.  
    65.  
    66.  
    67.  
    68.             Dim i As Integer
    69.             Dim inhouse As Decimal = 0
    70.             Dim payouts As Decimal = 0
    71.             Dim expenses As Decimal = 0
    72.             Dim net As Decimal = 0
    73.  
    74.  
    75.  
    76.  
    77.             For i = Convert.ToInt32(hfStartIndex.Value) To Convert.ToInt32(hfEndIndex.Value) 'datatable1.Rows.Count - 1
    78.                 dt.Rows.Add(New String() {datatable1.Rows(i)("ID").ToString(), datatable1.Rows(i)("dayy").ToString(), datatable1.Rows(i)("datee").ToString(), datatable1.Rows(i)("Client").ToString(), datatable1.Rows(i)("fromto").ToString(), datatable1.Rows(i)("collect").ToString(), datatable1.Rows(i)("via").ToString(), datatable1.Rows(i)("gross").ToString(), datatable1.Rows(i)("inhouse").ToString(), datatable1.Rows(i)("payouts").ToString(), datatable1.Rows(i)("expenses").ToString(), datatable1.Rows(i)("Net").ToString(), datatable1.Rows(i)("reconciliated").ToString(), datatable1.Rows(i)("farm").ToString()})
    79.  
    80.                 SubTotal = SubTotal + (Convert.ToDecimal(datatable1.Rows(i)("gross").ToString)) 'gross
    81.                 inhouse = inhouse + (Convert.ToDecimal(datatable1.Rows(i)("inhouse").ToString))
    82.                 payouts = payouts + (Convert.ToDecimal(datatable1.Rows(i)("payouts").ToString))
    83.                 expenses = expenses + (Convert.ToDecimal(datatable1.Rows(i)("expenses").ToString))
    84.                 net = net + (Convert.ToDecimal(datatable1.Rows(i)("net").ToString))
    85.  
    86.             Next
    87.  
    88.             If (btnType = "next") Then
    89.                 hfTotalGross.Value = Convert.ToDecimal(hfTotalGross.Value) + Convert.ToDecimal(SubTotal)
    90.  
    91.                 hfTotalInhouse.Value = Convert.ToDecimal(hfTotalInhouse.Value) + Convert.ToDecimal(inhouse)
    92.                 hfTotalPayouts.Value = Convert.ToDecimal(hfTotalPayouts.Value) + Convert.ToDecimal(payouts)
    93.  
    94.                 hfTotalexpense.Value = Convert.ToDecimal(hfTotalexpense.Value) + Convert.ToDecimal(expenses)
    95.                 hfTotalNet.Value = Convert.ToDecimal(hfTotalNet.Value) + Convert.ToDecimal(net)
    96.             ElseIf (btnType = "pre") Then
    97.  
    98.  
    99.  
    100.                 hfTotalGross.Value = Convert.ToDecimal(hfTotalGross.Value) - Convert.ToDecimal(hfSubGross.Value)
    101.  
    102.                 hfTotalInhouse.Value = Convert.ToDecimal(hfTotalInhouse.Value) - Convert.ToDecimal(hfSubInhouse.Value)
    103.                 hfTotalPayouts.Value = Convert.ToDecimal(hfTotalPayouts.Value) - Convert.ToDecimal(hfSubPayouts.Value)
    104.  
    105.                 hfTotalexpense.Value = Convert.ToDecimal(hfTotalexpense.Value) - Convert.ToDecimal(hfSubexpense.Value)
    106.                 hfTotalNet.Value = Convert.ToDecimal(hfTotalNet.Value) - Convert.ToDecimal(hfSubNet.Value)
    107.             Else
    108.                 hfTotalGross.Value = Convert.ToDecimal(SubTotal)
    109.                 hfTotalInhouse.Value = inhouse
    110.                 hfTotalPayouts.Value = payouts
    111.  
    112.                 hfTotalexpense.Value = expenses
    113.                 hfTotalNet.Value = net
    114.                 btnPrevious.Enabled = False
    115.             End If
    116.             'hfSubVia.Value = via
    117.             hfSubGross.Value = Convert.ToDecimal(SubTotal)
    118.             hfSubInhouse.Value = inhouse
    119.             hfSubPayouts.Value = payouts
    120.             hfSubexpense.Value = expenses
    121.             hfSubNet.Value = net
    122.  
    123.             dt.Rows.Add(New String() {"", "", "", "", "", "Sub Total", "", Convert.ToString(hfSubGross.Value), Convert.ToString(inhouse), Convert.ToString(payouts), Convert.ToString(expenses), Convert.ToString(net), "", ""})
    124.             dt.Rows.Add(New String() {"", "", "", "", "", "Total", "", Convert.ToString(hfTotalGross.Value), Convert.ToString(hfTotalInhouse.Value), Convert.ToString(hfTotalPayouts.Value), Convert.ToString(hfTotalexpense.Value), Convert.ToString(hfTotalNet.Value)})
    125.             ' GridView1.AutoGenerateEditButton = True
    126.             GridView1.DataSource = dt
    127.             GridView1.DataBind()
    128.         Else
    129.             lblmsg.Text = "no result found"
    130.             btnNext.Enabled = False
    131.             btnPrevious.Enabled = False
    132.             btnPrint.Enabled = False
    133.         End If
    134.  
    135.     End Sub
    136.     Public Function GetCustDT() As DataTable
    137.         Dim dt As New DataTable
    138.         dt.Columns.Add("Id", GetType(String))
    139.         dt.Columns.Add("Day", GetType(String))
    140.         dt.Columns.Add("Date", GetType(String))
    141.         dt.Columns.Add("Client", GetType(String))
    142.         dt.Columns.Add("From-To", GetType(String))
    143.         dt.Columns.Add("Collect", GetType(String))
    144.         dt.Columns.Add("Via", GetType(String))
    145.         dt.Columns.Add("Gross", GetType(String))
    146.         dt.Columns.Add("In-House", GetType(String))
    147.         dt.Columns.Add("Payouts", GetType(String))
    148.         dt.Columns.Add("Expenses", GetType(String))
    149.         dt.Columns.Add("Net", GetType(String))
    150.         dt.Columns.Add("Status", GetType(String))
    151.         dt.Columns.Add("Farm", GetType(String))
    152.         Return dt
    153.     End Function
    154.  
    155.     Protected Sub btnPrevious_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    156.         hfCurrentPage.Value = hfCurrentPage.Value - 1
    157.         btnType = "pre"
    158.         setQueryValue()
    159.         getSearchResult(txtDate, txtclient, txtfarm, txtcollect, txtvia, txtgross, txtgross2, txtNet, txtNet2, txtexpenses, txtexpenses2, txtDay, txtdate1, txtdate2)
    160.  
    161.     End Sub
    162.  
    163.     Protected Sub btnnext_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    164.         hfCurrentPage.Value = hfCurrentPage.Value + 1
    165.         btnType = "next"
    166.         setQueryValue()
    167.         getSearchResult(txtDate, txtclient, txtfarm, txtcollect, txtvia, txtgross, txtgross2, txtNet, txtNet2, txtexpenses, txtexpenses2, txtDay, txtdate1, txtdate2)
    168.  
    169.     End Sub
    170.  
    171.  
    172.    
    173.  
    174.     Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs)
    175.         '  Dim GridView1 As GridView
    176.  
    177.         Dim GridView1 As GridView = TryCast(LoginView1.FindControl("GridView1"), GridView)
    178.         GridView1.EditIndex = e.NewEditIndex
    179.      
    180.         BindData()
    181.     End Sub
    182.  
    183.     Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs)
    184.         Dim GridView1 As GridView = TryCast(LoginView1.FindControl("GridView1"), GridView)
    185.  
    186.         GridView1.PageIndex = e.NewPageIndex
    187.         'Bind data to the GridView control.
    188.           BindData()
    189.  
    190.     End Sub
    191.     Private Sub BindData()
    192.         Dim GridView1 As GridView = TryCast(LoginView1.FindControl("GridView1"), GridView)
    193.  
    194.         GridView1.DataSource = Session("trackmain")
    195.         GridView1.DataBind()
    196.     End Sub
    197.  
    198.     Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs)
    199.         Dim GridView1 As GridView = TryCast(LoginView1.FindControl("GridView1"), GridView)
    200.  
    201.         GridView1.EditIndex = -1
    202.  
    203.     End Sub
    204.  
    205.     Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs)
    206.         Dim GridView1 As GridView = TryCast(LoginView1.FindControl("GridView1"), GridView)
    207.  
    208.         Dim dt = CType(Session("trackmain"), DataTable)
    209.  
    210.         'Update the values.
    211.         Dim row = GridView1.Rows(e.RowIndex)
    212.         dt.Rows(row.DataItemIndex)("Id") = (CType((row.Cells(0).Controls(0)), TextBox)).Text
    213.        
    214.  
    215.         'Reset the edit index.
    216.         GridView1.EditIndex = -1
    217.  
    218.  
    219.     End Sub
    220. End Class

  15. #15
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Search + Sum + GridView + Edit

    Does line 177 get hit when you click on the Edit button?

  16. #16

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Search + Sum + GridView + Edit

    Hi,

    Yes it hits

  17. #17

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Search + Sum + GridView + Edit

    any help please.

  18. #18
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Search + Sum + GridView + Edit

    OK, so you're saying line 177 is hit and therefore the BindData() method is called. But then it sends you to a blank page? Step through the code in its entirety. At what point in the code does it suddenly give you a blank page?

  19. #19

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Search + Sum + GridView + Edit

    Hi,

    I changed some line of code.... and using this code, i'm able to see the edit mode gridview but i have to click twice the button to go to the edit mode and the edit textboxes are blank.
    Still even when it's blank i tried to edit rows value i get the following error
    Code:
    Object reference not set to an instance of an object.
    at this line
    vb Code:
    1. dt.Rows(row.DataItemIndex)("client") = (CType((row.Cells(4).Controls(0)), TextBox)).Text

    current code

    vb Code:
    1. Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs)
    2.         '  Dim GridView1 As GridView
    3.  
    4.         Dim GridView1 As GridView = TryCast(LoginView1.FindControl("GridView1"), GridView)
    5.         GridView1.EditIndex = e.NewEditIndex
    6.  
    7.  
    8.     End Sub
    9.  
    10.     Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs)
    11.         Dim GridView1 As GridView = TryCast(LoginView1.FindControl("GridView1"), GridView)
    12.  
    13.         GridView1.PageIndex = e.NewPageIndex
    14.        
    15.     End Sub
    16.     Private Sub BindData()
    17.         Dim GridView1 As GridView = TryCast(LoginView1.FindControl("GridView1"), GridView)
    18.  
    19.         GridView1.DataSource = Session("trackmain")
    20.         GridView1.DataBind()
    21.     End Sub
    22.  
    23.     Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs)
    24.         Dim GridView1 As GridView = TryCast(LoginView1.FindControl("GridView1"), GridView)
    25.  
    26.         GridView1.EditIndex = -1
    27.  
    28.     End Sub
    29.  
    30.     Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs)
    31.         Dim GridView1 As GridView = TryCast(LoginView1.FindControl("GridView1"), GridView)
    32.  
    33.         Dim dt = CType(Session("trackmain"), DataTable)
    34.  
    35.         'Update the values.
    36.         Dim row = GridView1.Rows(e.RowIndex)
    37.         dt.Rows(row.DataItemIndex)("client") = (CType((row.Cells(4).Controls(0)), TextBox)).Text
    38.  
    39.         GridView1.EditIndex = -1
    40.  
    41.  
    42.     End Sub
    43. End Class

    thanks

  20. #20
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Search + Sum + GridView + Edit

    Set a breakpoint on #37 and do a quickwatch on row.Cells(4). (Highlight it and press Ctrl+Alt+Q). It's likely that it shows you null. If it doesn't, explore the Controls collection. It's also possible that the textbox is Controls(1) or that the textbox is in a child of Controls(0).

  21. #21
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Search + Sum + GridView + Edit

    You can also show us your grid markup.

  22. #22

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Search + Sum + GridView + Edit

    The value is null, if it helps, the gridview is under a login control

    vb Code:
    1. <asp:GridView ID="GridView1" runat="server"
    2.                      
    3.                         AutoGenerateEditButton="True" onpageindexchanging="GridView1_PageIndexChanging"
    4.                           onrowcancelingedit="GridView1_RowCancelingEdit"
    5.                           onrowediting="GridView1_RowEditing" onrowupdating="GridView1_RowUpdating" >
    6.                       </asp:GridView>

  23. #23

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Search + Sum + GridView + Edit

    i fixed the code at this line, but still get error.

    vb Code:
    1. Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs)
    2.         Dim GridView1 As GridView = TryCast(LoginView1.FindControl("GridView1"), GridView)
    3.  
    4.         Dim dt = GetCustDT()
    5.  
    6.         'Update the values.
    7.         Dim row = GridView1.Rows(e.RowIndex)
    8.         dt.Rows(row.DataItemIndex)("Client") = (CType((row.Cells(3).Controls(0)), TextBox)).Text
    9.  
    10.         GridView1.EditIndex = -1
    11.  
    12.  
    13.     End Sub

    The error i get now is
    Code:
    No row at position 0
    vb Code:
    1. #
    2. Public Function GetCustDT() As DataTable
    3. #
    4.         Dim dt As New DataTable
    5. #
    6.         dt.Columns.Add("Id", GetType(String))
    7. #
    8.         dt.Columns.Add("Day", GetType(String))
    9. #
    10.         dt.Columns.Add("Date", GetType(String))
    11. #
    12.         dt.Columns.Add("Client", GetType(String))
    13. #
    14.         dt.Columns.Add("From-To", GetType(String))
    15. #
    16.         dt.Columns.Add("Collect", GetType(String))
    17. #
    18.         dt.Columns.Add("Via", GetType(String))
    19. #
    20.         dt.Columns.Add("Gross", GetType(String))
    21. #
    22.         dt.Columns.Add("In-House", GetType(String))
    23. #
    24.         dt.Columns.Add("Payouts", GetType(String))
    25. #
    26.         dt.Columns.Add("Expenses", GetType(String))
    27. #
    28.         dt.Columns.Add("Net", GetType(String))
    29. #
    30.         dt.Columns.Add("Status", GetType(String))
    31. #
    32.         dt.Columns.Add("Farm", GetType(String))
    33. #
    34.         Return dt
    35. #
    36.     End Function

  24. #24
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Search + Sum + GridView + Edit

    Hey,

    Is it possible that you can upload a complete project? It is getting to the point that this is getting hard to follow? If not, can you knock up a sample project, based on what you currently have, and upload that?

    Gary

  25. #25

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Search + Sum + GridView + Edit

    here is the project with the SQL script


    thx
    Attached Files Attached Files

  26. #26
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Search + Sum + GridView + Edit

    I think I see the problem here.

    When you do your RowUpdating, you're attempting to assign a value to a row in a datatable. However, this datatable is empty. If you look at GetCustDT(), all you're doing is defining the datatable, but no rows. You'd normally create a row by using dt.NewRow() and assigning it a value, but I don't think this is what you want. You want to update the database with your new value.

    The original datatable you used is in another method, when you bind the grid. It's out of scope now.

    Either make it class-level and fill the datatable up each time you load the page, and then update the row and call dataadapter.update

    or

    Use a SqlCommand, create your UPDATE statement and call ExecuteNonQuery and then rebind your grid.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width