Datagrid in edit mode
-
hello, i've been looking for ways to set a specific column to display an text box for edit mode. by default when in edit mode all columns in a row will show a text box to edit the data. i only want a specific row, not all of them to have the text box show up. how do i isolate the one column and then be able to find which record is being edited when i click the update link? thanks, Orion Orion orion.buttigieg@Teamplate.com www.Teamplate.com
-
hello, i've been looking for ways to set a specific column to display an text box for edit mode. by default when in edit mode all columns in a row will show a text box to edit the data. i only want a specific row, not all of them to have the text box show up. how do i isolate the one column and then be able to find which record is being edited when i click the update link? thanks, Orion Orion orion.buttigieg@Teamplate.com www.Teamplate.com
Hi Orion, If I'm understanding your question correctly, what you can do is set the ReadOnly property to True for columns that you don't want to be editable in edit mode. Datagrid Girl
-
Hi Orion, If I'm understanding your question correctly, what you can do is set the ReadOnly property to True for columns that you don't want to be editable in edit mode. Datagrid Girl
thanks, i'll give that a shot. figures it could be something so simple.. Orion Orion orion.buttigieg@Teamplate.com www.Teamplate.com
-
Hi Orion, If I'm understanding your question correctly, what you can do is set the ReadOnly property to True for columns that you don't want to be editable in edit mode. Datagrid Girl
Its also controlled by the edit template you have defined. If you always want the column to be non-editable then don't define a template.
-
thanks, i'll give that a shot. figures it could be something so simple.. Orion Orion orion.buttigieg@Teamplate.com www.Teamplate.com
alright excellent...! that works. i should have gotten that one. something i've noticed. as i page over, it keeps putting the row i've selected to edit in edit mode. so basically if the user pages over i don't want that row to stay in edit mode as its a completely new record. is there a way to stop this? i'm new at this asp.net datagrid stuff. thanks, Orion Orion orion.buttigieg@Teamplate.com www.Teamplate.com
-
alright excellent...! that works. i should have gotten that one. something i've noticed. as i page over, it keeps putting the row i've selected to edit in edit mode. so basically if the user pages over i don't want that row to stay in edit mode as its a completely new record. is there a way to stop this? i'm new at this asp.net datagrid stuff. thanks, Orion Orion orion.buttigieg@Teamplate.com www.Teamplate.com
In your page index changed event, set the grid's EditItemIndex property to -1. Datagrid Girl Day Job, CP!: http://www.codeproject.com Datagrid Stuff: http://www.datagridgirl.com
-
In your page index changed event, set the grid's EditItemIndex property to -1. Datagrid Girl Day Job, CP!: http://www.codeproject.com Datagrid Stuff: http://www.datagridgirl.com
cool, that works. thanks for the tip! and good site. i think i'll be frequenting there while i build this thing.. :) Orion Orion orion.buttigieg@Teamplate.com www.Teamplate.com
-
In your page index changed event, set the grid's EditItemIndex property to -1. Datagrid Girl Day Job, CP!: http://www.codeproject.com Datagrid Stuff: http://www.datagridgirl.com
i must be missing something obvious in regards to Updating. i found some code that gets the 'key' value but when i use the same code in the Update event method. string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString(); running this line throws an 'Index out of range' exception. i've seen examples to FindControl which would accordingly find the text box being used and then extract the string from it at that point. however, if i look at my html side there's no such control defined. so do i just add one straight into the html manually or something like that? thanks, Orion Orion orion.buttigieg@Teamplate.com www.Teamplate.com
-
i must be missing something obvious in regards to Updating. i found some code that gets the 'key' value but when i use the same code in the Update event method. string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString(); running this line throws an 'Index out of range' exception. i've seen examples to FindControl which would accordingly find the text box being used and then extract the string from it at that point. however, if i look at my html side there's no such control defined. so do i just add one straight into the html manually or something like that? thanks, Orion Orion orion.buttigieg@Teamplate.com www.Teamplate.com
Hi Orion, You need to set the DataKeyField property in your declaration to the name of your ID field from your database. Datagrid Girl Day Job, CP!: http://www.codeproject.com Datagrid Stuff: http://www.datagridgirl.com
-
Hi Orion, You need to set the DataKeyField property in your declaration to the name of your ID field from your database. Datagrid Girl Day Job, CP!: http://www.codeproject.com Datagrid Stuff: http://www.datagridgirl.com
hello Marcie, thanks for all your help today..! ok, maybe i'm going about this all wrong, as i fix one thing only to be not able to do something else. i implemented your suggestion and it worked. i set the DataKeyField with the field name from the table the data is coming from and that worked. it probably wasn't set since i just make a data connection, make a SQL query and populate the grid. now it doesn't like the next line of code which is supposed to pull the data from the cell\Textbox that's being edited. but i get 'arguement out of range'. so i think it can't find the text box. string newResValue; TextBox textBox; textBox = (TextBox)(e.Item.Cells[3].Controls[0]); maybe i should give a little background here as perhaps i'm doing this all wrong. i'm creating all the columns programatically except for the Edit column (property builder for that). they are all BoundColumns. as stated before i make a SQL query and get a dataset from a Data tier i have here and populate the columns with the BoundColumn.DataField property. i'm doing this all manually as that's the advice articles i've read give, plus i need the ability to control the width of the columns. see below for how i'm doing this.
string strSQL = "SELECT RESOURCES.ResName,RESOURCES.ResValue,RESOURCES.ResComment FROM RESOURCES INNER JOIN PROJECTID ON RESOURCES.ProjectIdentifier = PROJECTID.ProjectIdentifier "+ "WHERE (PROJECTID.ProjectName = '"+strProjectName+"')"+ "ORDER BY RESOURCES.DateCreated"; dataSet = dataAccess.GetDataSet(strSQL,conn); DataTable dt = dataSet.Tables[0]; //populate datagrid this.DataGrid1.AutoGenerateColumns = false; System.Web.UI.WebControls.BoundColumn column1 = new BoundColumn(); column1.HeaderText = "Resource Name"; column1.DataField = "ResName"; column1.Visible= true; column1.ReadOnly = true; this.DataGrid1.Columns.Add(column1);
i just repeat the code to create the other columns leaving the last column to be edited. however, doing it this way doesn't seem to allow me to create TemplateColumns and pass them data like i do with the BoundColumns as there's no DataField property. so i seem to be caught somewhere in the middle ground of doing things programmatically and letting VS do it by setting some properties..:( your thoughts are greatly welcomed. thanks, Orion ps. if you've gone home already, have a good weekend and happy valentines.. Orion orion.buttigieg@Teamplate.com www.Teamplate.com