c# repeater: I get one value from an indexed control in code behind but can't get others... why?

40 Views Asked by At

I'm using a repeater with a DbDataReader which displays all data correctly in the .aspx. I want to access specific columns and rows int the repeater in the code behind. I can get only one but not the others and I can't figure out why. Here is a shortened sql statement that I'm using:

sql = "select distinct question_explain_int as competency_int,dbo.CodeDescription('competency', question_explain_int, 0) as competency";
sql += " from test_content tc left join test_question tq on tc.question_int = tq.question_int where dbo.CodeDescription('competency', question_explain_int, 0) <> ''";
   DbDataReader rs = CADEdata.ReadData(cnxn, sql);
   competencyRepeater.DataSource = rs;
   competencyRepeater.DataBind();

So, I can get competency with:

((Label)competencyRepeater.Items[0].FindControl("competency")).Text    
((Label)competencyRepeater.Items[1].FindControl("competency")).Text

But the following returns null!

((Label)competencyRepeater.Items[0].FindControl("competency_int")).Text    
((Label)competencyRepeater.Items[1].FindControl("competency_int")).Text

Actually, I have a lot more columns and they all return null except the one. What's going on and how can I get the other values?

EDIT #1: I thought I found the solution, competency_int is a hidden field in the .aspx so I switched to the following format but it is still null:

<input type="hidden" name="competency_int" id="competency_int<%#Container.ItemIndex%>" value="<%# Eval("competency_int") %>" />

...

   ((HiddenField)competencyRepeater.Items[1].FindControl("competency_int")).Value
0

There are 0 best solutions below