An update:

I changed my GridView replacing: <%#Eval("Name")%>  for <asp:Label
ID="NameLabel" runat="server" Text='<%#Eval("Name")%>' />
And, in the function BindMyGridView, after the lines:

myGridView.DataSource = dTable
myGridView.DataBind()

I put the following code to test if the text in the Label is correct:

For k As Integer = 0 To myGridView.Rows.Count - 1
      Dim NameLabel As Label = myGridView.Rows(k).FindControl
("NameLabel")
      Dim str As String = myGridView.Text
Next

I went through about 20 iterations in this for loop, and the text in
the Label is correct. I have no idea why the blank spaces are not
removed from the GridView! Please, I need some help! =S

Thanks.

On Aug 27, 10:47 am, Ana <[email protected]> wrote:
> Hi,
>
> In my page I have a GridView and I'm binding it in the code behind.
> The data in my gridView should appear similar to a directory structure
> (but in my case using a TreeView doesn't apply). So my GridView should
> be like this:
>
> Name 1
>     Name 1.1
>     Name 1.2
> Name 2
>     Name 2.1
>         Name 2.1.1
>
> To do this, I'm updating the value for the column "Name" in the
> DataTable used to populate the GridView. For example, for Name 1.1,
> I'm doing:
> newName = "    " + row("Name")
> row("Name") = newName
>
> The DataTable is with the values I expect, but the values in the
> GridView are not matching the values in the DataTable. In the GridView
> the list is just:
>
> Name 1
> Name 1.1
> Name 1.2
> Name 2
> Name 2.1
> Name 2.1.1
>
> My code is as follows:
> GridView:
>
> <asp:GridView ...>
>         <Columns>
>             <asp:TemplateField HeaderText="Title">
>                 <ItemTemplate>
>                     <%#Eval("Name")%>
>                 </ItemTemplate>
>             </asp:TemplateField>
>             <asp:ButtonField Text="Details..." HeaderText="Show
> Details" CommandName="Select">
>             </asp:ButtonField>
>         </Columns>
>     </asp:GridView>
>
> Code for binding the DataTable:
>
> Private Function BindmyGridView () As DataTable
>         Dim DatabaseConnection As New SqlConnection
> (ConfigurationManager.ConnectionStrings("myServer").ConnectionString)
>         Dim selectSQL As String = "SELECT [ID], [Name] FROM [Table]"
>         Dim selectCMD As New SqlCommand(selectSQL, DatabaseConnection)
>         Dim dTable As New DataTable()
>         Dim adapter As New SqlDataAdapter()
>         dTable.Columns.Add("Id")
>         dTable.Columns.Add("Name")
>
>         adapter.SelectCommand = selectCMD
>         adapter.Fill(dTable)
>
>         dTable = indentTable(dTable)
>
>         myGridView.DataSource = dTable
>         myGridView.DataBind()
>
>         Return dTable
>     End Function
>
> Any ideas of what's is wrong and what do to to fix it?
>
> Thanks in advance for all the replies,
>
> Ana

Reply via email to