DataGrid the Right Choice for this???

Results 1 to 3 of 3

Thread: DataGrid the Right Choice for this???

  1. #1
    Join Date
    Dec 1969

    Default DataGrid the Right Choice for this???

    I&#039;ve got a database table of employees and want the user to be able to edit the data for an employee. I don&#039;t want them to edit the employee data in a data grid because there&#039;s more columns than I care to display. I really just want to add an "Edit" hyperlink or button on each row so that the user can click the button on each that submits the form with the associated employeeID and hopefully carry forward a couple of hidden form fields that are in the form. The "Extensive Examination of a DataGrid Web Control" part 3 ( seems to be in the ballpark of what I need, but it stops short of identifying the row that was clicked in such a way that I would know an employeeID. I&#039;ve putzed around and managed to get the selectedIndex, but that just gives me the datagrid row, nothing about the associated employee ID.<BR><BR>I managed to put an edit link to pass the URL parameter, but that doesn&#039;t give me my hidden form fields. I was hoping for a button that would SUBMIT the form, identifying the dataGrid selectedItem where I could pull employeeID from one of the columns.<BR><BR>Should I be using something other than a data grid to make this easier? If this is an appropriate use of the data grid, can somebody please direct me to documentation or a discussion that addresses putting a button on each line to that will submit the form passing the selected item similar to a drop down list?

  2. #2
    Join Date
    Dec 1969

    Default Sure it can be

    I&#039;ve done it like this in the past without a problem, simply have a hidden column with the ID stored and then on button click show the edit details (as outlined in the article).<BR><BR>Does that help?<BR><BR>Tim

  3. #3
    Join Date
    Dec 1969

    Default RE: Sure it can be

    You&#039;ve got a couple of options - <BR><BR>You can assign the EmployeeID to the DataKeyField of the datagrid - you can then retrieve from a command button click event:<BR><BR>Dim IntEmployeeId as Integer = YourDataGrid.DataKeys(e.item.ItemIndex) &#039; Gives you the EmployeeID<BR><BR>This option posts back to itself so probably doesn&#039;t suit your needs - <BR><BR>The other option is to use a HyperLinkColumn in your DataGrid:<BR><BR>&#060;asp:HyperLinkColumn<BR>Data NavigateUrlField="EmployeeID"<BR>DataNavigateUrlFo rmatString="employeedetails.aspx?id={0}"<BR>Text=" details"/&#062;<BR><BR>This creates a link with an employeeID QueryString<BR>- It doesn&#039;t pass any form fields but personally I would just look up the details using the ID Field<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts