i am trying to vertically align the table present in the panel but i cant and when i apply style properties to the table it does not work ? means there would be no effect of style property on it as my code is given below,
<asp:Panel ID="Panel1" runat="server"
style="z-index:0;left:250px;position:absolute;top:160px; height: 160px; padding:10"
BackColor="Green" Width="300px">
<div style="width: 295px; height: 155px;" align= "center">
<table style="height: 48px; width: 187px; margin-left:0px; min-height:14px; min-width:55px; vertical-align:bottom" align="center" bgcolor="green" >
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="UserName" ForeColor="White"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label3" runat="server" Text="Password" ForeColor="White"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox2" textmode="Password" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label4" runat="server" ForeColor="White"></asp:Label>
</td>
<td>
<asp:Button ID="Button1" runat="server" Text="Login" onclick="Button1_Click" />
</td>
</tr>
</table>
</div>
</asp:Panel>
Hopes for your suggestions
Vertical alignment of some content within parent container is always tricky if you don't know the height of the content. Solution is to have a wrapper div in between parent & content elements. Then have outer container with "display:table" and wrapper div with "display:table-cell" aligned vertically in middle. See this fiddle for the illustration: http://jsfiddle.net/myXL3/3/
For complete information on this approach, see this excellent article: http://www.jakpsatweb.cz/css/css-vertical-center-solution.html
The problem here is that you have the table within a div element. Adding vertical-align:middle to the div's style should work. This assumes that the div is always "higher" than the table (as in your code snippet).
(Also, you have margins in your table's style - they should be removed to make sure they are not interfering with the vertical alignment)
Related
Here is my asp.net Repeater From within it there is a button. I want to get the value of lblFaulType in a string in code behind when i click Button1, How can I do that?I have tried many approaches but nothing working. Please give me your suggestions.
<asp:Repeater ID="RepterDetails" runat="server">
<HeaderTemplate>
<table style="border:1px solid #0000FF; width:500px" cellpadding="0">
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color:#EBEFF0">
<td>
<table style="background-color:#EBEFF0;border-top:1px dotted #df5015; width:500px" >
<tr>
<td >
<strong><asp:Label ID="Label18" runat="server" Text="Fault Category: " Font-Bold="true"/></strong>
<asp:Label ID="lblFaultType" runat="server" Text='<%#Eval("Fault Type") %>' Font-Bold="true"/>
</td>
<td >
<strong><asp:Label ID="Label19" runat="server" Text="Fault Description: " Font-Bold="true"/></strong>
<asp:Label ID="Label8" runat="server" Text='<%#Eval("Fault Description") %>' Font-Bold="true"/>
</td>
</tr>
<tr>
<td >
<strong><asp:Label ID="Label2" runat="server" Text="Building: " Font-Bold="true"/></strong>
<asp:Label ID="Label9" runat="server" Text='<%#Eval("Name") %>' Font-Bold="true"/>
</td>
<td >
<strong><asp:Label ID="Label3" runat="server" Text="Floor: " Font-Bold="true"/></strong>
<asp:Label ID="Label10" runat="server" Text='<%#Eval("FloorNo") %>' Font-Bold="true"/>
</td>
</tr>
<tr>
<td>
<strong><asp:Label ID="Label6" runat="server" Text="Room Number: " Font-Bold="true"/></strong>
<asp:Label ID="Label11" runat="server" Text='<%#Eval("RoomNumber") %>' Font-Bold="true"/>
</td>
</tr>
<tr>
<td ><strong><asp:Label ID="Label14" runat="server" Text="Created Time: " Font-Bold="true"/></strong> <asp:Label ID="lblUser" runat="server" Font-Bold="true" Text='<%#Eval("Time") %>'/></td>
<td ><strong><asp:Label ID="Label15" runat="server" Text="Created Date: " Font-Bold="true"/></strong><asp:Label ID="lblDate" runat="server" Font-Bold="true" Text='<%#Eval("Date") %>'/></td>
</tr>
<tr>
<td ><strong><asp:Label ID="Label16" runat="server" Text="Start Status: " Font-Bold="true"/></strong> <asp:Label ID="Label12" runat="server" Font-Bold="true" Text='<%#Eval("StartStatus") %>'/></td>
<td ><strong><asp:Label ID="Label17" runat="server" Text="Assign Status: " Font-Bold="true"/></strong> <asp:Label ID="Label13" runat="server" Font-Bold="true" Text='<%#Eval("AssignStatus") %>'/></td>
</tr>
</table>
</td>
</tr>
<tr>
<td >
<asp:TextBox ID="lblComment" runat="server" style="color:#000000; font-weight: bold;" placeholder="Describe the fault here" Text='<%#Eval("Comment") %>' TextMode="MultiLine" Columns="70" Rows="6" Enabled="false"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2" class="text-center"><asp:Button ID="Button1" runat="server" Text="Assing Fault" class="btn btn-success" OnClick="Button1_Click" /> </td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
We may need to see the CodeBehind for this page, and specifically the "Button1_Click" method (click event).
Now though, it appears as though you only have one of the labels with an ID of "lblFaultType" (maybe you misspelled that in your initial description. Each of the other labels all carry sequentially numbered IDs (e.g. ID="Label1", ID="Label2", ID="Label3", etc), and your ClickEvent (the Button1_Click method) will need to iterate through those items to know 'which' label you are attempting to obtain a value from.
Suggestion: It may be better to apply a ClickEvent on each of the particular labels since it will have the ID there with it (a JScript/JQuery solution).
This actually a GREAT question!
(in fact good interview question)
Why?
Because how.net works for a gridview, listview, or a repeater?
They are ALL very similar.
If one has failed to grasp the “most basic” event model in .net, then suggestions to use JavaScript, or all kinds of wild approaches will be suggested (and they would get a failing mark in answering this question).
When using data bound controls that repeat data, then you can set a special command to trigger the Itemcommand event.
The attribute setting is called “CommandName”.
There are built in commands – and the command you use is important. However, "just" setting command name to somthing of your liking is sufficient in most cases.
This will CAUSE the ItemCommand event will fire. And once that occures, then you have "itemIndex" to point to any given row in the repeater (or gridview, or listview, or form view - the list goes on!!!).
So, add this to your button:
<asp:Button ID="Button1" runat="server" Text="Assing Fault"
class="btn btn-success" OnClick="Button1_Click"
CommandName = "Select" CommandArgument = '<%#Eval("Fault Type") %>'/>
Now, the the ItemCommand event, you can do this:
Protected Sub RepterDetails_ItemCommand(source As Object, e As RepeaterCommandEventArgs) Handles Repeater1.ItemCommand
Debug.Print("item command")
Dim MyRow As RepeaterItem = e.Item
Dim h As Label = e.Item.FindControl("lblFaultType")
Debug.Print(h.Text)
End Sub
Of course, since we set the CommandArguemnt to pass the value we want, then of course you can also do this:
debug.print("Value of FaultType = " & e.CommandArgument)
So, be it a classic "data aware" control in .net? Well be it a listview, gridview, repeater, and MANY MORE, then use the built in "gift horse" features that of course expected this common need and solution.
And you can get the selected index into the repeater with this:
Debug.Print(e.Item.ItemIndex)
Thanks guys but i found the answer at https://youtu.be/Oltxy1sGIds
So i did it like this:
RepeaterItem item = (sender as Button).NamingContainer as RepeaterItem; string type = +(item.FindControl("lblFaultType") as Label).Text;
I am working on my first Mobile Site using bootstrap. I am trying to create a Listview that is responsive, I made some research and I need to select Layout= Flow but my issue is that this layout flows from top to bottom (one column). I need to be able to display it from left to right up to 4 items, but I can't make it work.
code
<asp:ListView ID="ProductsListView" DataSourceID="SqlDataSource1" runat="server" DataKeyNames="ID">
<LayoutTemplate >
<div ID="itemPlaceholderContainer" runat="server" style="">
<span runat="server" id="itemPlaceholder" />
</div>
<div style="">
</div>
</LayoutTemplate>
<ItemTemplate>
<span style="">ID:
<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
</span>
</ItemTemplate>
</asp:ListView>
It looks like you are having the same problem as this user.
horizontal list view in asp.net
The LayoutTemplate contains a block level element (the div). This means that the ItemTemplate will be wrapped in the div which will take up the full available width.
You should be able to just remove div from the LayoutTemplate, make it a span, or make it a table like in the Selected Answer of the post I linked from #mshsayem
If you just want to show the images in a single row, you can just put
them in the columns of a single row. Try rewriting the listview markup
as follows (move table,tr markups into LayoutTemplate):
<asp:ListView runat="server" ID="PageHorizon">
<LayoutTemplate>
<table>
<tr>
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<td>
<img src='<%#Eval("ImagePath")%>' alt="Single Image"
width="64px" height="64px" />
</td>
</ItemTemplate>
</asp:ListView>
The script below displays the Listview item with layout = flow horizontally and it is responsive. I hope someone find it useful.
<div style=" text-align: center;">
<!-- start listview-->
<asp:ListView ID="ListView1" runat="server" DataKeyNames="ID" DataSourceID="SqlDataSource1">
<LayoutTemplate >
<div ID="itemPlaceholderContainer" runat="server" >
<span runat="server" id="itemPlaceholder" />
</div>
</LayoutTemplate>
<EmptyDataTemplate>
<span>No data was returned.</span>
</EmptyDataTemplate>
<ItemTemplate>
<table style="display: inline-block;" >
<tr >
<td colspan="3">
<asp:Image ID="Image1" runat="server" Height="200px"
ImageUrl='<%# Eval("Picture") %>' Width="150px" />
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
<span style="background-color: #FFFBD6;color: #333333;">
<asp:Label ID="OrderOfferNameLabel" runat="server"
Text='<%# Eval("WHATEVER") %>'></asp:Label>
</span>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
<span style="background-color: #FFFBD6;color: #333333;">
<asp:Label ID="ProductNameLabel" runat="server"
Text='<%# Eval("WHATEVER") %>'></asp:Label>
</span>
</td>
<td>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Button ID="Button1" runat="server" Height="44px"
style="height: 26px; width: 56px" Text="Button" Width="380px" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:ListView>
</div>
I have a Listview and one of the columns is called id_Number.
Is it possible to redirect to another page, if user clicks on one of the rows?
For example if id_Number is 4, than page should be redirected to ~/Page.aspx?id=4.
Code:
<asp:ListView ID="ListView1" runat="server"
DataKeyNames="id_Number" >
<EmptyDataTemplate>
<table id="Table1" runat="server" style="">
<tr>
<td>
No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<tr style="font-family: Arial; color: #FFFFFF" onMouseOver="this.bgColor='#219DD0';" onMouseOut="this.bgColor='#252526';">
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("id_Number") %>' />
</td>
<td>
<asp:Label ID="TextLabel" runat="server" Text='<%# Eval("Text") %>' />
</td>
<td>
<asp:Label ID="DateLabel" runat="server" Text='<%# Eval("Date") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table id="Table2" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table ID="itemPlaceholderContainer" runat="server" border="0" style="">
<tr id="Tr2" runat="server" style="">
<th id="Th1" runat="server">
Name</th>
<th id="Th2" runat="server">
Text</th>
<th id="Th3" runat="server">
Date</th>
</tr>
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
You can add an HTML link or a JavaScript into the ItemTemplate of your ListView pretty easily:
The "columns" are just HTML columns; in the ItemTemplate, you have access to all of your data, including id_number, so you can use it anywhere in the HTML, not just inside a column.
Since you wan the whole row to be clickable, I'd use a JavaScript function on the onClick event of the HTML table row <TR> element. You already have 2 events (onMouseOver, onMouseOut), with JavaScript in them, so this would just be one more...
A JavaScript redirect utilizes window.location.href which will redirect in the same window, assuming that's what you want (as opposed to a new window, etc.):
<ItemTemplate>
<tr style="font-family: Arial; color: #FFFFFF"
onMouseOver="this.bgColor='#219DD0';"
onMouseOut="this.bgColor='#252526';"
onClick="window.location.href = 'some/path/Page.aspx?id=<%# Eval("id_Number") %>';"
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("id_Number") %>' />
</td>
<td>
<asp:Label ID="TextLabel" runat="server" Text='<%# Eval("Text") %>' />
</td>
<td>
<asp:Label ID="DateLabel" runat="server" Text='<%# Eval("Date") %>' />
</td>
</tr>
</ItemTemplate>
One thing to note is for the path of Page.aspx, you have to use a relative path.
~/page.aspx?id=
Is a .net path that gets compiled into the full relative path to that page.
However, bacause your ItemTemplate contains HTML, you'd need the full (relative) path to Page.aspx in there.
So instead it should be (just an example):
/some/path/page.aspx?id= <-- page.aspx lives on http://www.yoursite.com/some/path/page.aspx
/page.aspx?id= <-- page.aspx lives on root, http://www.yoursite.com/page.aspx
Alternately you can use
onClick="window.location.href = '<% System.Web.VirtualPathUtility.ToAbsolute("~/Page.Aspx?ID=" + Eval("id_number")); %>';"
I have the following Repeater and I am trying to add a divider (dotted line or similar) after each row but the style is getting messed up, what am I doing wrong?
Code:
<ItemTemplate>
<table id="tableItem" runat="server">
<tr>
<td style="width:400px;">
<%-- <asp:Label ID="lblEmployeeId" runat="server" Text='<%#Eval("EmployeeId") %>' ></asp:Label>--%>
<asp:HiddenField ID="HdnEmployeeId" runat="server" Value='<%#Eval("EmployeeId") %>' />
<asp:Literal Text="" runat="server" ID="LiteralUser" ></asp:Literal>
</td>
</tr>
<tr>
<td style="width: 100px;">
<asp:HiddenField ID="HdnRequestId" runat="server" Value='<%#Eval("id") %>' />
<asp:Label ID="lblDate" runat="server" Text='<%#Eval("Date", "{0:dd/M/yyyy}") %>'></asp:Label>
</td>
<td style="width: 80px;">
<asp:Label ID="lblHours" runat="server" Text='<%#Eval("Hours") %>'></asp:Label>
</td>
<td style="width: 50px; font-size:10px;">
<asp:Label ID="lblPeriod" runat="server" Text='<%#Eval("AMorPM") %>'></asp:Label>
</td>
<td style="width: 850px; font-size:10px;">
<asp:Label ID="lblNote" runat="server" Text='<%#Eval("Note") %>'></asp:Label>
</td>
<td style="50px">
<asp:RadioButtonList ID="rbtVerified" runat="server" >
<asp:ListItem Value="1">Accept</asp:ListItem>
<asp:ListItem Value="2">Reject</asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:TextBox ID="txtNotes" runat="server" ></asp:TextBox>
</td>
</tr>
<tr>
<td style="width:900px;">
<asp:Label ID="lblBreak" runat="server" Text="------------------------------------------------------------------------------"></asp:Label>
</td>
</tr>
</table>
By Style getting messed up I mean the dotted line is being displayed only under the first column (lblDate) and the lblDate width is expanded.
you can use a separator template and inside it insert <hr />
<asp:Repeater runat="server" ID="rp">
<SeparatorTemplate>
<hr />
</SeparatorTemplate>
</asp:Repeater>
Since your middle TR has 6 TDs, add attribute colspan="6" to TD in the 1st and the last row
<td colspan="6" style="width:400px;">
...
<td colspan="6" style="width:900px;">
By the way, you're specifying different width for the 1st and the last TD and both are less than summary width of inner TDs, so those styles won't have any effect and can be removed.
Another approach would be to spit out a div at the very end of your template and change its border to dotted. I tend to use this approach quiet often as it gives me the ability to easily add space between each item by targeting the div and adding margin around it.
So something like this:
<ItemTemplate>
...
<div class="divider"></div>
</ItemTemplate>
.divider
{
border: 1px dotted #C5C5C5;
height: 5px;
margin-bottom: 15px;
width: 100%;
}
Another way to do that just with with css flex
<div style="display: flex; align-items: center">
<div>My awesome article price:</div>
<div style="flex:1;border-bottom: dotted 1px #eee"></div>
<div>10.00€</div>
</div>
I have a list view on a page and am trying emulate the toggling effect of a tree view. When first bound the detail elements (LBL_ActionTitle, LBL_Action, LBL_UrlTitle, LBL_Url) are set to visibility = false. I would like to have the click event of the element (LB_ExpandCollapse) toggle the visibility of detail elements directly related to it. IE not all the elements of that type on the page. I am not sure how to accomplish this, or if it can be done, and was hoping that someone could point me in the right direction. Here is the control for reference.
<div id="logContainer">
<asp:ListView ID=LV_Logs runat="server">
<LayoutTemplate>
<table border="0" cellpadding="0" cellspacing="0" style="width:100%">
<tr>
<td></td>
<td style="width:85%" />
</tr>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<hr />
<asp:LinkButton ID="LB_ExpandCollapse" runat="server" CausesValidation="false" OnClick="expandCollapse_Click">+</asp:LinkButton>
<asp:Label ID="LBL_MessageType" runat="server" Text='<%# Eval("messageType") %>'></asp:Label>
<hr />
</td>
<td style="text-align: right">
<hr />
<asp:Label ID="LBL_Message" runat="server" Text='<%# Eval("messageTime") %>'></asp:Label>
<hr />
</td>
</tr>
<tr style="text-align: left">
<td style="padding-left: 65px">
<asp:Label ID="LBL_ActionTitle" Visibility="false" runat="server" Text="User Action:"></asp:Label>
</td>
<td style="padding-left: 10px">
<asp:Label ID="LBL_Action" Visibility="false" runat="server" Text='<%# Eval("action") %>'></asp:Label>
</td>
</tr>
<tr style="text-align: left">
<td style="padding-left: 65px">
<asp:Label ID="LBL_UrlTitle" Visibility="false" runat="server" Text="URL:"></asp:Label>
</td>
<td style="padding-left: 10px">
<asp:Label ID="LBL_Url" runat="server" Visibility="false" Text='<%# Eval("url") %>'></asp:Label>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<asp:DataPager ID="DataPagerProducts" runat="server" PagedControlID="LV_Logs"
PageSize="20" OnPreRender="DataPagerProducts_PreRender">
<Fields>
<asp:NextPreviousPagerField ShowFirstPageButton="True" ShowNextPageButton="False" />
<asp:NumericPagerField />
<asp:NextPreviousPagerField ShowLastPageButton="True" ShowPreviousPageButton="False" />
</Fields>
</asp:DataPager>
I suggest you put the ID of the record as an ID on the TR containing the fields you want toggled. Then in your expandCollapseClick also pass the ID, so that you can set the row's style to display:block. Of course this assumes that all the rows start out at display:none. ie.
<tr id='<%# Eval("recordId") %>' style='display:none'>
and then in Javascript (pseudo-code)
function expandCollapseClick(row)
{
document.getElementById(row).style.display = 'block';
}
Then change your button to execute client-side as in:
<button onclick='expandCollapse(<%# Eval("recordId") %>)'>+</button>
This will call the code to display the row, passing in the id of the correct row. Of course this assumes that the table is fully populated when the page is retrieved and all you want to do is hide/show detail.