我有一个列表框,其中显示了多个选定的学生,并分配给了各个父母。现在我只想基于数据表行[“ ID”]获得选定的列表项。
这是我的代码:
DataTable dts = new DataTable();
dts = objsu.Get_StudentParent_By_ID(ID);
for(int i = 0;i <= ddl_student.Items.Count;i++)
{
ListItem item = ddl_student.Items[i];
if (dts.Rows[i]["ID"].ToString() == item.Value.ToString())
{
item.Selected = true;
}
}
这是我的列表框查询:
ALTER PROCEDURE [dbo].[GetStudentsByParentID]
@ID int = 0
AS
BEGIN
SET NOCOUNT ON;
select s.PK_PID as ID,s.StudentName+' class [ '+(select Classname from classes c where c.PK_PID = s.Class) +
' ] section ( '+(select SectionName from sections se where se.PK_PID = s.Section)+
' ) Roll ('+s.RollNo+')' as Value
from [dbo].[students] s
left join parentstudentassign ps on ps.StudentID = s.PK_PID
left join parents p on p.PK_PID = ps.ParentID
where 1 = 1
and p.PK_PID = @ID
END
在某些行之后,在第7个位置上没有行给我错误。