Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binding a datagrid

Status
Not open for further replies.

syno

Technical User
Joined
Mar 5, 2007
Messages
10
Location
GB
Hi Guys

I have an editable datagrid with Edit, Update and Cancel controls shown as links within my datagrid. However when I click on the Edit, Update and Cancel links within my rendered table the table disappears. I know these link controls work because I have a push button that gets a dataset to bind to the datagrid and then databinds the datagrid to the data source. If I click on the push button (which effectively does a free text search) the table does appear. However when I press the Edit, Update and Cancel links the table disappears. The code I am using for the Edit option is as follows. Is there anything else I should be doing to bind the datagrid on selecting Edit:


Public Sub DataGrid_Edit(ByVal Source As Object, ByVal E As DataGridCommandEventArgs)
dgSearch.EditItemIndex = E.Item.ItemIndex
DataBind()
End Sub

Thank you



 
What does [tt]databind()[/tt] do? I guessing it gets your data and binds to the grid. You refer to your grid as a DataGrid not GridView... I assume your using .Net 1.1 and not 2.0. Is this correct?

Is viewstate enabled for the grid? If so, you should not need to bind the grid when changing the edit item index. Just change the EditItemIndex like you do and your done. Don't call [tt]DataBind()[/tt]

if you don't have viewstate enabled call [tt]DataBind()[/tt] first and then change the EditItemIndex.
Code:
Public Sub DataGrid_Edit(ByVal Source As Object, ByVal E As DataGridCommandEventArgs)
        DataBind()
        dgSearch.EditItemIndex = E.Item.ItemIndex
End Sub

If this still doesn't work there may be a problem within the method [tt]DataBind[/tt].

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Are you databinding the DataGrid in your Page_Load method.

If so, is it wrapped in a PostBack block

K
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top