I have a C# repeater that is running a test list of objects and it runs the correct amount of iterations. The problem is is that the data is not visible on the web page. I have created an object but it seems like I am not accessing it correctly when it is time to bind it.
I have tested the objects and they do contain the test data.
ASPX CODE
<asp:Repeater ID="repeater" runat="server">
<ItemTemplate>
<asp:Panel ID="header" runat="server">
<asp:Panel ID="reportName" runat="server">
<p class='text-bold-xlg'>
<asp:Label ID="CampaignNameData" Text="Campaign Name" runat="server"></asp:Label></p>
<p class="text-md">
<asp:Label ID="ReportRangeLabel" Text="Report Range: " runat="server"></asp:Label>
<asp:Label ID="ReportRangeData" Text="" runat="server"></asp:Label>
</p>
</asp:Panel>
<asp:Panel ID="logo" runat="server">
<img src="images/Picture1.jpg" runat="server" enableviewstate="true" />
</asp:Panel>
</asp:Panel>
<asp:Panel ID="info" runat="server">
<asp:Panel ID="drPersonal" runat="server">
<p class='text-bold-lg'>
<asp:Label ID="DoctorNameData" Text="<%# DataBinder.Eval(Container.DataItem, "Name") %>"></asp:Label></p>
<asp:Table ID='drInfoTable' runat="server">
<asp:TableRow>
<asp:TableCell>
<p class='text-bold-md'>
<asp:Label ID="SpecialtyLabel" Text="Specialty:" runat="server"></asp:Label></p>
</asp:TableCell>
<asp:TableCell>
<p class='text-md'>
<asp:Label ID="SpecialtyData" Text="<%# DataBinder.Eval(Container.DataItem, "Specialty") %>"></asp:Label></p>
</asp:TableCell>
</asp:TableRow>
<..close table>
</itemTemplate>
</asp:Repeater>
ASPX.CS CODE
protected void Page_Load(object sender, EventArgs e)
{
List<Doctor> lstHcp = new List<Doctor>();
Doctor a = new Doctor();
a.Name = "Dr. A";
a.Decile = "10";
Doctor b = new Doctor();
b.Name = "Dr. B";
b.Decile = "5";
Doctor c = new Doctor();
c.Name = "Dr. C";
c.Decile = "7";
Doctor d = new Doctor();
d.Name = "Dr. D";
d.Decile = "2";
lstHcp.Add(a);
lstHcp.Add(b);
lstHcp.Add(c);
lstHcp.Add(d);
repeater.DataSource = lstHcp;
repeater.DataBind();
The asp:Label is missing the runat attribute.
The line should be:
<asp:Label ID="DoctorNameData" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>'></asp:Label>
(notice the use of single quotes for the Text attribute. Else a The server tag is not well formed. exception will be thrown)
DataBinder.Eval(Container.DataItem, "Specialty")
change it to following:
DataBinder.Eval(Container.DataItem, "Decile")
Related
I'm trying to implement a reinitialization button in my page which is linked to an UpdatePanel (AsyncPostBackTrigger). When i click on the button, it deals with an UpdateProgress.
The problem is that, because the reinitialization button is linked with an update panel, it cannot reinitialize what is outside of the UpdatePanel.
Is there a way to do some changes to the controls outside of the UpdatePanel without adding an UpdatePanel for the whole page ? In this case, i want to reinitialize the DropDownLists, the Textbox and the Repeater contained in the UpdatePanel.
How the page is rendered
ASPX code :
<body style="padding: 50px;">
<form id="form1" runat="server">
<asp:Label runat="server" ID="test"></asp:Label>
<asp:HiddenField runat="server" ID="AllDemandsTypeHfi"></asp:HiddenField>
<asp:ScriptManager runat="server" ID="ScriptManager"></asp:ScriptManager>
<asp:Panel runat="server" CssClass="panel-page-title">Création de demande</asp:Panel>
<asp:Panel runat="server" CssClass="panel-primary">
<asp:Panel runat="server" CssClass="panel-heading">Configuration de la recherche</asp:Panel>
<asp:Panel runat="server" CssClass="panel-body">
<asp:Table runat="server">
<asp:TableRow ID="BankRow">
<asp:TableCell>
<asp:Label runat="server">Banque : </asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:DropDownList runat="server" ID="BankDdl" AutoPostBack="true" OnSelectedIndexChanged="BankDdl_SelectedIndexChanged"></asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Label runat="server">Famille : </asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:DropDownList runat="server" ID="FamilyDdl" AutoPostBack="true" OnSelectedIndexChanged="FamilyDdl_SelectedIndexChanged"></asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Label runat="server">Motif : </asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:DropDownList runat="server" ID="MotiveDdl" AutoPostBack="true" OnSelectedIndexChanged="MotiveDdl_SelectedIndexChanged"></asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Label runat="server">Sous-motif : </asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:DropDownList runat="server" ID="SubmotiveDdl" AutoPostBack="true" OnSelectedIndexChanged="SubmotiveDdl_SelectedIndexChanged"></asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Label runat="server">Mots-clés : </asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox runat="server" ID="KeywordsTbx" data-target="#modalSuggestions" data-toggle="modal"></asp:TextBox>
<div id="keywordsTbxSuggestions"></div>
<asp:HiddenField runat="server" ID="KeywordsSearchHfi"></asp:HiddenField>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<br />
<asp:Button runat="server" ID="ResearchBtn" Text="Rechercher" OnClick="ResearchBtn_Click" />
<asp:Button runat="server" ID="ReinitializeBtn" Text="Réinitialiser" OnClick="ReinitializeBtn_Click" />
</asp:Panel>
</asp:Panel>
<br />
<asp:UpdatePanel runat="server" ID="ResultsUpnl" ChildrenAsTriggers="true" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel runat="server" CssClass="panel-primary">
<asp:Panel runat="server" CssClass="panel-heading">Résultat de la recherche </asp:Panel>
<asp:Panel runat="server" CssClass="panel-body">
<asp:Label runat="server" ID="ResultsLb" Text="Veuillez sélectionner les critères de recherche, puis cliquer sur Rechercher."></asp:Label>
<asp:Repeater runat="server" ID="ResultsRpt">
<HeaderTemplate>
<asp:Label runat="server" Text="<b>Type de demande</b>"></asp:Label>
<table>
</HeaderTemplate>
<ItemTemplate>
<asp:Panel runat="server">
<asp:HyperLink runat="server" NavigateUrl='<%# Eval("Link") %>' Text='<%# Eval("Title") %>' Target="_blank"></asp:HyperLink>
</asp:Panel>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ResearchBtn" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="ReinitializeBtn" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UppDemandsResult" runat="server" DisplayAfter="0">
<ProgressTemplate>
<div style="text-align: center;">
<table style="width: 100%;">
<tr>
<td>
<Loader:LoaderComponent ID="UcLoadingProgess" runat="server" />
</td>
</tr>
</table>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</form>
</body>
Code-behind :
private void HandleReinitialization()
{
this.ResultsLb.Text = DemandCreationConstants.ResearchDefaultText;
this.familyDdlSelectedValue = string.Empty;
this.motiveDdlSelectedValue = string.Empty;
this.submotiveDdlSelectedValue = string.Empty;
this.LoadFamilies(true);
this.LoadMotives(false);
this.LoadSubmotives(false);
this.ResultsRpt.DataSource = null;
this.ResultsRpt.DataBind();
this.KeywordsSearchHfi.Value = string.Empty;
this.KeywordsTbx.Text = string.Empty;
LogServiceInstance.Debug("L'utilisateur " + UserSession.UserLogOn + " a réinitialisé la recherche.");
}
HandleReinitialization is launched by the event ReinitializeBtn_Click.
If understand you correctly, you will need to create UpdatePanel2 and add whatever controls into it, then in the button Click() method of the first UpdatePanel1 invoke the Update() method.
UpdatePanel2.Update();
Update:
Make sure you set the UpdateMode of UpdatePanel2 to "Conditional"
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
// Your controls
</ContentTemplate>
</asp:UpdatePanel>
that is html code for main page for social network .
i use a gridview by templet element that post and image bind from database by loading page but i want comnt for each post binded by click to buttin show comment
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<asp:GridView ID="gvPosts" runat="server"
AutoGenerateColumns="False" Height="46px" Width="45px">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<fieldset class="color">
<fieldset>
<asp:Label ID="Label5" runat="server" Text='<%# Eval("username") %>'></asp:Label>
<div class="crope_main" id="zoom">
<asp:Image ID="ImageUSER" runat="server" Width="50px" Height="50px" ImageUrl='<%# Eval("picture") %>' />
</div>
<asp:Label ID="Label6" runat="server" Text='<%# Eval("biografy") %>'></asp:Label>
<fieldset>
<asp:Label ID="Label7" runat="server" Text='<%# Eval("date_post") %>'></asp:Label>
</fieldset>
</fieldset>
<asp:Image ID="imgeposts" runat="server" Height="200px" Width="400px" ImageUrl='<%# Eval("pic_book") %>' Style="margin-top: 43px; margin-right: 2px;" />
<fieldset>
<asp:Label ID="Label1" runat="server" Text="NameBOOk:"></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("name_book") %>' />
</fieldset>
<fieldset>
<asp:Label ID="Label3" runat="server" Text="Writer:"></asp:Label>
<asp:Label ID="Label4" runat="server" Text='<%# Eval("wrieter") %>'></asp:Label>
</fieldset>
</fieldset>
<div>
<asp:Label ID="lblidpost" runat="server" Text='<%# Eval("id_post_FK") %>' Visible="false" />
<asp:Label ID="lbluser_id_email" runat="server" Text='<%# Eval("id_user_fk") %>' Visible="false" />
<asp:Label ID="lbllike" runat="server" Text='<%# Eval("SUM_LIKE") %>' />
</div>
<asp:TextBox ID="TxtSummery" runat="server" Text='<%# Eval("summery") %>' TextMode="MultiLine" Width="390px" Height="34px" Enabled="false"></asp:TextBox>
</div>
<div>
<asp:Button ID="btn_showComment" runat="server" Text="show comment" OnClick="btn_showComment_Click" />
</div>
<div>
<asp:TextBox runat="server" TextMode="MultiLine" Width="391px" ></asp:TextBox>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:ImageField>
</asp:ImageField>
</Columns>
</asp:GridView>
<asp:Image ID="imgLoader" runat="server" ImageUrl="~/images/loading.gif" />
</div>
</fieldset>
</asp:Content>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class pages_main : System.Web.UI.Page
{
string m,j, Btnn, ofline;
int k = 1, record = 0;
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{ BindData(); }
}
protected void BindData()
{
DataSet.usersDataTable oUserDataTable =
new DataSet.usersDataTable();
DataSetTableAdapters.usersTableAdapter oUserTableAdapter =
new DataSetTableAdapters.usersTableAdapter();
oUserTableAdapter.FillBy_userID(oUserDataTable, (Int64)Session["UserID"]);
DataSet.usersRow userrow = oUserDataTable[0];
//////////////////////////////////////////////////
DataSet.postDataTable postDatatabale = new DataSet.postDataTable();
DataSetTableAdapters.postTableAdapter postTabeladabtor = new DataSetTableAdapters.postTableAdapter();
postTabeladabtor.FillBy_showPost(postDatatabale, Session["email"].ToString());
///////////////////////////////////////////////////
//////////////////////////////////////////////////
if (postDatatabale.Count != 0)
{
DataSet.postRow postrow = postDatatabale[0];
string imageProfile = "~/profile/" + Session["Username"] + ".jpg";
gvPosts.DataSource = postDatatabale;
gvPosts.DataBind();
for (int i = 0; i < gvPosts.Rows.Count; i++)
{
ImageButton h = ((ImageButton)gvPosts.Rows[i].FindControl("imaglike"));
ImageButton h1 = ((ImageButton)gvPosts.Rows[i].FindControl("imageDisLike"));
//h.ID = "delbtn" + gvPosts.Rows[i];
// h1.ID = "imbtn" + gvPosts.Rows[i];
// h.ImageUrl = ("../Images/heart.png");
//h1.ImageUrl = ("../Images/Broken_Heart.png");
}
}
}
protected void btn_showComment_Click(object sender, EventArgs e)
{
GridViewRow gridViewRow = (GridViewRow)(sender as Control).Parent.Parent;
int index = gridViewRow.RowIndex;
Button btn = (Button)sender;
GridViewRow gvr = (GridViewRow)btn.NamingContainer;
m = ((Label)this.gvPosts.Rows[gvr.RowIndex].FindControl("lblidpost")).Text;
j = ((Label)this.gvPosts.Rows[gvr.RowIndex].FindControl("lbluser_id_email")).Text;
DataSet.commentDataTable comment = new DataSet.commentDataTable();
DataSetTableAdapters.commentTableAdapter ta_comment = new DataSetTableAdapters.commentTableAdapter();
ta_comment.FillBy_comment_post(comment, j, int.Parse(m));
DataSet.commentRow row = comment[index];
if(row.text_comment!="")
{
Response.Write("hello");
}
}
}
You have to use the RowCommand event:
<asp:Button ID="btn_showComment" runat="server" Text="show comment" CommandName="ShowComment" />
And then from the code beside:
protected void gvPosts_RowCommand(object source, RepeaterCommandEventArgs)
{
if (e.CommandName == "ShowComment")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = ContactsGridView.Rows[index];
}
}
Reference: https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand(v=vs.110).aspx
I have a aspx page called bookscategory.aspx with this markup:
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<p>Books list</p>
</HeaderTemplate>
<ItemTemplate>
<h3><asp:Literal ID="Literal1" runat="server" Text='<%# Eval("Category") %>'></asp:Literal></h3>
<asp:Repeater ID="Repeater1" runat="server" DataSource='<%# Eval("Reviews") %>' ItemType="ELibraryModel.Review">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Item.Title%>' NavigateUrl='<%# "../books/bookdetails.aspx?bookId=" + Item.Id.ToString() %>'>
</asp:HyperLink><br />
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
Code behind:
using (ELibraryEntities entities = new ELibraryEntities())
{
var allbooks = from books in entities.Books.Include("Reviews")
orderby books.Category
select new { books.Category, books.Reviews};
Repeater1.DataSource = allbooks;
Repeater1.DataBind();
}
Now on my Default.aspx page I have a book image:
<div class="prod_img">
<img src="../Images/asp.net_image.jpg" alt="" title="" border="0" /></a>
</div>
<div class="box_center">
<div class="prod_title">ASP.NET Book</div>
<p class="details">ASP.NET Book.</p>
- read more -
<div class="clear"></div>
</div>
Finally, when I click on this image I want to navigate to that exact review:
NavigateUrl='<%# "../books/bookdetails.aspx?ReviewId=" + Item.Id.ToString()
Everything works fine with asp:HyperLink-s but instead I want to use images.
I'm reading Beginning ASP.NET 4.5 in C# and VB and here you can see all reviews http://aspnet45.planetwrox.com/Reviews/All.aspx. I want to use Images instead HyperLinks.
HyperLink control already provides this capabilty - it has ImageUrl property, and when this is set, HyperLink appears as an image:
<asp:HyperLink runat="server" ID="HyperLink1"
NavigateUrl='<%# "../books/bookdetails.aspx?ReviewId=" + Item.Id.ToString() %>'
ImageUrl="~/url/to/image" />
Just want to ask how can I find hiddenfield in repeater because my problem I have button and I want to get the associate hiddenfield inside ItemTemplate because I get null value when I try to get hiddenfield value
<asp:Repeater ID="rp_resList" runat="server" OnItemDataBound="rp_resList_ItemDataBound">
<ItemTemplate>
<div class="resourcesResult">
<asp:HiddenField ID="hf_resID" runat="server" Value='<%# Eval("Id") %>' />
<a href='<%# Eval("pageID") %>'><%# Eval("name") %></a>
<br />
<asp:Literal ID="litSummary" runat="server" Text='<%# Eval("summary") %>'></asp:Literal>
<br />
<%-- <asp:Repeater ID="rp_tagsSkill" runat="server">
<ItemTemplate>
<h6>
<%# Eval("Description") %>
</h6>
</ItemTemplate>
</asp:Repeater>--%>
<asp:Repeater ID="rp_tagsTopics" runat="server">
<ItemTemplate>
<h6>
<%# Eval("Description") %>
</h6>
</ItemTemplate>
</asp:Repeater>
<div id="controls">
<asp:ImageButton ID="imgbtnBookmark" runat="server" OnClick="imgbtnBookmark_Click" />
<asp:DropDownList ID="ddlGroup" runat="server" DataSourceID="SqlDS_Groups" DataTextField="name" DataValueField="id" AppendDataBoundItems="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" >
<asp:ListItem Value="-1">Select Group</asp:ListItem>
protected void imgbtnBookmark_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Bookmark bm = new Bookmark();
HiddenField hiddenField = rptGroup.FindControl("hf_resID") as HiddenField;
bm.UserID =
Guid.Parse(Membership.GetUser(HttpContext.Current.User.Identity.Name).ProviderUserKey.ToString());
bm.Resoursce.ResourceID = Convert.ToInt32(hiddenField.Value);
Bookmark.Insert(bm);
}
Try this, change you button tag to pass id as CommandArgument value
<asp:ImageButton ID="imgbtnBookmark" runat="server"
OnClick="imgbtnBookmark_Click"
CommandArgument='<%# Eval("Id") %>'/>
in your button click event you can access id using
bm.Resoursce.ResourceID = Convert.ToInt32(e.CommandArgument.ToString());
Change rptGroup.FindControl("hf_resID") as HiddenField; to
e.Item.FindControl("hf_resID")....
I hope this link will help you .
jquery
function showid(dllval) {
var ID = $(dllval).parent().parent().find('[id*="hiddenID"]').val();
alert(ID)
}
asp.net
<asp:DropDownList ID="ddl" runat="server" onclick="showid(this);" >
</asp:DropDownList>
<asp:HiddenField ID="hiddenID" runat="server" Value='<%#Eval("ID")%>' />
My repeater:
<asp:Repeater ID="rptrContacts" runat="server" OnItemCommand="rptrContact_ItemCommand" >
<div ID="itemTemplate>
<ItemTemplate>
<%# Eval("Name") %>
<%# Eval("Email") %>
<asp:LinkButton ID="lbtnEditContact" runat="server" CommandName="Edit" Text="Edit" CommandArgument='<%# Eval("ContactID") %>' />
<asp:Label ID="lblUpdateConfirm" runat="server" Text="Update Confirmed" Visible="false" />
</ItemTemplate>
</div>
<div ID="editTemplate runat="server" visibility="false">
Update your Info:<br>
Name: <asp:TextBox ID="txtName" runat="server Text="<%# Eval("Name") %>"/> <br>
Email: <asp:TextBox ID="txtEmail" runat="server Text="<%# Eval("Email") %>"/><br>
<asp:LinkButton ID="lbtnUpdateContact" CommandArgument='<%# Eval("ContactID") %>' CommandName="UpdateContact" runat="server" >Update</asp:LinkButton>
</div>
</asp:Repeater
and code for ItemCommand:
switch(e.CommandName)
{
case "Edit":
//make editTemplate div visible
HtmlGenericControl divEditContact = (HtmlGenericControl)e.Item.FindControl ("divEditContact");
divEditContact.Visible = true;
break;
case "Update":
Employee updateEmployee = new Employee
{
employeeName = txtName.Text:
employeeEmail = txtEmail.Text:
}
updateEmployee = API.UpdateEmployee(updateEmployee);
//display lblUpdateConfirm visible to True
// so user sees this confirm messge in the newly updated ItemTemplate
}
How can I access my lblUpdateConfirm and turn its Text state to visible from inside the ItemCommand, so that when the user sees the newly updated ITemTemplate, the label is showing the "Update Confirmed" message?
VB:
CType(e.Item.FindControl("lblUpdateConfirm"), Label).Visible = True;
C #:
Label lblToMakeVisible = (Label)e.Item.FindControl("lblUpdateConfirm");
lblToMakeVisible.Visible = True;