473,322 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

c# add button to repeater?

how do I add a linkbutton or asp:button to a datarepeater and
fire an event?

I am using this as my example code:

http://msdn.microsoft.com/library/de...ynamically.asp
--
tym, Eskimo
Nov 18 '05 #1
3 8570
Try something like this. In your page, you have a repeater...

<asp:Repeater id="HomesRepeater" runat="server">
<ItemTemplate>
<tr>
<td class="HomesItem" colspan="2" valign="middle">
<asp:LinkButton ID="linkHomeItem" Runat="server"
OnCommand="LinkButtonClick"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "MlsNumber")
%>'
CommandName='<%# DataBinder.Eval(Container.DataItem, "CoagentID_NE")
%>'>
<%# DataBinder.Eval(Container.DataItem, "Address") %>,&nbsp;
<%# DataBinder.Eval(Container.DataItem, "City") %>,&nbsp;
<%# DataBinder.Eval(Container.DataItem, "State") %>&nbsp;
<%# DataBinder.Eval(Container.DataItem, "Zip") %>
</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
... if you have one...
</AlternatingItemTemplate>
</asp:Repeater>

Then in your codebehind file do this...

protected void LinkButtonClick(Object sender, CommandEventArgs e){
// do something here
}

--
Alex Mueller
Nov 18 '05 #2
I'm using a custom template so the ItemTemplate is not in the html
on the webform.
e.g.

<form id="Form1" method="post" runat="server">
<asp:Repeater id="Repeater1" runat="server"></asp:Repeater>
</form>

I have to run - but I'll get an example with the northwind database
going so I can post it to you....

"Alex" wrote:
Try something like this. In your page, you have a repeater...

<asp:Repeater id="HomesRepeater" runat="server">
<ItemTemplate>
<tr>
<td class="HomesItem" colspan="2" valign="middle">
<asp:LinkButton ID="linkHomeItem" Runat="server"
OnCommand="LinkButtonClick"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "MlsNumber")
%>'
CommandName='<%# DataBinder.Eval(Container.DataItem, "CoagentID_NE")
%>'>
<%# DataBinder.Eval(Container.DataItem, "Address") %>,
<%# DataBinder.Eval(Container.DataItem, "City") %>,
<%# DataBinder.Eval(Container.DataItem, "State") %>
<%# DataBinder.Eval(Container.DataItem, "Zip") %>
</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
... if you have one...
</AlternatingItemTemplate>
</asp:Repeater>

Then in your codebehind file do this...

protected void LinkButtonClick(Object sender, CommandEventArgs e){
// do something here
}

--
Alex Mueller

Nov 18 '05 #3
works like a charm alex!

"Alex" wrote:
Try something like this. In your page, you have a repeater...

<asp:Repeater id="HomesRepeater" runat="server">
<ItemTemplate>
<tr>
<td class="HomesItem" colspan="2" valign="middle">
<asp:LinkButton ID="linkHomeItem" Runat="server"
OnCommand="LinkButtonClick"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "MlsNumber")
%>'
CommandName='<%# DataBinder.Eval(Container.DataItem, "CoagentID_NE")
%>'>
<%# DataBinder.Eval(Container.DataItem, "Address") %>,
<%# DataBinder.Eval(Container.DataItem, "City") %>,
<%# DataBinder.Eval(Container.DataItem, "State") %>
<%# DataBinder.Eval(Container.DataItem, "Zip") %>
</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
... if you have one...
</AlternatingItemTemplate>
</asp:Repeater>

Then in your codebehind file do this...

protected void LinkButtonClick(Object sender, CommandEventArgs e){
// do something here
}

--
Alex Mueller

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Keith Harris | last post by:
Hi, I have a Repeater control which is bound to a dataset. In the footer of the repeater control, I have a Button whose visibility I want to vary according to the sum of a column being > 0. ...
2
by: pnr | last post by:
I have an repeater that contains data witch it schould be possible to delete, I have placed a delete button in each row, but i can't make it work :-( This is my repeater (just a little bit of...
1
by: Keith Harris | last post by:
Hi, I have a Repeater control which is bound to a dataset. In the footer of the repeater control, I have a Button whose visibility I want to vary according to the sum of a column being > 0. ...
1
by: Mauritsius | last post by:
I have a simple page where I would like to modify a repeater (bounded to a dataset) if a button (outside the repeater) is clicked or not. I tried to solve this with a button click event that...
3
by: Shimon Sim | last post by:
I put linkbutton in a repeater header. I attached event handler in makeup as onclick="btnSort_Click". Made btnSort_Click method public. It doesn't fire if I click on it. I tried to attach it in...
9
by: mosscliffe | last post by:
I am sorry but I am all very new and slow at understanding all this ASP.NET2. I found some code which showed how to page with a repeater. All very excited as I had been looking for this all...
3
by: koonda | last post by:
Hi Guys, I have 5 listbox controls which I populated from the database tables. I tried it using the wizard. For all 5 listboxes and a single Repeater I used a SQL DataSourse Object and mapped this...
3
by: Queez | last post by:
I have an issue with an ASP repeater which is seriously frustrating me. In simple terms, I have an ASP repeater which is meant to display a list of items for a wedding list, including the name of...
4
by: Nathan Sokalski | last post by:
I have a Button that uses the PostBackUrl property which is inside a Repeater template. When I get to the Page that is being posted to (the one specified in PostBackUrl), I am having trouble...
1
by: semomaniz | last post by:
I have a button inside a repeater which is supposed to open a popup when clicked. But when i click on the button my modalpopup does not open. The strange thing is on the code provided below if i...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.