![]() |
| ||
| The Datagrid: How does one fill text boxes in edit mode with their original content? Hello, all! I'm working with a project to search a Microsoft Access database, show the results in a datagrid, create text boxes to edit the entries found, and then update them. So far, the search works great, and I have a typical datagrid with an "edit" button on the end, when you click on edit to switch the datagrid into edit mode, the options to update or cancel appear as I have intended, but empty textboxes replace the old data there. I would like the original data present until the user changes something and clicks "update." I have been trying to get a feel for how to reference these text boxes and fill them, but so far I only get errors. Here is my most recent attempt and the given error: Public Sub softwareGrid_EditCommand(ByVal source As Object, _ Feel free to comment on the update method as well, but the edit one is what's giving me the trouble right now. If I uncomment the second set of debug lines in the edit method, I get the following error: Error message: Specified argument was out of the range of valid values. Parameter name: index Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: index Source Error: Line 262: Me.BindDataGrid() Line 263: Dim txtSoftNum As String Line 264: txtSoftNum = CType(e.Item.Cells(0).Controls(0), TextBox).Text Line 265: Debug.WriteLine("test") Line 266: Debug.WriteLine(txtSoftNum) Source File: c:\inetpub\wwwroot\ASPproject\WebApplication2\WebForm1.aspx.vb Line: 264 Stack Trace: [ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: index] System.Web.UI.ControlCollection.get_Item(Int32 index) WebApplication2.WebForm1.softwareGrid_EditCommand(Object source, DataGridCommandEventArgs e) in c:\inetpub\wwwroot\ASPproject\WebApplication2\WebForm1.aspx.vb:264 System.Web.UI.WebControls.DataGrid.OnEditCommand(DataGridCommandEventArgs e) System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e) System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e) System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) System.Web.UI.Page.ProcessRequestMain() So yeah, the debugger shoots out a '0' for the editItemIndex, which I believe should be correct, and then errors out on the next debug request. The idea there was to see if the text box really had anything in it. So thats it, I need to know how to fill those text boxes, and how to reference them properly with index values. Of course, any and all help would be greatly a-pree-key-8-ed. Thanks! :D |
| ||
| Re: The Datagrid: How does one fill text boxes in edit mode with their original content? One more wierd thing: when you click on edit, nothing happens, then if you click it again, the empty text boxes appear. Hope that helps, maybe. :-| |
| ||
| Re: The Datagrid: How does one fill text boxes in edit mode with their original content? Buddy, I tried following your code but could not come into any conclusion.There is insufficient information,your client side datagrid isnt posted. I have done something like this in the past. This article does EXACTLY WHAT YOUR TRYING TO DO Check it out. http://aspnet.4guysfromrolla.com/art...71002-1.2.aspx HOPE IT HELPS |
| ||
| Re: The Datagrid: How does one fill text boxes in edit mode with their original content? Thank you for your time, and yes, the resource you gave me has been a great help. My apologies for not including enough information in my former post. This project is getting rather large, and sometimes I briefly lose track of relevant code. :o Although, I've kept it well organized, be assured! I will post the results of my efforts soon. Thanks again. |
| ||
| Re: The Datagrid: How does one fill text boxes in edit mode with their original content? I'd like to give the Sub that creates the datagrid as LetsCode requested. Hope this isn't too much code for y'all to handle! Believe me there's a lot more in the project as a whole! Here we go: Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal E As System.EventArgs) Handles btnSearch.Click |
| ||
| Re: The Datagrid: How does one fill text boxes in edit mode with their original content? Since LetsCode's last post I have reevaluated the values of my datagrid textboxes and believe I have solved the pervious indexing error. I won't know for sure until I address the other major error I keep returning to, given as follows: Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: Line 245: Line 246: If ValidEntry(tbSoftwareNum, tbSoftwareName, tbLocation) Then Line 247: Dim dr As DataRow = dsSoftware.Tables("[SOFTWARE DATABASE]").Rows(E.Item.ItemIndex) Line 248: Try Line 249: dr("Software #") = tbSoftwareNum Source File: c:\inetpub\wwwroot\ASPproject\WebApplication2\WebForm1.aspx.vb Line: 247 Stack Trace: [NullReferenceException: Object reference not set to an instance of an object.] WebApplication2.WebForm1.softwareGrid_UpdateCommand(Object source, DataGridCommandEventArgs E) in c:\inetpub\wwwroot\ASPproject\WebApplication2\WebForm1.aspx.vb:247 System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventArgs e) System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e) System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e) System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) System.Web.UI.Page.ProcessRequestMain() :idea: :idea: :idea: This is part of the new and improved Sub softwareGrid_UpdateCommand, which is as follows: Public Sub softwareGrid_UpdateCommand(ByVal source As Object, ByVal E As DataGridCommandEventArgs) Handles softwareGrid.UpdateCommand Anyone know how to check the validity of the line: Dim dr As DataRow = dsSoftware.Tables("[SOFTWARE DATABASE]").Rows(E.Item.ItemIndex) Thank you for troubling through all this code. Any and all help will be welcomed with open arms! :mrgreen: I refuse to give up! Optimism thrives still! |
| ||
| Re: The Datagrid: How does one fill text boxes in edit mode with their original content? dsSoftware.Tables("[SOFTWARE DATABASE]").Rows(E.Item.ItemIndex)Is [SOFTWARE DATABASE] the table name or database name? It should be the table to execute properly. |
| ||
| Re: The Datagrid: How does one fill text boxes in edit mode with their original content? Quote:
[SOFTWARE DATABASE] is the table name. In brackets so it can recognize the name with the space. Terrible name, but hey, I didn't pick it. Any ideas on this? |
| ||
| Re: The Datagrid: How does one fill text boxes in edit mode with their original content? Solved my own problem. I had 2 separate instances of the same data set. Thank you for those who assisted me in this. |
| All times are GMT -4. The time now is 1:47 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC