I am getting this weird error... the primary key in my database is \'DocumentID\' so I know that is not the issue. I am trying to get the select,edit & delete gridview b
Well, you haven't selected the documentid
column and hence it's not present in either datatable or dataview which you are binding to grid OR referencing that column through datatable.
Change your query to
SelectCommand="SELECT [DocumentID],[DocumentTitle], [DocumentBody] FROM [tblDocument]" />
It seems that your sqldatasource does not return the DocumentId column.
Maybe you should change the datasource definition to this:
<asp:SqlDataSource ID="sdsDocuments" runat="server" ConnectionString="<%$ ConnectionStrings:blcDocumentationConnectionString %>"
SelectCommand="SELECT [DocumentID], [DocumentTitle], [DocumentBody] FROM [tblDocument]" />
1- First step you have to select the Documentid column in SELECT statement
SelectCommand="SELECT [DocumentID], [DocumentTitle], [DocumentBody] FROM [tblDocument]" />
2- You have to include it in datagridview COLUMN as you did:
<asp:GridView ID="GridView1" runat="server" DataSourceID="sdsDocuments" EnableModelValidation="True"
SelectedIndex="0" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" DataKeyNames="DocumentID, DocumentTitle, DocumentBody">
<Columns>
<asp:BoundField DataField="DocumentID" HeaderText="DocumentID" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="DocumentTitle" HeaderText="DocumentTitle" SortExpression="Title" />
<asp:BoundField DataField="DocumentBody" HeaderText="DocumentBody" SortExpression="Body" />
<asp:CommandField ShowSelectButton="True" ShowDeleteButton="True" />
</Columns>
</asp:GridView>
3- If you are using Paging in datagridview AllowPaging="True" ,you have to SELECT also documentid on the event OnSelectedIndexChanged="GridView1_SelectedIndexChanged" to SELECT data in second and third page and so on:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" DataSourceID="sdsDocuments" EnableModelValidation="True"
SelectedIndex="0" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" DataKeyNames="DocumentID, DocumentTitle, DocumentBody">
Then on the event OnSelectedIndexChanged="GridView1_SelectedIndexChanged" :
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
DataTable dt = // your SELECT statement //
GridView1.DataSource = dt;
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
if you dont use this void then you will get same error when you click page 2
DataSet Année = new DataSet();
Année.ReadXml(Server.MapPath("~/Annees.xml"));
DropDownList1.DataTextField = "Number";
DropDownList1.DataValueField = "Number";
DropDownList1.DataSource = "Année";
DropDownList1.DataBind();