Question

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!

Was it helpful?

Solution

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

You could just try

    ddlRole.Items[0].Text = RoleName
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top