GRCHELPDESK
asked on
Retrieving values from DetailsView Control with template fields
Hello Experts,
I'm new to the details view control. I've created one, and and it's pulling data perfectly. I then created an "accept" button. When the user clicks it, take the first 2 fields of the DetailsView control and populate text boxes with them like this:
txtCompanyName.Text = dvCompany.Rows(0).Cells(1) .Text
txtCompanyID.Text = dvCompany.Rows(1).Cells(1) .Text
This was working like a charm. Them I turned those first 2 fields into Template Fields so I could validate them. Ever since then, the above lines pull a blank string. It's almost like, the above just doesn't apply to template fields. Or something. Does anyone know how I can get this working?
Thanks,
GRCHELPDESK
I'm new to the details view control. I've created one, and and it's pulling data perfectly. I then created an "accept" button. When the user clicks it, take the first 2 fields of the DetailsView control and populate text boxes with them like this:
txtCompanyName.Text = dvCompany.Rows(0).Cells(1)
txtCompanyID.Text = dvCompany.Rows(1).Cells(1)
This was working like a charm. Them I turned those first 2 fields into Template Fields so I could validate them. Ever since then, the above lines pull a blank string. It's almost like, the above just doesn't apply to template fields. Or something. Does anyone know how I can get this working?
Thanks,
GRCHELPDESK
ASKER
Hey RedKelvin,
Thanks for the reply. Although, I'm not following entirely. I'm not sure what you mean about "inside the grid event". Can you clarify that for me? And also, will it be possible to have this happen in the button click event?
Thanks!
GRCHELPDESK
Thanks for the reply. Although, I'm not following entirely. I'm not sure what you mean about "inside the grid event". Can you clarify that for me? And also, will it be possible to have this happen in the button click event?
Thanks!
GRCHELPDESK
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hey RedKelvin,
Awesome, it's working. I had to modify it a slightly, so I'll post that code for anyone running into this. On button click:
Dim lblCompanyName As Label
Dim lblCompanyID As Label
For Each row As DetailsViewRow In dvCompany.Rows
lblCompanyName = CType(row.FindControl("lab el1"), Label)
lblCompanyID = CType(row.FindControl("lab el2"), Label)
txtCompanyName.Text = lblCompanyName.Text
txtCompanyID.Text = lblCompanyID.Text
Next
Many thanks for that!!
Cheers,
GRCHELPDESK
Awesome, it's working. I had to modify it a slightly, so I'll post that code for anyone running into this. On button click:
Dim lblCompanyName As Label
Dim lblCompanyID As Label
For Each row As DetailsViewRow In dvCompany.Rows
lblCompanyName = CType(row.FindControl("lab
lblCompanyID = CType(row.FindControl("lab
txtCompanyName.Text = lblCompanyName.Text
txtCompanyID.Text = lblCompanyID.Text
Next
Many thanks for that!!
Cheers,
GRCHELPDESK
You can do it like this
Dim lblId As Label = CType(e.Item.FindControl("
that is for a label control with an id of lblId.
This needs to be used inside a grid event, otherwise e will not be found