v2 - GridView - UserControl .ascx - Problem

A

Alexander Widera

Hi,

I have the following source code:

<%@ Register tagprefix="my" tagname="tcontrol" Src="article_small.ascx" %>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:ShopConnectionString %>" SelectCommand="SELECT
AricleNumber FROM Articles;"></asp:SqlDataSource>
<asp:GridView ID="List1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<my:tcontrol runat=server ArticleNumber=<%# Eval("ArticleNumber") %> />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

With this I get the following errormessage:
"Databinding methods such as Eval(), XPath(), and Bind() can only be used
in
the context of a databound control."

But how can I realize that what I want? Is there a workaround?

Thanks,

Alex
 
G

Guest

Hi Alexander,

It has to do with what your user control is doing. You might want to post
the code in your user control.

I met that error when a dropdown list within FormView caused a postback to
change the values of another dropdownlist within the templated control. I
solved it by removing the databind on the dependent list:
http://www.webswapp.com/CodeSamples/aspnet20/FormView1.aspx
 
A

Alexander Widera

Yes, there was an "illegal" DataBind(). But now I have the Problem, that
the
data is not bound. I get empty <div>-tags, where should be content.

the control looks like that:
<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="article_small.ascx.cs" Inherits="shop_ArticleSmall" %>

<script runat="server" >

public Article article;

public string ArticleNumber {

set { article = new Article(value); }

get { return article.Articlenumber; }

}

</script>


<div class="ArticleSmall">

<div class="ArticleSmallNew" runat="server"> <%# article.ArticleNumber %>
</div>

<div class="ArticleSmallTitle"> <%# article.Title %> </div>

</div>


Perhaps it has something to do with the public in "public Article article"
.... but if I use private then I get the error "'shop_ArticleSmall.artikel'
is inaccessible due to its protection level"

Can someone help me?
Perhaps the solution is allready in
http://www.webswapp.com/CodeSamples/viewsource.aspx?file=\aspnet20\FormVie
w1.aspx
but I don't get it work.

Please help.

Thanks,

alex
 
A

Alexander Widera

oh, i forgot:
Article is a selfmade class.... it collects some data ... article.Title and
article.ArticleNumber are returning string values.



"Alexander Widera"
 
A

Alexander Widera

Well, thanks for help ... I found the error myself ... it was a completely
other problem.

Case closed

"Alexander Widera"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top