查詢兩個表是有有關的DataSourceID和DataSource
EmpInf
EmpId,
EmpName,
Salary,
DepartNumber.
Dept
DeptNo,
Deptname,
我有一個作爲
<asp:LinqDataSource ID="LinqDataSource1" runat="server" EntityTypeName=""
ContextTypeName="FilterControl.DataClasses1DataContext" EnableDelete="True"
EnableInsert="True" EnableUpdate="True" OrderBy="DeptName"
TableName="Dept1s" Select="new (DeptNo, DeptName)">
</asp:LinqDataSource>
一個listview
<asp:ListView ID="ListView1" runat="server" DataSourceID="LinqDataSource1"
style="z-index: 1; left: 10px; top: 34px; position: absolute; height: 63px; width: 293px"
>
<AlternatingItemTemplate>
<tr style="">
<td>
<asp:DynamicControl runat="server" DataField="DeptNo" Mode="ReadOnly" />
</td>
<td>
<asp:DynamicControl runat="server" DataField="DeptName" Mode="ReadOnly" />
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr style="">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update"
Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Cancel" />
</td>
<td>
<asp:DynamicControl runat="server" DataField="DeptNo" Mode="Edit" />
</td>
<td>
<asp:DynamicControl runat="server" DataField="DeptName" Mode="Edit" />
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server" style="">
<tr>
<td>
No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert"
ValidationGroup="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Clear" />
</td>
<td>
<asp:DynamicControl runat="server" DataField="DeptNo" Mode="Insert"
ValidationGroup="Insert" />
</td>
<td>
<asp:DynamicControl runat="server" DataField="DeptName" Mode="Insert"
ValidationGroup="Insert" />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="">
<td>
<asp:DynamicControl runat="server" DataField="DeptNo" Mode="ReadOnly" />
</td>
<td>
<asp:DynamicControl runat="server" DataField="DeptName" Mode="ReadOnly" />
</td>
</tr>
</ItemTemplate>
linqdatasource control
等,並試圖實現這個listview
thorugh動態數據並使用了dynamic data manager control
<asp:DynamicDataManager ID="DynamicDataManager1" runat="server" >
<DataControls>
<asp:DataControlReference ControlID="ListView1" />
</DataControls>
</asp:DynamicDataManager>
我已經採取了dropdownlist
,勢必EmpInf.Empname
,當我從下拉列表中選擇partcular員工姓名我要綁定的部門名稱。
在運行期間,後端
FilterControl.DataClasses1DataContext obj = new DataClasses1DataContext();
protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
{
var a = from r in obj.EmpInfs
join s in obj.Dept1s on r.DeptNumber equals s.DeptNo
where r.EmpName == DropDownList1.SelectedValue
select s.DeptName;
ListView1.DataSource = a;
ListView1.DataBind();
}
,它拋出一個異常,這說明要麼使用DataSourceID="LinqDataSource1" or use the datasource a the back end. remove one of them.
,而這樣做的過程中什麼都不會返回。我該如何讓這個運行,需要建議。感謝您的幫助。以解決
寫入
listview.DatasourceId=null
解決。請告訴我。 –