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!

有帮助吗?

解决方案

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

You could just try

    ddlRole.Items[0].Text = RoleName
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top