Expanding gridview's row - c#

One of gridview's column is a "Content" column that can have few lines of text (it can be literal, textbox or label ).
In "default" mode i want it to show only the first line and a link button: "(more)" or "(read)".
Clicking on this link should expand the column and display full content.
What is the best way to do this?

Selecting first 10 characters of content text and using it as your link's text is better aproach. This will reduce size of data that retrieved from database like that :
SELECT ContentId, SUBSTRING(Content, 0, 10) AS Content
FROM ContentTable;
Then you can use template column for this column that includes a label and a link. Lbel for the description text, link for the details.
<asp:TemplateColumn>
<ItemTemplate>
<asp:Label
Text='<%# Eval("Content") %>'
runat="server"/>
<a href='<%# Eval("ContentId", "contentdetails.aspx?id={0}") %>'>More</a>
</ItemTemplate>
</asp:TemplateColumn>

This will help you.
http://www.asp.net/community/control-gallery/Item.aspx?i=1465

try this. http://mosesofegypt.net/post/BuildingjQueryAndASPNetAJAXEnabledControlsjQueryCollapsiblePanelExtenderPart2.aspx

Use the power of CSS!
Place this inside your gridview row. It will naturally push out the row to the height of your content, or the amount of rows required.
<div class="toggle">
<div class="toggle-header">
Toggle!
</div>
<div class="toggle-height">
<div class="toggle-transform">
<p>2nd line of text</p>
<p>3rd line</p>
<p>4th line</p>
<p>etc</p>
</div>
</div>
</div>
And use this CSS...
body {
font-family: sans-serif;
}
.toggle {
position: relative;
border: 2px solid #333;
border-radius: 3px;
margin: 5px;
width: 200px;
}
.toggle-header {
margin: 0;
padding: 10px;
background-color: #333;
color: white;
text-align: center;
cursor: pointer;
}
.toggle-height {
background-color: tomato;
overflow: hidden;
transition: max-height .6s ease;
max-height: 0;
}
.toggle:hover .toggle-height {
max-height: 1000px;
}
.toggle-transform {
padding: 5px;
color: white;
transition: transform .4s ease;
transform: translateY(-100%);
}
.toggle:hover .toggle-transform {
transform: translateY(0);
}
You may want to disguise the "toggle" with a textbox of your "(more)" line to expand the rest.
Let us know if it worked.

Related

How to select dropdown item with same data-testid

Im trying to get selenium to click an option in a dropdown. There are several options and it looks like the only unique thing about them is the link text. They all have 'data-testid' and they are all the same.
Anyone see a way to click a specific choice within the dropdown?
Here are a few examples of options within the dropdown: (App installs and Lead Generation)
<li class="" data-testid="ads-mini-grouped-objective-selector-option" style=""><div aria-checked="false" aria-disabled="false" class="_2wpb _3v8w" data-testid="SUISelectorOption/container" role="menuitem" style="letter-spacing: normal; color: rgb(75, 79, 86); font-size: 12px; font-weight: normal; font-family: Arial, sans-serif; line-height: 16px; padding: 6px 24px 6px 32px;" tabindex="-1"><span class="_27_z _4s-j" style="margin-left: 0px; margin-right: 8px;"></span><div class="_3leq"><span>App installs</span></div></div></li>
<li class="" data-testid="ads-mini-grouped-objective-selector-option" style="background-color: rgba(29, 33, 41, 0.08);"><div aria-checked="false" aria-disabled="false" class="_2wpb _3v8w" data-testid="SUISelectorOption/container" role="menuitem" style="letter-spacing: normal; color: rgb(75, 79, 86); font-size: 12px; font-weight: normal; font-family: Arial, sans-serif; line-height: 16px; padding: 6px 24px 6px 32px;" tabindex="-1"><span class="_27_z _5da8" style="margin-left: 0px; margin-right: 8px;"></span><div class="_3leq"><span>Lead generation</span></div></div></li>
I have tried to select by link text but that did not work.
To click an option from the Dropdown you can write a function as clickOption() as follows :
public void clickOption(String option)
{
driver.FindElement(By.XPath("//li[#data-testid='ads-mini-grouped-objective-selector-option']//span[.='" + option + "']")).Click();
}
Now, from your main() or #Test annotation Class, call the function clickOption() method with the option which you want to select as follows :
clickOption("App installs");
//or
clickOption("Lead generation");
You can use XPath to select li element by attribute data-testid and inner text :
//li[#data-testid='ads-mini-grouped-objective-selector-option' and .='Lead generation']
driver.findElement(By.xpath("(//li[#data-testid='ads-mini-grouped-objective-selector-option'])[2]")).click();
Try this xpath to click second data with same data-testid:
har07 answer is a good answer,
you can also try this as an option
//*[text()='App installs']/parent::div/parent::div/parent::li
Because not all the html is given, this is the only option i can get

ASP fixed Header

I have a GridView in a div on my HTML-Code like this:
<div class="container" style="width: 80%; height: 800px; overflow: scroll">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" PageSize="40" AllowSorting="True"
AutoGenerateSelectButton="True" EnableModelValidation="False" OnPageIndexChanging="GridView1_SelectedIndexChanged"
AutoGenerateColumns="false" OnSorting="GridView1_Sorting" CssClass="mydatagrid"
PagerStyle-CssClass="pager" HeaderStyle-CssClass="headerGrida1" RowStyle-CssClass="rows"
ShowHeaderWhenEmpty="true" Font-Size="X-Small" ForeColor="Black">
The div makes it already scrollable but I also need a fixed Header of the Grid. What I tried with CSS doesnt work out...
I tried thi for the container:
.container
{
overflow: scroll;
}
.container table th
{
position: relative;
}
.container table tbody
{
overflow: hidden;
}
</style>
And this with the Gird:
.headerGrida1
{
background-color: #4a708b;
font-family: Calibri;
color: White;
border: none 0px transparent;
height: 25px;
text-align: center;
font-size: 16px;
position: relative;
}
But nothing seems to work...
Below is the good solution that will fixed header with vertical and horizontal scroll bars
http://www.dotnetbull.com/2011/11/scrollable-gridview-with-fixed-headers.html
Isn't there a way to do t just with CSS?
That's what I get when switching Position=absolute or = fixed.
The only thing is that it has to be above the first row otherwise nobody would see the rwos anymore.
Maybe there is simple solution, too?
Another Problem is that he width of the header is now different to the columns

Dynamic text underlined by braces

I want to underline a word with a round brace. This should be part of a C# Text but if it is easier in CSS, no problem. My problem is that the length of the Word can vary, so the bow must by calculated for each word.
My first idea was using CSS box-shadow:
CSS:
#test {
font-size: 50px;
background: transparent;
border-radius: 70px;
height: 65px;
width: 90px;
box-shadow: 0px 6px 0px -2px #00F;
font-family: sans-serif;
}
HTML:
<div id="test">Hey</div>
Unfortunately due to the dynamic Text sizes I can't calculate them.
Is there a smarter approach to this problem?
You don't need to calculate the width if you use span tags instead.
CSS:
.test {
font-size: 50px;
background: transparent;
border-radius: 70px;
height: 65px;
box-shadow: 0px 6px 0px -2px #00F;
font-family: sans-serif;
}
HTML:
<span id="test" class="test">Hey</span><br/>
<span class="test">Hey this is longer</span>
Working Fiddle: http://jsfiddle.net/Ge8Q3/
I found a different approach.
Working fiddle: http://jsfiddle.net/6pEQA/1/
I used javascript and made the width dynamic:
textWidth function taken from here.
$.fn.textWidth = function(){
var self = $(this),
children = self.contents(),
calculator = $('<span style="white-space:nowrap;" />'),
width;
children.wrap(calculator);
width = children.parent().width(); // parent = the calculator wrapper
children.unwrap();
return width;
};
$(document).ready(function(){
$('#test').css('width',$('#test').textWidth());
});
It also works with h1, div or span. You can check my fiddle. Because it is using span elements to calculate width of the element.

CSS table properties

I am trying to set some styles for objects that are within a table but the problem is that the properties are not being applied to the actual objects.
the .tblData works fine but the label and textbox properties are supposed to be or any ASP.net label or textbox that appears within the table but the CSS doesnt get applied to them.
.tblData {
border: solid;
border-width: 1px;
height: 200px;
color: rgb(45,40,128);
background-color: white;
width: 100%;
border-radius:3px;
margin-top:3px;
}
/*Class for the labels*/
.tblData label {
width: 13%;
color:black;
border-radius:3px;
font-family:verdana;
border-radius:3px;
border-color:rgba(45,40,128,0.75);
border-width:1px;
}
/*Class for the data textboxes*/
.tblData textbox {
border-color: rgba(45,40,128,0.75);
border-width: 1px;
background-color:rgba(45,40,128,0.10);
font-family:Verdana;
border-radius:3px;
}
This is the HTML (can't show all of it because the table is massive):
<table id="tblAddress" class="tblData">
<tr>
<td class="auto-style3">
<asp:Label ID="lblACNO" runat="server" Text="ACNO" CssClass="Datalabelcolumn"></asp:Label></td>
<td class="auto-style2">
<asp:TextBox ID="txtACNO" runat="server" CssClass="autosuggest" Width="20%" ToolTip="This is a test tooltip"></asp:TextBox>
</td>
In ASP.Net, server tag<asp:Label> will be rendered as html <span>.
for <asp:TextBox> it is <input type='text'>
So please change your css selector
from
.tblData label {}
.tblData textbox{}
to
.tblData span{} or .tblData .Datalabelcolumn{}
.tblData input[type="text"]{} or .tblData .autosuggest {}
You are applying different css class to your Lable and TextBox inside your table (i.e Datalabelcolumn and autosuggest). So it will only apply those properties. Remove them and it will work. Or mention whatever style you need in your "Datalabelcolumn" and "autosuggest" css class for those controls.
add class="tblData" to td instead of table
basic demo
<td class="tblData">
<label>this is a label</label>
<textbox>this is textbox</textbox>
</td>

Speech bubble inside repeater

Above is an image of the rendered css when I changed the bg color of .speech_bubble_content to red. The bubble isn't displaying properly.
I am using the following code to retrieve data from a database and bind it to a repeater. I am also using css to display a speech bubble around what I want to display. I noticed that data is displayed when I place a label outisde of the div - and nothing is retrieved when the label is inside the div - in this case creation date is displayed, but story is omitted. Why is this happening? Thanks for your help. I believe this is caused by css.
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<div class="speech_bubble">
<b class="sb1"></b><b class="sb2"></b><b class="sb3"></b><b class="sb4"></b><b class="sb5"></b><b class="sb6"></b><b class="sb7"></b>
<div class="speech_bubble_content">
<p>
<asp:Label ID="story" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Story") %>'></asp:Label>
</p>
</div>
<b class="sb7"></b><b class="sb6"></b><b class="sb5"></b><b class="sb4"></b><b class="sb3"></b><b class="sb2"></b><b class="sb1"></b>
<em></em><span></span>
</div>
<asp:Label ID="user" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "CompanyRole") %>'></asp:Label> <asp:Label ID="date" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "CreationDate") %>'></asp:Label>
</ItemTemplate>
</asp:Repeater>
Here's the CSS:
.speech_bubble{
background: transparent;
margin:10px 0;
}
.speech_bubble_content{
display:block;
background:#fff;
border:3px solid #ddd;
border-width:0 3px;
}
.speech_bubble p{
padding:0.5em 0;
color:#000;
margin:0 15px;
}
.sb1, .sb2, .sb3, .sb4, .sb5, .sb6, .sb7{
display:block;
overflow:hidden;
font-size:0;
}
.sb1, .sb2, .sb3, .sb4, .sb5, .sb6{
height:1px;
}
.sb4, .sb5, .sb6, .sb7{
background:#fff;
border-left:1px solid #ddd;
border-right:1px solid #ddd;
}
.sb1 {margin:0 8px; background:#ddd;}
.sb2 {margin:0 6px; background:#ddd;}
.sb3 {margin:0 4px; background:#ddd;}
.sb4 {margin:0 3px; background:#fff; border-width:0 5px;}
.sb5 {margin:0 2px; background:#fff; border-width:0 4px;}
.sb6 {margin:0 2px; background:#fff; border-width:0 3px;}
.sb7 {margin:0 1px; background:#fff; border-width:0 3px; height:2px;}
.speech_bubble em{
display:block;
width:0;
height:0;
overflow:hidden;
border-top:12px solid #ddd;
border-left:12px dotted transparent;
border-right:12px dotted transparent;
margin-left:50px;
}
.speech_bubble span{
display:block;
width:0;
height:0;
overflow:hidden;
border-top:10px solid #fff;
border-left:10px dotted transparent;
border-right:10px dotted transparent;
margin-left:52px;
margin-top:-15px;
}
Yes do as rene suggest. View the source, HTML copy it and the CSS and save it to http://jsbin.com/ and send the Link back here so we can see the REAL html that .NET generates.
You might also just want to have
<%#DataBinder.Eval(Container.DataItem, "Story") %>
instead of using a asp:label as it will add unwanted HTML tags.

Categories