Does anyone know how to load a row of the datgrid or the entire datagrid in edit mode instead of having to click the edit button?<BR>Couldn't you just call the datagrid edit sub at the end of the datagrid load sub?<BR><BR>Sort of like this:<BR><BR>Sub Page_Load()<BR><BR> "Your page load or data query here"<BR> DataGrid1.DataSource = dsScores<BR> DataGrid1.DataBind()<BR> DataGrid1_Edit<BR><BR>End Sub<BR><BR>Sub DataGrid1_Edit(obj as object, e as DataGridCommandEventArgs)<BR><BR> DataGrid1.EditItemIndex = e.Item.ItemIndex<BR> DataGrid1.DataBind()<BR><BR>End sub<BR><BR>Some kind of code along these lines should put you into edit mode when you load the grid. You can likely shorten the whole<BR>thing and just put the DataGrid1.EditItemIndex = right in the<BR>page load routine.<BR><BR><BR><BR>Good Luck,<BR><BR>Tom TThat seems logical. I had tried it before posting this. It dosent work
<BR><BR>If you call the procedure: MyDataGrid_Edit <BR><BR>From the form load you get the error:<BR><BR>Argument not specified for parameter 'E' of 'Public Sub MyDataGrid_Edit(Sender As Object, E As System.Web.UI.WebControls.DataGridCommandEventArgs )'.<BR><BR>If you try to shorten it by putting: <BR>MyDataGrid.EditItemIndex = CInt(E.Item.ItemIndex)<BR><BR>if form load that gives you and error msg as well.<BR><BR>I also tried putting this in MyDataGrid_ItemDataBound. That doesent work quite right either.<BR><BR>Any other ideas?? Thanks for the suggestion though!I just ran code where I loaded the datagrid and just before<BR>the DataBind() I added the line:<BR><BR>DataGrid1.EditItemIndex = 0<BR><BR>The code loop (I left out the connection stuff) looked like this:<BR><BR>Dim objCmd As New OleDbDataAdapter _<BR>("Select * from Scores", objConn)<BR><BR>Dim dsScores As DataSet = New Dataset()<BR><BR>objCmd.Fill(dsScores, "Scores")<BR><BR>DataGrid1.DataSource = dsScores<BR> <BR>DataGrid1.DataMember = "Scores"<BR><BR>DataGrid1.EditItemIndex = 0<BR><BR>DataBind()<BR><BR>When I ran it, it loaded the datagrid and opened the first line in edit mode.<BR><BR>Tom Thmmmmm - That does make sense. However, i can not get it to work on my code. No error message or anything. I tried putting the statement mydatagrid.edititemindex = 0 in the form load, and when that did not work i tired it in my bindgrid(). But still no edit mode. No errors either.<BR><BR>Here is my bindgrid()<BR><BR>Dim DS As DataSet<BR> Dim MyCommand As OleDbDataAdapter<BR> MyCommand = new OleDbDataAdapter("select ordernum, vendor1N, Vendor1C, Vendor2N, Vendor2C, Vendor3N, Vendor3C, Vendor4N, Vendor4C, Revenue from tblOrdersProcessed WHERE OrderNum = " & OrderID.text, MyConnection)<BR><BR> DS = new DataSet()<BR> MyCommand.Fill(DS, "tblOrdersProcessed")<BR> MyDataGrid.DataSource=DS.Tables("tblOrdersProcessed").DefaultView<BR> MyDataGrid.DataBind()<BR> MyDataGrid.EditItemIndex = 0<BR><BR><BR>Any thoughts as to what may be going wrong? Thank you very much for taking the time to offer suggestions on this!My dyslexia kicked in. I just realized you suggested putting mydatagrid.edititemindex = 0 BEFORE mydatagrid.databind() and not AFTER.<BR><BR>I corrected my mistake and i do get and error message that says: Object reference not set to an instance of an object<BR><BR>Any ideas?<BR><BR>ThanksI think you're actually there. The error you're getting sounds like (excuse me, but it's late) a typing error. I usually get that when I mis-type a variable or object name.<BR><BR>With the change you made to do binding after setting the editItemIndex, it should work with no problems. <BR><BR>Repost your code again if it is something else and I'll substitute my database and run it.<BR><BR>Since I'm on west coast time, it must be later where you are.<BR><BR>Good Luck<BR><BR>Tom TI tested your suggestion of mydatagrid.edititemindex = 0 on another datagrid i had, and it worked fine. My data grid is and editiable datagrid with a list box. I think that may be part of the problem of why i get the error message: Object reference not set to an instance of an object<BR><BR>Im going to post my code. If you see anything that may be causing the problem, please let me know. Im going to play around with it some more.<BR><BR><BR>Thanks again for all the help!!<BR><BR>___________________________________________<BR><BR><!--#Include File = "DBinventory.aspx"--><BR><!--#Include File="Header.aspx"--><BR><BR><html><BR><BR><script language="VB" runat="server"><BR><BR> <BR> Public vendor3CIndex As Hashtable<BR> <BR> Sub Page_Load(Src As Object, E As EventArgs)<BR><BR> If Not (IsPostBack)<BR> OrderID.text=Request.QueryString("OrderNUM")<BR> BindGrid()<BR> <BR> End If<BR><BR> vendor3CIndex = New Hashtable()<BR> <BR>vendor3CIndex("Select Vendor") = 0<BR>vendor3CIndex("Coast Index") = 1<BR>vendor3CIndex("Custom Tabs") = 2<BR>vendor3CIndex("GE Polymershapes") = 3<BR>vendor3CIndex("Image Star") = 4<BR>vendor3CIndex("Ingram Micro") = 5<BR>vendor3CIndex("Kleer Fax") = 6<BR>vendor3CIndex("Marks Papter") = 7<BR>vendor3CIndex("National Index") = 8<BR>vendor3CIndex("Original") = 9<BR>vendor3CIndex("Pengad") = 10<BR>vendor3CIndex("Shamrock") = 11<BR>vendor3CIndex("Southwest") = 12<BR>vendor3CIndex("Spiral") = 13<BR>vendor3CIndex("TEI") = 14<BR>vendor3CIndex("Unibind") = 15<BR>vendor3CIndex("United Manual") = 16<BR>vendor3CIndex("United Transmittal") = 17<BR> <BR> <BR> <BR> End Sub<BR><BR> Public Function Getvendor3CIndex(vendor3CName As String) As Integer<BR><BR> If vendor3CIndex(vendor3CName) <> Nothing<BR> Return CInt(vendor3CIndex(vendor3CName))<BR> Else<BR> Return 0<BR> End If<BR> End Function<BR><BR> Sub MyDataGrid_Edit(Sender As Object, E As DataGridCommandEventArgs)<BR><BR> MyDataGrid.EditItemIndex = CInt(E.Item.ItemIndex)<BR> BindGrid()<BR> End Sub<BR><BR> Sub MyDataGrid_Cancel(Sender As Object, E As DataGridCommandEventArgs)<BR><BR> MyDataGrid.EditItemIndex = -1<BR> BindGrid()<BR> End Sub<BR><BR><BR>Sub PlaceNewOrder_Click(sender As Object, e As EventArgs) <BR><BR><BR> dim url as string<BR> url="frmPlaceOrder.aspx"<BR> Response.Redirect(url)<BR><BR><BR>end Sub<BR><BR> Sub MyDataGrid_Update(Sender As Object, E As DataGridCommandEventArgs)<BR><BR> Dim DS As DataSet<BR> Dim MyCommand As oleDBCommand<BR><BR> Dim UpdateCmd As String = "UPDATE tblOrdersProcessed SET OrderNum = @OrderNum, Vendor1N = @Vendor1N, Vendor1C = @Vendor1C, Vendor2N = " _<BR> & " @Vendor2N, Vendor2C = @Vendor2C, Vendor3N = @Vendor3N, vendor3C = @vendor3C, vendor4N = @vendor4N, vendor4C = @vendor4C, Revenue = @Revenue where OrderNum = @OrderNum"<BR><BR> MyCommand = New oleDBCommand(UpdateCmd, MyConnection)<BR><BR> MyCommand.Parameters.Add(New OleDbParameter("@OrderNum", OleDbType.VarChar, 100))<BR> MyCommand.Parameters.Add(New OleDbParameter("@Vendor1N", OleDbType.VarChar, 100))<BR> MyCommand.Parameters.Add(New OleDbParameter("@Vendor1C", OleDbType.VarChar, 100))<BR> MyCommand.Parameters.Add(New OleDbParameter("@Vendor2N", OleDbType.VarChar, 100))<BR> MyCommand.Parameters.Add(New OleDbParameter("@Vendor2C", OleDbType.VarChar, 100))<BR> MyCommand.Parameters.Add(New OleDbParameter("@Vendor3N", OleDbType.VarChar, 100))<BR> MyCommand.Parameters.Add(New OleDbParameter("@vendor3C", OleDbType.VarChar, 100))<BR> MyCommand.Parameters.Add(New OleDbParameter("@vendor4N", OleDbType.VarChar, 100))<BR> MyCommand.Parameters.Add(New OleDbParameter("@vendor4C", OleDbType.VarChar,100))<BR> MyCommand.Parameters.Add(New OleDbParameter("@Revenue", OleDbType.VarChar,100))<BR><BR> MyCommand.Parameters("@OrderNum").Value = http://aspmessageboard.com/archive/index.php/MyDataGrid.DataKeys(CInt(E.Item.ItemIndex))<BR><BR> Dim Cols As String() = {"Vendor1C","Vendor2C","Vendor3C","Vendor4C","Revenue"}<BR><BR> Dim I As Integer<BR> For I = 0 To 4<BR><BR> Dim CurrentTextBox As TextBox<BR> CurrentTextBox = E.Item.FindControl("edit_" & Cols(I))<BR> Dim ColValue As String = CurrentTextBox.Text<BR><BR> ' Check for null values in required fields<BR> ' If I<3 And ColValue = ""<BR><BR> ' Message.InnerHtml = "ERROR: Null values not allowed for Name or Vendor2N"<BR> ' Message.Style("color") = "red"<BR> ' Return<BR> ' End If<BR><BR> MyCommand.Parameters("@" & Cols(I)).Value = Server.HtmlEncode(ColValue)<BR> Next<BR><BR> <BR> Dim vendor1NDropDownList As DropDownList<BR> vendor1NDropDownList = E.Item.FindControl("edit_vendor1N")<BR> MyCommand.Parameters("@vendor1N").Value = vendor1NDropDownList.SelectedItem.ToString()<BR><BR> Dim vendor2NDropDownList As DropDownList<BR> vendor2NDropDownList = E.Item.FindControl("edit_vendor2N")<BR> MyCommand.Parameters("@vendor2N").Value = vendor2NDropDownList.SelectedItem.ToString()<BR><BR> Dim vendor3NDropDownList As DropDownList<BR> vendor3NDropDownList = E.Item.FindControl("edit_vendor3N")<BR> MyCommand.Parameters("@vendor3N").Value = vendor3NDropDownList.SelectedItem.ToString()<BR><BR> Dim vendor4NDropDownList As DropDownList<BR> vendor4NDropDownList = E.Item.FindControl("edit_vendor4N")<BR> MyCommand.Parameters("@vendor4N").Value = vendor4NDropDownList.SelectedItem.ToString()<BR><BR> <BR><BR> MyCommand.Connection.Open()<BR><BR> Try<BR> MyCommand.ExecuteNonQuery()<BR> Message.InnerHtml = "<b>Record Updated</b>"' & UpdateCmd<BR> MyDataGrid.EditItemIndex = -1<BR> Catch Exp As OledbException<BR> ' If Exp.Number = 2627<BR> Message.InnerHtml = "ERROR: A record already exists with the same primary key"<BR> ' Else<BR> Message.InnerHtml = "ERROR: Could not update record, please ensure the fields are correctly filled out"<BR> ' End If<BR> Message.Style("color") = "red"<BR> End Try<BR><BR> MyCommand.Connection.Close()<BR><BR> BindGrid()<BR> End Sub<BR> <BR> Sub MyDataGrid_ItemDataBound(Sender As Object, E As DataGridItemEventArgs)<BR> If (e.Item.ItemType = ListItemType.EditItem) Then<BR> Dim i As Integer<BR> For i = 0 To e.Item.Controls.Count-1<BR> Try<BR> If (e.Item.Controls(i).Controls(1).GetType().ToString () = "System.Web.UI.WebControls.TextBox") Then<BR> Dim tb As TextBox<BR> tb = e.Item.Controls(i).Controls(1)<BR> tb.Text = Server.HtmlDecode(tb.Text)<BR> End If<BR> Catch<BR> <BR> End Try<BR> Next<BR> End If<BR> End Sub<BR> <BR> Sub BindGrid()<BR><BR> Dim DS As DataSet<BR> Dim MyCommand As OleDbDataAdapter<BR> MyCommand = new OleDbDataAdapter("select ordernum, vendor1N, Vendor1C, Vendor2N, Vendor2C, Vendor3N, Vendor3C, Vendor4N, Vendor4C, Revenue from tblOrdersProcessed WHERE OrderNum = " & OrderID.text, MyConnection)<BR><BR> DS = new DataSet()<BR> MyCommand.Fill(DS, "tblOrdersProcessed")<BR> MyDataGrid.DataSource=DS.Tables("tblOrdersProcessed").DefaultView<BR> MyDataGrid.DataBind()<BR> <BR> <BR> End Sub<BR><BR></script><BR><BR><body style="font: 10pt verdana"><BR><BR> <form runat="server"><BR><BR> <BR><BR> <span id="Message" EnableViewvendor3C="false" style="font: arial 11pt;" runat="server"/><p><BR><BR> <ASP
ataGrid id="MyDataGrid" runat="server"<BR> Width="800"<BR> BackColor="#ccccff"<BR> BorderColor="black"<BR> ShowFooter="false"<BR> CellPadding=3<BR> CellSpacing="0"<BR> Font-Name="Verdana"<BR> Font-Size="8pt"<BR> HeaderStyle-BackColor="#aaaadd"<BR> OnEditCommand="MyDataGrid_Edit"<BR> OnCancelCommand="MyDataGrid_Cancel"<BR> OnUpdateCommand="MyDataGrid_Update"<BR> DataKeyField="OrderNum"<BR> AutoGenerateColumns="false"<BR> OnItemDataBound="MyDataGrid_ItemDataBound"<BR> ><BR><BR> <Columns><BR> <asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Add Vendor" ItemStyle-Wrap="false" ButtonType="PushButton"/><BR> <asp:BoundColumn HeaderText="OrderNum" SortExpression="OrderNum" ReadOnly="True" DataField="OrderNum" ItemStyle-Wrap="false"/><BR> <asp:TemplateColumn HeaderText="Revenue" SortExpression="Revenue"><BR> <ItemTemplate><BR> <asp:Label runat="server" Text='<%# DataBinder.Eval (Container.DataItem, "Revenue", "{0:c}") %>'/><BR> </ItemTemplate><BR> <EditItemTemplate><BR> <asp:TextBox runat="server" id="edit_Revenue" Text='<%# DataBinder.Eval(Container.DataItem, "Revenue") %>'/><BR> </EditItemTemplate><BR> </asp:TemplateColumn><BR> <asp:TemplateColumn HeaderText="vendor1N" SortExpression="vendor1N"><BR> <ItemTemplate><BR> <asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "vendor1N") %>'/><BR> </ItemTemplate><BR> <EditItemTemplate><BR> <asp
ropDownList runat="server" SelectedIndex='<%# Getvendor3CIndex(Container.DataItem("vendor1N")) %>' id="edit_vendor1N"><BR><asp:ListItem>Select Vendor</asp:ListItem><BR><asp:ListItem>Coast Index</asp:ListItem><BR><asp:ListItem>Custom Tabs</asp:ListItem><BR><asp:ListItem>GE Polymershapes</asp:ListItem><BR><asp:ListItem>Image Star</asp:ListItem><BR><asp:ListItem>Ingram Micro</asp:ListItem><BR><asp:ListItem>Kleer Fax</asp:ListItem><BR><asp:ListItem>Marks Papter</asp:ListItem><BR><asp:ListItem>National Index</asp:ListItem><BR><asp:ListItem>Original</asp:ListItem><BR><asp:ListItem>Pengad</asp:ListItem><BR><asp:ListItem>Shamrock</asp:ListItem><BR><asp:ListItem>Southwest</asp:ListItem><BR><asp:ListItem>Spiral</asp:ListItem><BR><asp:ListItem>TEI</asp:ListItem><BR><asp:ListItem>Unibind</asp:ListItem><BR><asp:ListItem>United Manual</asp:ListItem><BR><asp:ListItem>United Transmittal</asp:ListItem><BR> </asp
ropDownList><BR> </EditItemTemplate><BR> </asp:TemplateColumn><BR> <BR> <asp:TemplateColumn HeaderText="Vendor1C" SortExpression="Vendor1C"><BR> <ItemTemplate><BR> <asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Vendor1C", "{0:c}") %>'/><BR> </ItemTemplate><BR> <EditItemTemplate><BR> <asp:TextBox runat="server" id="edit_Vendor1C" Text='<%# DataBinder.Eval(Container.DataItem, "Vendor1C") %>'/><BR> </EditItemTemplate><BR> </asp:TemplateColumn><BR> <BR> <asp:TemplateColumn HeaderText="vendor2N" SortExpression="vendor2N"><BR> <ItemTemplate><BR> <asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "vendor2N", "{0:c}") %>'/><BR> </ItemTemplate><BR> <EditItemTemplate><BR> <asp
ropDownList runat="server" SelectedIndex='<%# Getvendor3CIndex(Container.DataItem("vendor2N")) %>' id="edit_vendor2N"><BR> <asp:ListItem>Select Vendor</asp:ListItem><BR><asp:ListItem>Coast Index</asp:ListItem><BR><asp:ListItem>Custom Tabs</asp:ListItem><BR><asp:ListItem>GE Polymershapes</asp:ListItem><BR><asp:ListItem>Image Star</asp:ListItem><BR><asp:ListItem>Ingram Micro</asp:ListItem><BR><asp:ListItem>Kleer Fax</asp:ListItem><BR><asp:ListItem>Marks Papter</asp:ListItem><BR><asp:ListItem>National Index</asp:ListItem><BR><asp:ListItem>Original</asp:ListItem><BR><asp:ListItem>Pengad</asp:ListItem><BR><asp:ListItem>Shamrock</asp:ListItem><BR><asp:ListItem>Southwest</asp:ListItem><BR><asp:ListItem>Spiral</asp:ListItem><BR><asp:ListItem>TEI</asp:ListItem><BR><asp:ListItem>Unibind</asp:ListItem><BR><asp:ListItem>United Manual</asp:ListItem><BR><asp:ListItem>United Transmittal</asp:ListItem><BR> </asp
ropDownList><BR> </EditItemTemplate><BR> </asp:TemplateColumn><BR> <BR> <asp:TemplateColumn HeaderText="Vendor2C" SortExpression="Vendor2C"><BR> <ItemTemplate><BR> <asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Vendor2C", "{0:c}") %>'/><BR> </ItemTemplate><BR> <EditItemTemplate><BR> <asp:TextBox runat="server" id="edit_Vendor2C" Text='<%# DataBinder.Eval(Container.DataItem, "Vendor2C") %>'/><BR> </EditItemTemplate><BR> </asp:TemplateColumn><BR> <asp:TemplateColumn HeaderText="vendor3N" SortExpression="vendor3N"><BR> <ItemTemplate><BR> <asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "vendor3N", "{0:c}") %>'/><BR> </ItemTemplate><BR> <EditItemTemplate><BR> <asp
ropDownList runat="server" SelectedIndex='<%# Getvendor3CIndex(Container.DataItem("vendor3N")) %>' id="edit_vendor3N"><BR> <asp:ListItem>Select Vendor</asp:ListItem><BR><asp:ListItem>Coast Index</asp:ListItem><BR><asp:ListItem>Custom Tabs</asp:ListItem><BR><asp:ListItem>GE Polymershapes</asp:ListItem><BR><asp:ListItem>Image Star</asp:ListItem><BR><asp:ListItem>Ingram Micro</asp:ListItem><BR><asp:ListItem>Kleer Fax</asp:ListItem><BR><asp:ListItem>Marks Papter</asp:ListItem><BR><asp:ListItem>National Index</asp:ListItem><BR><asp:ListItem>Original</asp:ListItem><BR><asp:ListItem>Pengad</asp:ListItem><BR><asp:ListItem>Shamrock</asp:ListItem><BR><asp:ListItem>Southwest</asp:ListItem><BR><asp:ListItem>Spiral</asp:ListItem><BR><asp:ListItem>TEI</asp:ListItem><BR><asp:ListItem>Unibind</asp:ListItem><BR><asp:ListItem>United Manual</asp:ListItem><BR><asp:ListItem>United Transmittal</asp:ListItem><BR> </asp
ropDownList><BR> </EditItemTemplate><BR> </asp:TemplateColumn><BR> <asp:TemplateColumn HeaderText="Vendor3C" SortExpression="Vendor3C"><BR> <ItemTemplate><BR> &#Lot of code and I'm bluring out.<BR><BR>I'll take a look in the morning to see if anything jumps out.<BR><BR>Good luck with it.<BR><BR>Tom TWhen you get the error "object not set.........", what line number is noted?<BR><BR>Its not giving me a line number. I am doing this in ultraedit and running it in ie 6.0.<BR><BR>However, i did find something helpful. If i put it in edit mode, then put in the MyDataGrid.EditItemIndex = 0 statement before bindgrid() i can refresh and it works fine. I can even click the cancel button and it stays in edit mode.<BR><BR>I just need to figure out why i get the error when i try to initialize the program on pageload.<BR><BR>Im doing more testing now.<BR><BR>Thanks for the help again!I figured out the promblem. Everything you said about setting the edit mode to 0 works fine. The problem was in my form load. I just moved my hash table above the <BR>"If not (ispostback)" <BR>where my bindgrid() statement was and it works fine. I think it will be obvious why this was causing the problem. <BR><BR>Thanks for all of your help! <BR><BR>In case anyone is following this code i am posting the corrected page load here: <BR>____________________________<BR><BR>Sub Page_Load(Src As Object, E As EventArgs)<BR> OrderID.text=Request.QueryString("OrderNUM")<BR><BR> <BR><BR> vendor3CIndex = New Hashtable()<BR> <BR>vendor3CIndex("Select Vendor") = 0<BR>vendor3CIndex("Coast Index") = 1<BR>vendor3CIndex("Custom Tabs") = 2<BR>vendor3CIndex("GE Polymershapes") = 3<BR>vendor3CIndex("Image Star") = 4<BR>vendor3CIndex("Ingram Micro") = 5<BR>vendor3CIndex("Kleer Fax") = 6<BR>vendor3CIndex("Marks Papter") = 7<BR>vendor3CIndex("National Index") = 8<BR>vendor3CIndex("Original") = 9<BR>vendor3CIndex("Pengad") = 10<BR>vendor3CIndex("Shamrock") = 11<BR>vendor3CIndex("Southwest") = 12<BR>vendor3CIndex("Spiral") = 13<BR>vendor3CIndex("TEI") = 14<BR>vendor3CIndex("Unibind") = 15<BR>vendor3CIndex("United Manual") = 16<BR>vendor3CIndex("United Transmittal") = 17<BR> <BR> If Not (IsPostBack)<BR> <BR> BindGrid()<BR> End If<BR> <BR> End SubI use a text editor for most coding as well. I have VS.net but can't get away from a basic editor for asp work.<BR><BR>If you add Debug="true" to the top of your page:<BR><BR><%@ Page Language="VB" Debug="True" %><BR><BR>you will get a lot more information when an error pops. This<BR>works with any editor.<BR><BR>Tom T







