How to add responsive behaviour to the asp:GridView - c#

I want the asp gridview to show responsive behaviour like the html table does with the no-more-table css style as
seen here http://bootsnipp.com/snippets/featured/no-more-tables-respsonsive-table.
Is there a way to achieve it.
I have tried one way before, which is to replace my gridview with the html table and apply no-more-table style from
code behind. But I don't want to do this as I want to all the features offered by the asp:GridView.

I have written custom css to achieve this feature. To use my code follow the below steps,
Step1: Enclose your GridView inside a section with Id as no-more-gridView
as below
<section id="no-more-gridView">
<asp:GridView..>
.
</asp:GridView>
</section>
Step2: Assign a data-title attribute to each of your cells from code behind (inside the RowDataBound function) like below,
e.Row.Cells[0].Attributes["data-title"] = "Col1Name";
e.Row.Cells[1].Attributes["data-title"] = "Col2Name";
e.Row.Cells[2].Attributes["data-title"] = "Col3Name";
.
.
Step3: Finally include my custom style given below. Use media query to apply the style at whatever screen size you wish it to come to effect and that should pretty much do the trick.
/* Author : Vinay
Description: Responsive GridView
*/
/* Force gridview to not be like gridview anymore */
#no-more-gridView table,
#no-more-gridView thead,
#no-more-gridView tbody,
#no-more-gridView th,
#no-more-gridView td,
#no-more-gridView tr {
display: block;
}
/* Hide table headers (but not display: none;, for accessibility) */
#no-more-gridView .table_column_head > * {
display:none;
}
#no-more-gridView tr { all: revert;border: 2px solid #ccc;height:auto !important;}
#no-more-gridView td {
/* Behave like a "row" */
border: none;
border-bottom: 1px solid #eee;
position: relative;
padding-left: 50%;
white-space: normal;
text-align:left;
padding-bottom: 1em;
}
#no-more-gridView td:before {
/* Now like a table header */
position: absolute;
/* Top/left values mimic padding */
left: 6px;
width: 45%;
padding-right: 10px;
white-space: nowrap;
text-align:left;
font-weight: bold;
}
/*
Label the data
*/
#no-more-gridView td:before { content: attr(data-title); }

Related

Add Css to dynamically created label and textbox

I am dynamically creating the label and textbox in my C# code and am having issues with css formatting. Since the label and textbox are generated separately adding css to it to float left and add padding has been a challenge. I am new to c# and would appreciate any help.
I tried adding the cssClass to both the text box and label but the formatting is off.
Here is my css:
.form-control{
margin-bottom:10px;
width:300px;
float:left;
}
.form-control-label{
display:block;
float:left;
}
I added the css class in the script side using
label.CssClass = "form-control-label";
textbox.CssClass = "form-control"
Here is the output and expected result
Not sure about the text alignment that you expect for the Labels, but you can try the following style classes:
.form-control
{
float: left;
width: 300px;
}
.form-control-label
{
clear: left;
float: left;
width: 120px;
text-align: left;
}
If you prefer the Label texts to be right aligned, you can change the style for:
.form-control-label
{
clear: left;
float: left;
width: 120px;
text-align: right;
margin-right: 8px;
}

I want to get the ID of label using C# which is being created by jQuery on RunTime

First I will explain my scenario.
I have asp.net menu (dynamically created menu) and now I want to place push notification just like Facebook on my each menu option. I have designed it using CSS and put a label using jQuery.
if (res == "MenuIcons") {
$(this.parentElement).addClass('Notification');
var $label = $("<label ID=\"notificationlbl" + i + "\" style=\"position: absolute; margin-top: 2%; margin-left: -3.1%; margin-right:-3.3%; z-index: 99; color: white; font-size: 9px; font-family: Verdana; letter-spacing: -1px;\">").text('99');
$(this.parentElement.parentElement).append($label);
i++;
}
But I am totally confused that how to handle it using C# because I am unable to get the ID of the label created on run-time.
If you didn't understand please let me know and I will explain it more.
why don't you set a data attribute to each label, something like
var $label = $("<label data-element-type='notification' ID=\"notificationlbl" + i + "\" style=\"position: absolute; margin-top: 2%; margin-left: -3.1%; margin-right:-3.3%; z-index: 99; color: white; font-size: 9px; font-family: Verdana; letter-spacing: -1px;\">").text('99');
and then you can retrieve the whole collection with jQuery:
$("[data-element-type='notification']").each(function(){...});
Try adding runat="server" attribute in your label tag. You label tag id won't be available until runtime. So what you can do is search for the controllers by the id of your label. In code behind you can do as following
foreach(Contol c in this.Controls)
{
if(c.ID.contains("notificationlbl")
{
//your code
}
}

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.

TextBoxWatermarkExtender losing text after Response.Write

I am exporting an asp.net gridview to an excel sheet by Response.Write(*stringBuilder*), but when the button is clicked TextBoxesare losing TextBoxWatermarkExtender Text. Any idea? Thanks.
There is a problem in your CSS...
Work Like This..
.yourWatermarkedClass
{
color: Black;
font-family: Arial;
font-size: 11px;
border: solid 1px #a9a9a9;
text-indent:2px;
vertical-align:middle;
text-align:right;
background-image:url(../images/yourfileName.png);
background-repeat:no-repeat;
}

Expanding gridview's row

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.

Categories