Adding button in asp:repeater

  • Thread starter Thread starter simon
  • Start date Start date
S

simon

I have <asp:repeater> with Item template:

<ItemTemplate>
<%# writeLine(DataBinder.Eval(Container.DataItem, "danIme"),DataBinder.Eval(Container.DataItem, "timeStart"))%>
</ItemTemplate>

In my function writeLine, I would like to add in some cases, <asp:button>
Protected Function writeLine(ByVal dayName As String, ByVal timeS As String) As String

If dayName="Friday" then
writeLine="<asp:button> + some HTML sintaks"
else
writeLine = "some html sintaks"
end if

End Function


How can I do that?

Thank you,
Simon
 
Can I have some if statements in my template, like I have them into my write functions.

For example:
<itemTemplate>
<%IF danIme=dayOld then%>
<tr><td><asp:button>
<% else%>
<table><tR>.......
<%end if%>

Thank you,
Simon
Simon,

On databinding stage you can't add any server controls programmatically. You rather should include everything in the template and manipulate visibility settings.

Eliyahu

I have <asp:repeater> with Item template:

<ItemTemplate>
<%# writeLine(DataBinder.Eval(Container.DataItem, "danIme"),DataBinder.Eval(Container.DataItem, "timeStart"))%>
</ItemTemplate>

In my function writeLine, I would like to add in some cases, <asp:button>
Protected Function writeLine(ByVal dayName As String, ByVal timeS As String) As String

If dayName="Friday" then
writeLine="<asp:button> + some HTML sintaks"
else
writeLine = "some html sintaks"
end if

End Function


How can I do that?

Thank you,
Simon
 
Why I can't use in my function writeLine, which is in my ItemTemplate, some other control clientID property?

Is there some other way?

writeLine = "</td></tr><tr><td><table bgcolor='white' width=100%><tr><td>" & dan & "</tD><td><input onclick='" & btnDelete.ClientID & ".click()' type='button' value='Delete'></td></tR><tr><td><ul>"

Thank you,

Simon

Simon,

On databinding stage you can't add any server controls programmatically. You rather should include everything in the template and manipulate visibility settings.

Eliyahu

I have <asp:repeater> with Item template:

<ItemTemplate>
<%# writeLine(DataBinder.Eval(Container.DataItem, "danIme"),DataBinder.Eval(Container.DataItem, "timeStart"))%>
</ItemTemplate>

In my function writeLine, I would like to add in some cases, <asp:button>
Protected Function writeLine(ByVal dayName As String, ByVal timeS As String) As String

If dayName="Friday" then
writeLine="<asp:button> + some HTML sintaks"
else
writeLine = "some html sintaks"
end if

End Function


How can I do that?

Thank you,
Simon
 
Simon,

On databinding stage you can't add any server controls programmatically. You rather should include everything in the template and manipulate visibility settings.

Eliyahu

I have <asp:repeater> with Item template:

<ItemTemplate>
<%# writeLine(DataBinder.Eval(Container.DataItem, "danIme"),DataBinder.Eval(Container.DataItem, "timeStart"))%>
</ItemTemplate>

In my function writeLine, I would like to add in some cases, <asp:button>
Protected Function writeLine(ByVal dayName As String, ByVal timeS As String) As String

If dayName="Friday" then
writeLine="<asp:button> + some HTML sintaks"
else
writeLine = "some html sintaks"
end if

End Function


How can I do that?

Thank you,
Simon
 
No. The point is that server components need compilation and it happens before databinding. Put all server controls in the template and than set Visible=false in the code-behind or databind Visible property in the ..aspx file. A server control with Visible=false won't be rendered to the client, exactly what you want if I understand you correctly.

Eliyahu

Can I have some if statements in my template, like I have them into my write functions.

For example:
<itemTemplate>
<%IF danIme=dayOld then%>
<tr><td><asp:button>
<% else%>
<table><tR>.......
<%end if%>

Thank you,
Simon
Simon,

On databinding stage you can't add any server controls programmatically. You rather should include everything in the template and manipulate visibility settings.

Eliyahu

I have <asp:repeater> with Item template:

<ItemTemplate>
<%# writeLine(DataBinder.Eval(Container.DataItem, "danIme"),DataBinder.Eval(Container.DataItem, "timeStart"))%>
</ItemTemplate>

In my function writeLine, I would like to add in some cases, <asp:button>
Protected Function writeLine(ByVal dayName As String, ByVal timeS As String) As String

If dayName="Friday" then
writeLine="<asp:button> + some HTML sintaks"
else
writeLine = "some html sintaks"
end if

End Function


How can I do that?

Thank you,
Simon
 
If I have:
<ItemTemplate>
<tr runat="server" id="trName">
<td><%#DataBinder.Eval(Container.DataItem, "danIme")%></td>
</tr>
<%# writeLine(DataBinder.Eval(Container.DataItem, "danIme"),DataBinder.Eval(Container.DataItem, "timeStart"))%>
</ItemTemplate>

AND then in writeLine function I would like to set the visible property of my row:
trName.Visible = False

I get an error message: Not set to the instance of the object.

In page I have declared:
Protected WithEvents trName As System.Web.UI.HtmlControls.HtmlTableRow

Where is the problem and how I can solve it?

Thank you,
Simon

No. The point is that server components need compilation and it happens before databinding. Put all server controls in the template and than set Visible=false in the code-behind or databind Visible property in the ..aspx file. A server control with Visible=false won't be rendered to the client, exactly what you want if I understand you correctly.

Eliyahu

Can I have some if statements in my template, like I have them into my write functions.

For example:
<itemTemplate>
<%IF danIme=dayOld then%>
<tr><td><asp:button>
<% else%>
<table><tR>.......
<%end if%>

Thank you,
Simon
Simon,

On databinding stage you can't add any server controls programmatically. You rather should include everything in the template and manipulate visibility settings.

Eliyahu

I have <asp:repeater> with Item template:

<ItemTemplate>
<%# writeLine(DataBinder.Eval(Container.DataItem, "danIme"),DataBinder.Eval(Container.DataItem, "timeStart"))%>
</ItemTemplate>

In my function writeLine, I would like to add in some cases, <asp:button>
Protected Function writeLine(ByVal dayName As String, ByVal timeS As String) As String
If dayName="Friday" then
writeLine="<asp:button> + some HTML sintaks"
else
writeLine = "some html sintaks"
end if
End Function

How can I do that?

Thank you,
Simon
 
Simon,

Are you sure you are on the right track? What us your task? Looks, like you are trying to build a table in a repeater? What does writeLine do? Trying to write an html for the table row?

May be you should rather re-design to using normal datagrid with templates built in a regular way?

Eliyahu

If I have:
<ItemTemplate>
<tr runat="server" id="trName">
<td><%#DataBinder.Eval(Container.DataItem, "danIme")%></td>
</tr>
<%# writeLine(DataBinder.Eval(Container.DataItem, "danIme"),DataBinder.Eval(Container.DataItem, "timeStart"))%>
</ItemTemplate>

AND then in writeLine function I would like to set the visible property of my row:
trName.Visible = False

I get an error message: Not set to the instance of the object.

In page I have declared:
Protected WithEvents trName As System.Web.UI.HtmlControls.HtmlTableRow

Where is the problem and how I can solve it?

Thank you,
Simon

No. The point is that server components need compilation and it happens before databinding. Put all server controls in the template and than set Visible=false in the code-behind or databind Visible property in the .aspx file. A server control with Visible=false won't be rendered to the client, exactly what you want if I understand you correctly.

Eliyahu

Can I have some if statements in my template, like I have them into my write functions.

For example:
<itemTemplate>
<%IF danIme=dayOld then%>
<tr><td><asp:button>
<% else%>
<table><tR>.......
<%end if%>

Thank you,
Simon
Simon,

On databinding stage you can't add any server controls programmatically. You rather should include everything in the template and manipulate visibility settings.

Eliyahu

I have <asp:repeater> with Item template:

<ItemTemplate>
<%# writeLine(DataBinder.Eval(Container.DataItem, "danIme"),DataBinder.Eval(Container.DataItem, "timeStart"))%>
</ItemTemplate>

In my function writeLine, I would like to add in some cases, <asp:button>
Protected Function writeLine(ByVal dayName As String, ByVal timeS As String) As String
If dayName="Friday" then
writeLine="<asp:button> + some HTML sintaks"
else
writeLine = "some html sintaks"
end if
End Function

How can I do that?

Thank you,
Simon
 
Back
Top