views:

70

answers:

1

Hello,

I want to stylize a SPGridview as row-based. I can do it in ASP .Net as follows (this is sample code and doesn't have a meaning. I wrote here because of describing the problem clearly on programmer side):

<asp:GridView runat="server" ID="myGrid" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table>
<tr>
<td>
<b>Position:</b> <%#Eval("Position") %><br />
<b>Gender</b> <%#Eval("Gender") %>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Of course, Eval sections should match with SQL Columns names in query string. So I want to do same with Sharepoint Gridview. SPGridview supports item template too but the problem is how to bind data to Eval (or whatever in Sharepoint) sections.

This problem seems to you silly but there is a big text field in a SPList and I want to show it under title using a webpart. I tried views also but I think SharePoint has "Column-based" logic.

I think this problem may be solved by using CAML Query but I don't know how to bind data to Databinder.Eval() sections in Webpart page. For example, when you use sql and asp.net, you can write connection string to web.config file and define it in datasource in aspx page and you can write query in aspx page... You can also add parameters too. I try to work in same way, but I don't know how to define SPList (which is connection string in sql scenario) and get data. I tried the following but no luck:

<SharePoint:SPGridView runat="server" ID="acikPozGrid" AutoGenerateColumns="false" DataSourceID="SPDataSourceCan">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table>
<tr>
<td>
<b>Pozisyon:</b> <%#DataBinder.Eval(Container.DataItem,"isUnvaniTextBox").ToString() %>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</SharePoint:SPGridView>
<SharePoint:SPDataSource ID="SPDataSourceCan" SelectCommand="<View><Query><Where><IsNotNull><Fieldref Name='isUnvaniTextBox'></Fieldref></IsNotNull></Where></Query></View>" runat="server" DataSourceMode="List">
<SelectParameters>
<asp:Parameter Name="WebURL" DefaultValue="http://omni-can/insankaynaklari" />
<asp:Parameter Name="ListID" DefaultValue="0E50737C-D9A9-4E89-8E5F-E1CFA2310930" />
</SelectParameters>
</SharePoint:SPDataSource>

Do you have any suggestion?

A: 

I would say IMHO it is best to feed SPGridView with SPDataSource but if you want to use SQL Data you can always do it, refer this Link where you can find example on how to do that. Also this article talks more about adding Menu to the Grid.

Kusek