Data source of my grid view comes of stored procedure by using linqdatasource. The parameter of this linqdatasource is the textbox (txtSearchKeywords) ,when I press the search button the gridview takes the data according to below code.
Now I like to update or delete some rows of gridview, so I have added command field (edit/delete) to gridview and enabled edit/delete linqdatasource but I cannot update the row, actually I cannot even type in the row. Nothing is active , just shows edit/update/cancel buttons.
Please help how I can solve?
Stored procedure:
ALTER PROCEDURE [dbo].[spQuickSearchDoc]
@Searchtext varchar(50)=null
AS
select DocId,DocumentNo,Title,Unit
from tblDocuments
where DocumentNo like '%'+@SearchText + '%'
or Title like '%'+@SearchText + '%'
or Unit like '%'+@SearchText + '%'
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>
Code:
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();
}
Do you get an error when you click on the Edit link in the grid view row?
You can handle the following three events in order to enable the data in your grid to be updated:
1) RowEditing
2) RowUpdating
3) RowCancellingEdit
A simple google search with the event name + linq datasource in grdiview will bring up more than enough examples on how