Problem taking value from details view

GingJonesy

Member
Joined
Nov 30, 2011
Messages
6
Programming Experience
Beginner
Hello, im currently trying to take the text from a details view and pass it to a label. Im getting the error message that it cannot be converted to string. I have tried both pieces of code below:

Dim ModCode As String = LblSelectedModCode.Text
LblSelectedModCode.Text = DtlVwProgrammeInfo.Rows[0].Cells[1].Text

Anyone any ideas how i could pass the value of the first row and cell 2 of my details view into a label??
 
Can you give a little more info on what you are trying to do? For now I will guess...

If it were me, and I am not saying its best practice, because frankly I'm unsure...

If the label was somewhere away from the details view on the page, I would be tempted to convert the field to template on details view, change the field to a label so you can give it a specific id. then use find control...

sooo....

on the details view item template, you have a label called lblCellTwoData
then at some stage in code AFTER to details view is databound you could just

VB.NET:
dim lbltmp as label = Ctype(dvDetailView.findcontrol("lblCellTwoData"), Label)
lblMyLabelSomewhereOnPage.text = lbltmp.text
As I am assigning data to it, I would also use a property to encapsulate the label.
 
I'll give you exactly what im trying to do. I have a details view called DtlVwProgrammeInfo that is generated from a database table called Pathway_Module, with all the information on a module and below it i have a gridview called GrdVwTimetable with the timetable for that module. HOWEVER i need to take the module code that is in the first row, cell 2 and use it as a parameter for the gridview.

Sooo if the details view has CSC3001 then i need the gridview to be populated with CSC3001's timetable and if the user clicks the next page with CSC3002 then the timetable will be populated with that. I was going to pass the text from that cell into a label called LblModCode and use the label as a parameter for the gridview. Thats why i was trying to do that.

Any ideas on what way to do it?
 
Ok, well in DtlVwProgrammeInfo, convert the field containing the ID Code to a template field. In source view you can do away with any additional templates showing for that field and just keep the ItemTemplate. In the Item template use a label to show the data column from the pathway_module database. In the text property for your label you can have

VB.NET:
'<%# currentID(Eval("ID")) %>'

This assumes the column name from your database is ID, change accordingly.

In code behind create a new function and a variable outwith the class methods

VB.NET:
Private _id as string

Public Property pRef as string
get
return _id
end get
set
_id = value
end set
end Property

Public Function currentID(ByVal id as String) as String
pRef = id
return id
End Function

You can then use pRef property as parameter for the gridview datasource.
I have no idea how this conforms to best practice, just thinking out loud without VS being open, so also untested.
 
Back
Top