4

Need to retrieve an index of a row in LINQ, then use that value to specify my DropDownList.SelectedIndex upon page load or postback.

    public String GetRoleName(Int16 RoleID)
    {
        SQL_TA_SCOREBOARDEntities1 c = new SQL_TA_SCOREBOARDEntities1();

        String qry = (from b in c.EmployeeAccessLevels
                      where b.id == RoleID
                      select b.Role).FirstOrDefault();

        return qry;
    }

I take the name of the Role for the dropdownlist to display but it doesn't work anyway.

            String RoleName = MyClass.RoleName(RoleID);
            ddlRole.Text = RoleName

So I really need the index instead.

Thanks in advance!

4
  • 1
    I think you're doing it wrong. Use ddl.SelectedItem to set selected item, not the index. Commented Apr 3, 2014 at 1:41
  • I tried, doesn't work. :( Commented Apr 3, 2014 at 1:50
  • Use ddlRole.SelectedValue = RoleID instead Commented Apr 3, 2014 at 2:04
  • My id's are 1,2,5 and 6 so I can't do that. :( Commented Apr 3, 2014 at 2:37

1 Answer 1

2

I don't think retrieving a row's index is directly possible in LINQ.

You could just try

    ddlRole.Items[0].Text = RoleName
Sign up to request clarification or add additional context in comments.

2 Comments

sorry for bothering on such a simple question :(
It's ok we all start somewhere. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.