Here you will find the code to bind document Library data in gridview using SharePoint 2010 object model:
Source:
<asp:GridView ID="grdDocs" runat="server" AutoGenerateColumns="true"
ForeColor="Black" GridLines="None" AllowPaging="True" PageSize="15">
<AlternatingRowStyle BackColor="#EFEFFE" />
<FooterStyle BackColor="#000" />
<HeaderStyle BackColor="#efefef" Font-Bold="True" ForeColor="DarkSlateBlue" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"
HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#EFEFFE" ForeColor="GhostWhite" />
</asp:GridView>
.cs Code:
public void BindDocuments()
{
try
{
SPSite mysite = SPContext.Current.Site;
SPWeb web = mysite.RootWeb;
SPList oList = web.Lists["Doc Lib Name"];
SPView oView = oList.Views["View Name"];
SPQuery oQuery = new SPQuery(oView);
oQuery.ViewAttributes = "Scope=\"RecursiveAll\"";
SPListItemCollection collListItemsAvailable = oList.GetItems(oQuery);
grdDocs.DataSource = collListItemsAvailable.GetDataTable();
grdDocs.DataBind();
}
catch(Exception ex){
}
}