我的網格視圖的數據源來自存儲過程通過使用linqdatasource。這個linqdatasource的參數是文本框(txtSearchKeywords),當我按下搜索按鈕時,gridview根據下面的代碼獲取數據。 現在我喜歡更新或刪除一些gridview的行,所以我已經添加命令字段(編輯/刪除)到gridview並啓用編輯/刪除linqdatasource但我不能更新行,實際上我甚至不能在行中輸入。沒有任何活動,只顯示編輯/更新/取消按鈕。 請幫我怎麼解決?Gridview更新
存儲過程:
ALTER PROCEDURE [dbo].[spQuickSearchDoc]
@Searchtext varchar(50)=null
AS
select DocId,DocumentNo,Title,Unit
from tblDocuments
where DocumentNo like '%'[email protected] + '%'
or Title like '%'[email protected] + '%'
or Unit like '%'[email protected] + '%'
的LinqDataSource:
<asp:LinqDataSource ID="LinqDataSource2" runat="server"
ContextTypeName="EDMSDataContext" OnSelecting="LinqDataSource2_Selecting"
EnableDelete="True" EnableUpdate="True" TableName="tblDocuments" EnableInsert="True"
>
<WhereParameters>
<asp:ControlParameter Name="Subject"
ControlID="txtSearchKeywords"
PropertyName="Text"
Type="String" />
</WhereParameters>
</asp:LinqDataSource>
的GridView:
<asp:GridView ID="GridViewDocuments_Search" runat="server" AutoGenerateColumns=False
Visible="False" onrowcommand="GridViewDocuments_Search_RowCommand" DataKeyNames="DocId"
PageSize="100" DataSourceID="LinqDataSource2" >
<Columns>
<asp:BoundField DataField="DocumentNo" HeaderText="DocumentNo"
SortExpression="DocumentNo" ReadOnly="True" />
<asp:BoundField DataField="TITLE" HeaderText="TITLE" ReadOnly="True"
SortExpression="TITLE" />
<asp:BoundField DataField="Unit" HeaderText="Unit" SortExpression="Unit"
ReadOnly="True" />
<asp:BoundField DataField="DocId" HeaderText="DocId" ReadOnly="True"
SortExpression="DocId" />
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
代碼:
public void LinqDataSource2_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
_DataContext = new EDMSDataContext();
var subjectFilter = e.WhereParameters["Subject"];
var query = _DataContext.spQuickSearchDoc(subjectFilter.ToString());
e.Result = query;
}
protected void btnSearch_Click(object sender, EventArgs e)
{
_DataContext = new EDMSDataContext();
this.LinqDataSource2.WhereParameters["Subject"].DefaultValue = this.txtSearchKeywords.Text;
GridViewDocuments.Visible = false;
GridViewDocuments_Search.Visible = true;
this.GridViewDocuments_Search.DataBind();
}