Here is my screen:
Here is my code for the ItemTemplate in the Repeater:
<ItemTemplate>
<div style="float: left; overflow: hidden; display: inline-block; border-style: solid; margin: 5px; background-color: Silver">
<div style="text-align:center">
<asp:Label ID="lblImage" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "image") %>'></asp:Label>
</div>
<asp:Image runat="server" ID="image1" Width="250px" Height="250px" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "url") %>' />
<div style="text-align: center;">
<asp:Button runat="server" ID="btnNew" Text="New" />
<asp:Button runat="server" ID="btnOriginal" Text="Original" />
</div>
</div>
The Repeater uses a dataset in my program to populate the ItemTemplate's label and image controls. There's another field in my dataset called graphicID. I'd like to, somehow, pass the value in that field to the 'Original' button, so that if a user presses that button, that particular graphicID is passed into the click event. Does this make sense?
For instance, the second image is Captain Harlock. The graphicID for this image is 93. If the user presses the Original button under Captain Harlock, I want to pass 93 to the onClick event. I'm not sure how to do this, though. If someone could point me in the right direction, I'd greatly appreciate it!
<div style="text-align: center;">
<asp:Button runat="server" ID="btnNew" Text="New" />
<asp:Button runat="server" CommandName="cmd_original" CommandArgument="name of field which you want to access" ID="btnOriginal" Text="Original" />
</div>
EDIT
In repeater control
you have to add an event as below:
onitemcommand="Repeater1_ItemCommand"
In code behind
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "cmd_original")
{
Int32 id = Convert.ToInt32(e.CommandArgument);
}
}
Related
I am trying to pass value from listbox in ModalPopupExtender to textbox in gridview footer row textbox in parent page. In the current scenario the application breaks on button click. I have tried using Javascript,juery and C# but all results in same. Does somebody has any suggestion on how to do this? Below is my code:
I am trying to Pass value from listbox "lst_PdfViewers" to gridview textbox "AddSupplierName" on Done button click event "btnSupplierDone_Click"
Gridview Footer row:
<FooterTemplate>
<asp:TextBox ID="AddSupplierName" runat="server" >
</asp:TextBox>
<asp:ImageButton ID="btnlnkSupplier" runat="server" ImageUrl="../images/openDialog20.gif"
onclick ="lnkSupplier_Click" />
</FooterTemplate>
ModalPopupExtender:
<act:ModalPopupExtender ID="ModalPopupExtenderSupplier" CancelControlID="SupplierPopupCancel" TargetControlID="Sample"
PopupControlID="Pnl_Pdfviewers" runat="server" Enabled="true"> </act:ModalPopupExtender>
Popup Div having Listbox and Done Button:
<div id="Pnl_Pdfviewers" style="display: none; width: 500px !important; height: 400px !important;"
class="popupConfirmation">
<div class="popup_Titlebar" id="div3">
<div class="TitlebarRight" onclick="$get('SupplierPopupCancel').click();">
</div>
</div>
<div id="div4" class="popup_Container popup_Body" style="overflow: auto; height: 125px;">
<table id="Table2" class="table" style="table-layout: fixed; width: 450px;">
<tr>
<td style="word-wrap: break-word;">
<asp:ListBox ID="lst_PdfViewers" Width="250px" runat="server" OnSelectedIndexChanged="lst_PdfViewers_SelectedIndexChanged"></asp:ListBox>
</td>
</tr>
<tr>
<td style="word-wrap: break-word;">
<%--<input type="button" id="btn1" OnClick="btnSupplierDone_Click" value="Client Button" />--%>
<asp:Button ID="BtnSupplierDone" runat="server" CausesValidation="False" OnClick="btnSupplierDone_Click" Text="Done" />
</td>
</tr>
</table>
</div>
</div>
.cs btnSupplierDone_Click event
protected void btnSupplierDone_Click(object sender, EventArgs e)
{
if (lst_PdfViewers.SelectedValue != null)
{
var footerRow = gvPITransactionData.FooterRow;
var txtAddSupplierName = (TextBox)footerRow.FindControl("AddSupplierName");
lst_PdfViewers.SelectedValue = txtAddSupplierName.Text;
// ModalPopupExtenderSupplier.Hide();
}
}
I get correct results when I switch these controls. You have:
lst_PdfViewers.SelectedValue = txtAddSupplierName.Text;
But if you want the value of lst_PdfViewers in the Footer row use:
txtAddSupplierName.Text = lst_PdfViewers.SelectedValue;
I am creating a social network site, I cant seem to get the "LinkEmail" in the code behind, I need this to function as I then use it to post to the database.
The LinkEmail is being dynamically generated in the first repeater, I need a way to grab that value.
at the moment I am getting this error in the browser:
Compiler Error Message: CS0103: The name 'LinkEmail' does not exist in the current context
this is aspx code
<asp:Repeater runat="server" ID="Repeater1">
<ItemTemplate>
<div style="border-top: thin none #91ADDD; border-bottom: thin none #91ADDD; padding: 10px; width: 548px; margin-top: 10px; right: 10px; left: 10px; border-left-width: thin; margin-left: 15px; background-color: #F6F6F6; border-left-color: #91ADDD; border-right-color: #91ADDD;">
<br />
<div style="width: 58px; height: 40px">
<asp:Image ID="Image2" runat="server" Height="59px" ImageAlign="Top" ImageUrl="~/Profile/Image/Default.png" Width="55px" />
</div>
<div style="width: 307px; margin-left: 65px; margin-top: -60px">
<asp:Label ID="Label6" runat="server" Font-Bold="True" Font-Names="Arial" ForeColor="#3b5998"><%#Eval("YourName") %> </asp:Label>
</div>
<div id="status" style=" width: 461px; margin-left: 78px; margin-top: 11px;"> <asp:Label ID="Label7" runat="server" Font-Italic="False" ForeColor="Black" Font-Size="Medium"><%#Eval("Birthday") %> </asp:Label>
<asp:LinkButton ID="LinkEmail" runat="server" OnClick="lbl_Click"><%#Eval("Email") %></asp:LinkButton>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</div>
</ItemTemplate>
Could you tell me How to get LinkButton ID to my code behind file?
You can find it in ItemCommand event like this:-
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
LinkButton LinkEmail= e.Item.FindControl("LinkEmail") as LinkButton ;
}
You need to associate this event handler with your control like this:-
<asp:Repeater runat="server" ID="Repeater1" OnItemCommand="Repeater1_ItemCommand">
foreach(RepeaterItem item in Repeater1.Items)
{
LinkButton LinkEmail=(LinkButton)item.FindControl("LinkEmail");
//Do here what ever you want
}
using Sender
You get the RepeaterItem by casting the Link button's NamingContainer. Then you can use FindControl to get the reference to your Other Controls.
protected void lbl_Click(object sender,EventArgs e)
{
LinkButton LinkEmail=(LinkButton) sender;
var RepeaterRow=(RepeaterItem)LinkEmail.NamingContainer;
//find your other control like this
Label Label6=(Label) RepeaterRow.FindControl("controlname")
//Do here what ever you want
}
Or
You can use ItemCommand as Suggested by Rahul singh
I have the following front end code:
<asp:Panel ID="pn_TSAdmin" runat="server" GroupingText="Timesheet Admin" CssClass="Dashboard_Panel" Visible="false">
<div id="dv_ProjectSelect" runat="server" style="width:500px;" >
<asp:Label ID="lb_Project" runat="server" Text="Project:" CssClass="Label" />
<asp:DropDownList ID="ddl_Project" runat="server" CssClass="Label" />
<asp:ImageButton ID="ibt_AddProject" runat="server" ImageAlign="AbsBottom" ImageUrl="~/Images/add.png" CssClass="ibt_22" OnClick="Click_AddProject" />
<asp:ImageButton ID="ibt_ProjectStatus" runat="server" ImageAlign="AbsBottom" ImageUrl="~/Images/power.png" CssClass="ibt_22" OnClick="Click_SwitchProject" />
</div>
<div id="dv_ProjectAdd" runat="server" style="width:500px;" visible="false">
<asp:Label ID="lb_NewProject" runat="server" CssClass="Label" Text="Project Name: " />
<asp:TextBox ID="txt_NewProject" runat="server" CssClass="Label" />
<asp:ImageButton ID="ibt_SubmitNewProject" runat="server" ImageUrl="~/Images/go.png" CssClass="ibt_22" OnClick="Click_SubmitProject" />
<asp:ImageButton ID="ibt_CancelNewProject" runat="server" ImageUrl="~/Images/cancel.png" CssClass="ibt_22" OnClick="Click_CancelAddProject" />
</div>
</asp:Panel>
Code behind for ibt_AddProject:
protected void Click_AddProject (object sender, EventArgs e)
{
dv_ProjectSelect.Visible = false;
dv_ProjectAdd.Visible = true;
}
Which is using the following CSS Classes:
.Label
{
width:200px;
margin:10px auto 10px 20px;
}
.ibt_22
{
width:22px;
height:22px;
margin: 10px auto 10px 10px;
}
dv_ProjectSelect shows up as expected with the items lining up perfectly.
However when I click ibt_AddProject the items aren't showing correctly in dv_ProjectAdd as per the following picpaste showing the screen transition(http://picpaste.com/DumbCSS-173MxC30.jpg)
I've seen things mentioned about adding cursor:text and also z-index:999 but nonbe of which have helped with this issue.
Any idea why this is happening and how I could go about resolving it so it looks correct.
I have a repeater which i am trying to load after the page has loaded and have stumbled across the PreRender event. I have everything set up but the content of the repeater is not showing - the weird thing is that when i inspect the html, the code is there, just not displaying in the browser.
<asp:updatepanel id="panel1" runat="server" updatemode="Conditional" onprerender="upUpdatePanel_PreRender">
<contenttemplate>
<asp:repeater runat="server" id="mainContentRptr" onitemdatabound="bindDepts">
<headertemplate>
<div id="products-tabs-content" class="row tab-content">
</headertemplate>
<itemtemplate>
<div class="tab-pane" id='<%# eval("dept_id") %>
'> <asp:repeater runat="server" id="prodRepeater" onitemcommand="itemToCart">
<headertemplate>
.... </headertemplate>
<itemtemplate>
.... <asp:repeater runat="server" id="condRptr">
<headertemplate>
.... </headertemplate>
<itemtemplate>
.... </itemtemplate>
<footertemplate></footertemplate>
</asp:repeater>
</itemtemplate>
<footertemplate>
</div>
</footertemplate>
</asp:repeater>
</div>
<!-- End .tab-pane -->
</itemtemplate>
<footertemplate>
</footertemplate>
</asp:repeater>
</contenttemplate>
</asp:updatepanel>
As you can see a few nested repeaters... i also have my UpdateProgress control
<asp:UpdateProgress id="updateProgress" runat="server" AssociatedUpdatePanelID="panel1">
<ProgressTemplate>
<div style="position: relative; text-align: center; height: 100%; width: 100%; background-color: white; opacity: 0.7;margin:0 auto">
<asp:Image ID="imgUpdateProgress" runat="server" ImageUrl="images/loader.GIF" AlternateText="Loading ..." ToolTip="Loading ..." style="padding: 10px; position: relative; top: 45%;margin: 0 auto" />
<br/>
<span style="font-size: 16pt;font-weight: bold">Bulding your menu</span>
<br/>
<span>Please wait</span>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
and then the following to trigger the delayed load
<script language="javascript" type="text/javascript">
function pageLoad(sender, e) {
if (!e.get_isPartialLoad()) {
__doPostBack('<%= panel1.ClientID %>', 'aaaa');
}
}
</script>
and server side...
protected void upUpdatePanel_PreRender(object sender, EventArgs e)
{
if (Request["__EVENTTARGET"] == panel1.ClientID &&
Request.Form["__EVENTARGUMENT"] == "aaaa")
{
populateRepeaters(); //This has databind for each repeater
}
}
This works without the prerender but loading speeding will vary depending on data etc so i wanted to have it load after the page loaded.
Any help would be appreciated guys! :)
a repeater was sitting out of the updatepanel that controlled the visibility of everything above. it was populated in the prerender event but did not display. Ive moved it inside the panel and everyhting is now working
I have a listview control that is nested in the item template of another listview control that i'm trying to reference in codebehind using the .FindControl() method, but it keeps returning null. After get this to work, I'll need to reference a ComboBox inside of the inner listview. Here is where I am so far:
ListView lsvTickets
ItemTemplate
Listview lsvActions
ItemTemplate
ComboBox cboAssignees
I'm using the following code to attempt the reference in code behind:
var actions = (RadListView)lsvTickets.FindControl("lsvActions");
But this is returning null. I thought I would only have to do something like this to achieve the final desired result:
var assignees = (RadComboBox)lsvTickets.FindControl("lsvActions").FindControl("cboAssignees")
Can anyone help? What am I doing wrong here? Here's the full layout for those of you it would help:
<rad:RadListView runat="server" ID="lsvTickets">
<ItemTemplate>
<div id="divContainer" class="divContainer">
<div id="divTicketHeader" class="divTicketHeader">
<asp:Table runat="server" ID="tblTicketHead" Width="100%" CellSpacing="0" CellPadding="5" HorizontalAlign="Center">
<asp:TableRow HorizontalAlign="Center">
<asp:TableCell Width="25%">
<asp:Label ID="Label1" runat="server" Text='<%#Eval("Subject") %>' Font-Bold="true" />
</asp:TableCell><asp:TableCell Width="25%">
<asp:Label ID="Label2" runat="server" Text='<%#Eval("Status.Key") %>' />
</asp:TableCell><asp:TableCell Width="25%">
<asp:Label ID="Label3" runat="server" Text='<%#Eval("Ticket.Reported_By") %>' />
</asp:TableCell><asp:TableCell Width="25%">
<asp:Label ID="Label4" runat="server" Text='<%#Eval("DateOpened") %>' />
</asp:TableCell></asp:TableRow></asp:Table></div>
<div id="divTicketBody" class="divComments">
<rad:RadListView runat="server" ID="lsvActions" DataSource='<%#Eval("TicketActions") %>'>
<ItemTemplate>
<center>
<div id="divAddComment" style="width: 500px;">
<div id="divCommentControls" style="margin: 8px 0px 8px 0px;">
<rad:RadComboBox runat="server" ID="cboStatus" DataSource='<%#GetStatuses() %>' DataTextField="Status" DataValueField="ID" /> <rad:RadComboBox runat="server" ID="cboAssignTo" DataSource='<%#GetAssignees() %>' DataTextField="Key" DataValueField="Value" />
</div>
<rad:RadTextBox runat="server" ID="txtComment" TextMode="MultiLine" Width="500" Height="100" CssClass="commentBox" /><br />
<div style="height: 35px;">
<div style="float:left"><asp:CheckBox ID="cbMakeITTicket" runat="server" Text="Convert to IT Support Ticket" /></div>
<div style="float:right; margin: 3px 0 0 0; "><rad:RadButton runat="server" ID="btnSubmit" Text="Submit" CssClass="buttonTag" /></div>
</div>
</div>
</center>
<div id="divComment" class="divComment">
<asp:Table runat="server" ID="tblComment" CellPadding="5">
<asp:TableRow>
<asp:TableCell Width="15%" HorizontalAlign="Center">
<rad:RadBinaryImage runat="server" ID="imgCommenter" Width="50" Height="50" /><br />
<asp:Label ID="Label5" runat="server" Text="[action author]" CssClass="commenterText" /><br />
<asp:Label ID="Label6" runat="server" Text='<%#Eval("Action_Date", "{0:MMM d, yyy hh:mm}") %>'
CssClass="commenterText"/><br />
</asp:TableCell><asp:TableCell>
<asp:Label ID="Label7" runat="server" Text='<%#Eval("Description") %>' />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</div>
</ItemTemplate>
</rad:RadListView>
</div>
</div>
</ItemTemplate>
</rad:RadListView>
</asp:Content>
You're looking for a combobox in a control that potentially has many lines (thus rows of combobox instances ) - it doesn’t know which one you’re looking for.
Obviously I don’t know what you need to do to the combobox but you should look at
alternate approaches.
Take a look at using the OnItemDataBound event of lsvActions
Then add code such as …
protected void lsvActions_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
RadComboBox myCBO = (RadComboBox)item.FindControl("cboStatus")
myCBO.Visible = false;
}
}
...also, just a general tip, I usually find using OnNeedDataSource to load RadGrids and ListViews saves a lot of headaches.
Hope that helps.