Autogeneratecolumns = true, and I want to edit

  • Thread starter Thread starter Andy Sutorius
  • Start date Start date
A

Andy Sutorius

Can someone point me to an article on how to edit a datagrid when the grid
is set to autogeneratecolumns?

Each article I have come across has instructions when autogenerate is false
and you have an item template with data containers.

Thanks

Andy
 
Not unless you dynamically (in the code behind) add the Item Templates
to your DataGird.

Regards

Trevor Benedict R
MCSD

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Here is an example:
In your aspx page declare Datagrid as follows:
<asp:DataGrid id="Datagrid2" runat="server" CssClass="grid"
AutoGenerateColumns="True"><Columns>
<asp:EditCommandColumn EditText="Edit" CancelText="Cancel"
UpdateText="Update" /></Columns>
</asp:DataGrid>

In code behind, you need to Bind your data source to the datagrid and on
Edit ItemCommand you can say
Private Sub Datagrid2_EditCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
Datagrid2.EditCommand
Datagrid2.EditItemIndex = e.Item.ItemIndex
BindGrid()
End Sub

Again on Datagrids Update command you can read the values of the columns and
then save it into the DB

Hope this helps

Thanks,
Sandeep
 
Back
Top