 |
| ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

April 10th, 2013, 07:15 AM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 9
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
Load Repeater (Data)content on click event?
I have a Repeater control and there is a gridview inside this repeater and when users adds comment i want to populate the gridview and display the newly added comment instantly, how could i do this? I use exact the same structure on the book as LINQ anonymous type. Any idea or help will be appreciated. Thanks!
Last edited by master777; April 10th, 2013 at 10:16 AM..
|
|

April 10th, 2013, 07:31 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
The error is on line 17....
Imar
|
|

April 10th, 2013, 07:55 PM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 9
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
Sorry!
I like to remove this thread if possible?
|
|

April 11th, 2013, 03:05 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Did you figure it out? As I suggested in my other post, it's impossible to help if you don't post the relevant bits of code.....
Cheers,
Imar
|
|

April 11th, 2013, 07:52 AM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 9
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
Sure!
Hi, I thought you already know what i am using because the structure and the idea is identical actually(yours), just swap the Genre with as "Event" and comments remains the same hence i created a "Add Event" function form that you can add an event(genre) and add your comments right beneath the particular event. Would you like to see the repeater code? it's slightly different! I use a table to display events items and i use GridView to display comments. I also use DetailsView to obtain the comments but this is out of the Repeater. All I am trying to achieve is to have gridView populate exactly when the new comment is added and display it shortly after a "Add Comment" Button Click Event is fired. Which it didn't work!
Here is the example of my code;
MarkUp Code:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" OnLoad="UpdatePanel1_Load"
OnPreRender="UpdatePanel1_PreRender" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound"
OnItemCommand="RepeaterGetSelectedID">
<HeaderTemplate>
<br />
<center>
<h1 style="color: Gray; font-size: 18pt;">
Local Events</h1>
</center>
<div id="NoRecords" runat="server" visible="false" style="text-align: center;">
<asp:Label ID="Label9" runat="server" Text="No current events are available." CssClass="ErrorMessage"
Font-Italic="True" Font-Bold="True" Font-Size="Large"></asp:Label>
</div>
</HeaderTemplate>
<ItemTemplate>
<div class="EventsComments">
<div id="divDisplay">
<table class="style1" align="left" id="tblEventsArea">
<tr>
<td rowspan="8" align="left" class="style3" width="150">
<asp:HiddenField ID="HiddenID" runat="server" Value='<%# Eval("Id") %>' />
<img id="Img1" alt="All Stars Cyprus Event Photo JPG" src="/Images/NoPhotoAvailable.jpg"
runat="server" style="max-height: 255px; max-width: 255px;" class="Image3" />
</td>
<td class="style5" width="10">
</td>
<td class="style5" width="120" nowrap="nowrap">
Venue Name:
</td>
<td class="style1" width="510px">
<asp:Label ID="lblVenueName" runat="server" Text='<%# Eval("VenueName") %>' Style="font-weight: 700;
color: #993333; font-size: 20px"></asp:Label>
</td>
</tr>
<tr>
<td class="style3" width="10">
</td>
<td class="style3" width="120" nowrap="nowrap">
Event Type:
</td>
<td class="style4" width="510px">
<asp:Label ID="Label2" runat="server" Text='<%# Eval("EventType") %>' Style="color: #000066;
font-weight: 700"></asp:Label>
</td>
</tr>
<tr>
<td class="style5" width="10">
</td>
<td class="style5" width="120" nowrap="nowrap">
Event Date:
</td>
<td class="style1" width="510px">
<asp:Label ID="Label3" runat="server" Text='<%# Eval("Date") %>'
Style="font-weight: 700; font-size: 15px; color: #FF3300"></asp:Label>
</td>
</tr>
<tr>
<td class="style5" width="10">
</td>
<td class="style5" width="120" nowrap="nowrap">
Starting Time:
</td>
<td class="style1" width="510px">
<asp:Label ID="Label4" runat="server" Text='<%# Eval("StartTime") %>'
Style="font-weight: 700; font-size: 15px; color: #000000"></asp:Label>
</td>
</tr>
<tr>
<td class="style5" width="10">
</td>
<td class="style5" width="120" nowrap="nowrap">
Ending Time:
</td>
<td class="style1" width="510px">
<asp:Label ID="Label5" runat="server" Text='<%# Eval("EndTime") %>'
Style="font-weight: 700; font-size: 15px; color: #000000"></asp:Label>
</td>
</tr>
<tr>
<td class="style5" width="10">
</td>
<td class="style5" width="120" nowrap="nowrap">
Contact Phone:
</td>
<td class="style1" width="510px">
<asp:Label ID="Label6" runat="server" Text='<%# Eval("Phone") %>' Style="color: #FF3300;
font-size: 15px; font-weight: 700"></asp:Label>
</td>
</tr>
<tr>
<td class="style5" valign="top" width="10">
</td>
<td class="style5" valign="top" width="120" nowrap="nowrap">
Address:
</td>
<td class="style1" valign="top" width="510px">
<asp:Label ID="Label7" runat="server" Text='<%# Eval("Address") %>' Style="color: #333333;
font-size: 15px; font-weight: 700"></asp:Label>
</td>
</tr>
<tr>
<td class="style5" valign="top" width="10">
</td>
<td class="style5" valign="top" width="120">
</td>
<td align="right" class="style1" valign="top" width="510px">
<br />
<asp:LinkButton ID="lnkSelect" CommandName="Select" runat="server" OnClick="lnkSelect_Click"
Font-Italic="True" ToolTip="Post your comment for this event." CssClass="addComment"> Add your comment here!</asp:LinkButton>
</td>
</tr>
</table>
</div>
</div>
<br />
<div id="reviews">
<asp:GridView ID="GridView1" runat="server" DataSource='<%# Eval("Reviews") %>' AutoGenerateColumns="False"
BackColor="#FFFFE6" Font-Size="Medium" BorderStyle="Solid" CellSpacing="1" CellPadding="10"
ForeColor="#333333" AlternatingRowStyle-BackColor="#CCCCCC" Width="811px" CssClass="grid">
<AlternatingRowStyle BackColor="#EEFFFE"></AlternatingRowStyle>
<Columns>
<asp:BoundField HeaderText="Commented By" DataField='NickName' ItemStyle-Wrap="False"
ItemStyle-Height="25" ItemStyle-Width="150">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle Wrap="False" Height="25px" Width="150px" HorizontalAlign="Center" Font-Bold="True"
ForeColor="#0000CC"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="Comment" DataField="Comment">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle ForeColor="Maroon" Font-Bold="false" />
</asp:BoundField>
<asp:TemplateField HeaderText="Date &Time Created">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("CreateDateTime") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblCreateDateTime" runat="server" Text='<%# Eval("CreateDateTime") %>'
ForeColor="#666666"></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" Width="180px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<br />
<br />
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
<DetailsView here that is used to insert comments />
CodeBehind for my Linq DataSource as;
var allEvents = from a in myEntities.AddEvents
where a.Authorized == true
where a.Date >= today
orderby a.Id descending
select new
{
a.Id,
a.VenueName,
a.EventType,
a.Date,
a.StartTime,
a.EndTime,
a.Address,
a.Phone,
a.Reviews
};
Repeater1.DataSource = allEvents;
Repeater1.DataBind();
I hope this would give you a sufficient idea which i am sure of that. Any help or idea will be appreciated, thanks!
P.S please let me know if i omitted anything above.
Last edited by master777; April 11th, 2013 at 08:03 AM..
|
|

April 11th, 2013, 11:13 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Have you tried calling DataBind on the control that displays the comments at the end of the Click handler for the Add Comment button?
Imar
|
|

April 11th, 2013, 01:18 PM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 9
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
Sure!
Hi, Honestly i have tried various stuff, i.e. tried populating the whole LINQ data expression in the click event so i could have my GridView populated, or updatePnl.update() which i couldn't make this working at all! either on the click nor pageLoad, init. onLoad, preRender etc. Thus i don't know what we have it's method for? I also tried to (postBack)refresh the page to cause dataGrid populate and display newly added(inserted) record on the click event and pageLoad but no! no! no!. Since i am new and started like last year by collecting and building my programming library where consist of the physical books, so i can hardly say that i am experienced enough to know about these things. In fact this is my very first try on many things right from databases to collect values dynamically so on and so forth. I have been searching though the internet for over a week but can't find anything about it. I am really frustrated! and overwhelmed. just need a help here.
I think i know what you mean! it's like this:
GridView1.DataBind();
I don't know how to use this! because i am new on SQL and i have not much ideas especially in a scenario like yours! It confuses me a lot because you use Review entity as a data item. It's kind of advanced and i have no idea ultimately! Could you please give me a tip please? Thank you!!!
|
|

April 11th, 2013, 01:22 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
>> I don't know how to use this!
Exactly as you showed, from the button's click event handler.
I see that the GridView is inside the Repeater, so maybe you need to rebind the data to the Repeater and call DataBind, similar to how you bind it on the initial load?
Alternatively, you could redirect to the same.
Cheers,
Imar
|
|

April 11th, 2013, 08:21 PM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 9
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
Finally
Hi, I have finally managed to achieve this by using the itemInserted event handler so it wasn't the click event all along. Sweet Jesus! Yey! I have to thank you for helping me by writing and publishing this book and also helping each of us individually via your site! Thank you! God Bless you! :)
|
|
 |