GridView中Selectcommand的参数如何赋值 在repeater控件中加了<asp:label runat="Server" Text='<%# Eval("DeptName") %>'></asp>控件,然后又加了<asp:GridView ID="Gridview1" runat="server" AutoGenerateColumns="true" DataSourceID="Accessdatasource_member" OnRowDataBound="Gridview_onRowDataBound"> </asp:GridView>控件, 我在 SelectCommand="SELECT [DeptName],[LevelName],[RoleName] from ([tbDept] left join [tbLevel] on [tbDept.LevelID]=[tbLevel.LevelID]) left join [tbRole] on [tbDept.RoleID]=[tbRole.RoleID] where [DeptName]IN(SELECT [DeptName] from [tbDept] where [ParentID] in(SELECT [ID] from [tbDept] where [b][DeptName]= ?[/b]))">用了一个叫DeptName的参数
if(e.Row.RowType == DataControlRowType.DataRow) { xx.SelectCommand = "SELECT [DeptName],[LevelName],[RoleName] from ([tbDept] left join [tbLevel] on [tbDept.LevelID]=[tbLevel.LevelID]) left join [tbRole] on [tbDept.RoleID]=[tbRole.RoleID] where [DeptName]IN(SELECT [DeptName] from [tbDept] where [ParentID] in(SELECT [ID] from [tbDept] where [DeptName]= '" + DeptName + "'" ; }
或者
xx.SelectCommand = "SELECT [DeptName],[LevelName],[RoleName] from ([tbDept] left join [tbLevel] on [tbDept.LevelID]=[tbLevel.LevelID]) left join [tbRole] on [tbDept.RoleID]=[tbRole.RoleID] where [DeptName]IN(SELECT [DeptName] from [tbDept] where [ParentID] in(SELECT [ID] from [tbDept] where [DeptName]= @DeptName"; xx.Parameters.Clear(); xx.SelectParameters.Add("@DeptName",DeptName);