I have a column which has has very long text i have to scroll to the end to see it. Can you help out with fitting the content in a fixed width cell
UI:
<asp:GridView ID="GridView1" runat="server" OnPageIndexChanging="PageIndexChanging_Click"
style="height: 166px; width: 217px; z-index: 1; left: 16px; top: 252px; position: absolute"
EmptyDataText="No Records Within this time Frame" >
<PagerSettings LastPageText="Last" />
</asp:GridView>
//Code Behind:
private void GetData()
{
string fromdata = txt_fromdate.Text;//" '2013-09-23 11:06:00.077'";
string todate = txt_todata.Text;//" '2013-09-23 11:28:25.163' ";
string querstring = "select * from gt_transaction_log where LogTimeStamp between" +"'"+ fromdata +"'"+ " and " +"'"+ todate + "'";
SqlDataAdapter adapter = new SqlDataAdapter(querstring, conn);
DataTable dt = new DataTable();
GridView1.AllowPaging = true;
if (TextBox1.Text != "" && int.Parse(TextBox1.Text) != 0)
{
GridView1.PageSize = int.Parse(TextBox1.Text);
}
else
{ GridView1.PageSize = 10; }
adapter.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
GridView doesn't have a Style property, but it does have a CssClass property you can use to control its CSS.
Create your CSS in a style block:
<style type="text/css">
.gridViewStyle {
height: 166px;
width: 217px;
z-index: 1;
left: 16px;
top: 252px;
position: absolute
}
</style>
Then in your GridView, it'll look like this:
<asp:GridView CssClass="gridViewStyle" <!-- additional GV fields here -->>
</asp:Gridview>
You can do it using CSS:
.Grid{
height: 166px; width: 217px; z-index: 1; left: 16px; top: 252px; position: absolute
}
.Grid tr td{
Width:100px;
}
<asp:GridView ID="GridView1" runat="server" CssClass="Grid" OnPageIndexChanging="PageIndexChanging_Click" EmptyDataText="No Records Within this time Frame"></asp:GridView>
OR
<asp:GridView ID="GridView1" runat="server" OnPageIndexChanging="PageIndexChanging_Click"
style="height: 166px; width: 217px; z-index: 1; left: 16px; top: 252px; position: absolute" AutoGenerateColumns="false"
EmptyDataText="No Records Within this time Frame" >
<Columns>
<asp:TemplateField HeaderText="Your column Name">
<ItemTemplate>
<%#Eval("EmployeeName") %>
</ItemTemplate>
<ItemStyle Width="50px" />
</asp:TemplateField>
.
.
.
.
Template fields for all columns of your datatable
</Columns>
<PagerSettings LastPageText="Last" />
</asp:GridView>
Related
<EditItemTemplate >
<li style="">username:
<asp:Label ID="usernameLabel1" runat="server" Text='<%# Eval("username") %>' />
<br />
password:
<asp:TextBox ID="passwordTextBox" runat="server" Text='<%# Bind("password") %>' />
<asp:Button ID="btnClick" OnClick="btnClick_Click" runat="server" Text="Hide/Show" />
<br />
email:
<asp:TextBox ID="emailTextBox" runat="server" Text='<%# Bind("email") %>' />
<br />
phone:
<asp:TextBox ID="phoneTextBox" runat="server" Text='<%# Bind("phone") %>' />
<br />
dob:
<asp:TextBox ID="dobTextBox" runat="server" Text='<%# Bind("dob") %>' />
<br />
gender:
<asp:TextBox ID="genderTextBox" runat="server" Text='<%# Bind("gender") %>' />
<br />
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
</li>
</EditItemTemplate>
For example, in Listview edit item template I want to add that button so how to access that button in code behind file as it is in Listview.
For displaying the Password, try the following Client-Side approach:
.wrapper {
display: inline-block;
position: relative;
}
.reveal-eye {
position: relative;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
position: absolute;
right: 1px;
top: 1px;
bottom: 1px;
z-index: 2;
width: 30px;
background: #fff url(https://dtzbdy9anri2p.cloudfront.net/cache/b55f544d09a0872a74b4427ce1fe18dd78418396/telerik/img/dist/reveal-password.png) 50% 50% no-repeat;
cursor: pointer;
visibility: hidden;
opacity: 0;
transition: opacity .2s ease 0s, visibility 0s linear .2s;
}
.reveal-eye.is-visible {
display: block;
visibility: visible;
opacity: 1;
transition: opacity .2s ease 0s, visibility 0s linear 0s;
}
<div class="wrapper">
<!--<asp:TextBox ID="passwordTextBox" runat="server" TextMode="Password" />-->
<input type="password" id="passwordTextBox" />
</div>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script>
function checkShowPasswordVisibility() {
var $revealEye = $(this).parent().find(".reveal-eye");
if (this.value) {
$revealEye.addClass("is-visible");
} else {
$revealEye.removeClass("is-visible");
}
}
$(document).ready(function () {
var txtPassword = document.getElementById('passwordTextBox');
var $revealEye = $('<span class="reveal-eye"></span>')
$(txtPassword).parent().append($revealEye);
$(txtPassword).on("keyup", checkShowPasswordVisibility)
$revealEye.on({
mousedown: function () { txtPassword.setAttribute("type", "text") },
mouseup: function () { txtPassword.setAttribute("type", "password") },
mouseout: function () { txtPassword.setAttribute("type", "password") }
});
})
</script>
Example originates from: ShowPassword button for RadTextBox with TextMode Password
However, if you would like to do it on server-side during a PostBack, here is an example showing how to access the TextBox when the Button Show/Hide is clicked:
protected void btnClick_Click(object sender, EventArgs e)
{
Button btn = sender as Button;
TextBox TextBox1 = btn.Parent.FindControl("TextBox1") as TextBox;
TextBox1.TextMode = TextBox1.TextMode == TextBoxMode.Password ? TextBoxMode.SingleLine : TextBoxMode.Password;
}
You are developing a website, for any user interface interaction, you are strongly recommended to use javascript,css to manipulate it. Only use code behind to process data.
function toggleShowPassword() {
var passwordTextBox = document.getElementById('passwordTextBox');
if(passwordTextBox.getAttribute('type')=='text'){
passwordTextBox.type='password';
}
else {
passwordTextBox.type='text';
}
}
.button {
line-height: 100%;
display: inline-block;
padding: 7px 15px;
background: #6eddff;
text-decoration: none;
color: black;
border-radius: 6px;
}
.button:active,
.button:hover{
background: #3d9dba;
color: white;
}
<input id='passwordTextBox' type='password' value='abcd' />
<a class='button' href='#' onclick='toggleShowPassword(); return false;'>
Show/Hide Password</a>
I have a Listview which consist of field called description(Which can be lengthy)
now i want to set read more and when user click on read more it should give full description in popup.
Code Designing :
<asp:ListView ID="listcourse" runat="server" >
<ItemTemplate>
<p >
<div>
<b>
<%# (Eval("Description").ToString().Length <=150)?Eval("Description").ToString(): Eval("Description").ToString().Substring(0, 150) + "...Readmore"%>
</b>
</div>
</p>
</ItemTemplate>
</asp:ListView>
C# Code :
public void bindList()
{
listcourse.DataSource = DB.Tbl_Categories_Master.Where(p => p.Deleted == true && p.Parent_Cat_id == 0);
listcourse.DataBind();
}
How can I ?
Since its MVC application and by default the template uses Bootstrap, I am giving you this solution.
Add this in your <script> tag.
$(function(){
$('div.popOverWrapper b').popover()
});
Also modify your HTMl div tag to have a class called popOverWrapper
<asp:ListView ID="listcourse" runat="server" >
<ItemTemplate>
<p>
<div class="popOverWrapper">
<b>
//....
</b>
</div>
</p>
</ItemTemplate>
</asp:ListView>
So technically what I am doing is to first mark my respective divs with a class name of my choice.. And later when the document is ready I will find this div and find the b tag within it and apply the bootstrap .popover() plugin
You can achieve this using Web service - Try this, It may help you.
---Web service code---
[WebMethod]
public string getFullDescription(int ID) {
string result = "";
using (SqlConnection con = new SqlConnection(#"Data Source=SANTOSH-PC\SQLEXPRESS;Initial Catalog=master;User ID=sa;Password=ssrana#317"))
{
SqlCommand com = new SqlCommand("select description from discriptionList where id="+ID+"", con);
con.Open();
SqlDataReader rdr = com.ExecuteReader();
if (rdr.Read())
{
result = Convert.ToString(rdr["description"]);
}
}
return result;
}
---.Aspx code---
<div>
<asp:ListView ID="lstView" runat="server" DataKeyNames="id" GroupItemCount="4" OnItemDataBound="lstView_ItemDataBound">
<EmptyDataTemplate>
<table>
<tr>
<td></td>
</tr>
</table>
</EmptyDataTemplate>
<GroupTemplate>
<tr id="ItemPlaceHolderContainer" runat="server">
<td id="ItemPlaceHolder" runat="server" style="text-align: center;"></td>
</tr>
</GroupTemplate>
<ItemTemplate>
<td id="Td1" runat="server" style="border: 2px solid #adbdc4; border-collapse: inherit; width: 20%">
<table style="width: 100%;">
<tr>
<td style="text-align: left; font-weight: bold; width: 100%; padding-left: 1px; height: 23px; vertical-align: top; font-size: 12px; color: black;">
<b style="text-decoration:underline">Title : <%#Eval("title") %></b>
<br />
<%#Eval("description") %>
<asp:LinkButton ID="lnkShowDescription" runat="server" Text="Read more.."></asp:LinkButton>
</td>
</tr>
</table>
</td>
</ItemTemplate>
<LayoutTemplate>
<table style="width: 100%; margin-left: 3px; background-color: #f2f2f2">
<tbody>
<tr>
<td>
<table id="GroupPlaceHolder" runat="server" style="width: 100%; height: 90%; text-align: center;">
<tr>
<td></td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
<tr>
<td></td>
<td colspan="5">
</td>
</tr>
</LayoutTemplate>
</asp:ListView>
</div>
---I am using Script Manager for calling webservice in my project---
<asp:ScriptManager ID="scripMngr" runat="server" >
<Services>
<asp:ServiceReference Path="~/MyServices.asmx" />
</Services>
</asp:ScriptManager>
----- This is the popup div ------
<div class="PopBackground" id="dvBackground" >
<div id="NewPopUp">
</div>
<br />
<div style="height:30px; text-align:right;">
<asp:Button ID="btnClose" runat="server" Text="Close" OnClientClick=" return hidePopup();" Style="background-color: #fb7b3a; border: 1px solid #fb7b3a" />
</div>
</div>
--- This is .cs code----
protected void Page_Load(object sender, EventArgs e)
{
bindView();
}
protected void bindView()
{
using (SqlDataAdapter da = new SqlDataAdapter("select id,title,SUBSTRING(description,1,40) as description from discriptionList", new SqlConnection(#"Data Source=SANTOSH-PC\SQLEXPRESS;Initial Catalog=master;User ID=sa;Password=ssrana#317")))
{
DataSet ds = new DataSet();
da.Fill(ds);
lstView.DataSource = ds;
lstView.DataBind();
}
}
protected void lstView_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
LinkButton lnkShowDescription = (LinkButton)(e.Item.FindControl("lnkShowDescription"));
int id=Convert.ToInt32(lstView.DataKeys[e.Item.DisplayIndex].Value);
lnkShowDescription.OnClientClick="return getFullDescription('"+id+"')";
}
}
--- This is popup style---
#NewPopUp {
position: fixed;
width: 300px;
height:auto;
max-height:650px;
top: 20%;
left: 50%;
margin-left: -255px;
margin-top: -150px;
border: 2px solid #adbdc4;
background-color: white;
text-align: left;
padding: 10px;
Z-index: 1000;
font-family: Verdana;
font-size: 10pt;
border-radius: 7px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
color: black;
filter: alpha(opacity=100);
opacity: 1;
-moz-opacity: 1;
display:none;
}
.PopBackground {
position: fixed;
vertical-align: middle;
text-align: center;
z-index: 999;
top: 0px;
left: 0px;
background-color: gray;
filter: alpha(opacity=70);
opacity: 0.95;
margin: 0px 0px 0px 0px;
width: 100%;
height: 100%;
min-height: 100%;
min-width: 100%;
display:none;
}
</style>
----- This is Script ------
<script type="text/javascript">
function getFullDescription(Id) {
MyServices.getFullDescription(Id, onSuccess, onError);
return false;
}
function onSuccess(result) {
document.getElementById('NewPopUp').style.display = 'block';
document.getElementById('dvBackground').style.display = 'block';
document.getElementById('NewPopUp').innerHTML = "Description : "+result;
}
function onError(error) {
document.getElementById('NewPopUp').style.display = 'block';
document.getElementById('dvBackground').style.display = 'block';
document.getElementById('NewPopUp').innerHTML = "Error : " + error;
}
function hidePopup() {
document.getElementById('NewPopUp').style.display = 'none';
document.getElementById('dvBackground').style.display = 'none';
return false;
}
</script>
I have an asp:file upload which I allowed users to select multiple files, I want it that if the user clicks on browse and pressed ok, I want the users to be able to preview the images selected (just like facebook image upload) how can i do this?
http://www.aspforums.net/Threads/165544/Display-Image-Preview-without-saving-file-physically-after-upload-in-ASPNet/
also refer this link...........
<asp:FileUpload ID="FileUpload1" runat="server"
style="top: 256px; left: 533px; position: absolute; height: 23px; width: 217px" ForeColor="White" />
<asp:Button ID="btnset" runat="server" Font-Bold="False" Font-Names="Times New Roman" Font-Size="Medium" style="top: 309px; left: 605px; position: absolute; height: 26px; width: 81px" Text="Set Photo " />
<asp:Image ID="Image2" runat="server" style="top: 66px; left: 568px; position: absolute; height: 152px; width: 136px" BorderColor="#CCCCFF" BorderStyle="Ridge" />
VB Code :
Protected Sub btnset_Click(ByVal sender As Object,
ByVal e As System.EventArgs) Handles btnset.Click
Image2.ImageUrl = FileUpload1.FileName
End Sub
I have a drop down list that shows all of the job numbers that are current. I need a text box to display the "name" equivalent of this number. The drop down list is based on a query to a separate table within the same database. The drop down list is:
<asp:DropDownList ID="dlRef" runat="server" DataSourceID="DataRef" DataTextField="Ref"
DataValueField="Ref" style="z-index: 1; left: 155px; top: 68px; position: absolute;
width: 115px; height: 29px; bottom: 254px;" AutoPostBack="True">
</asp:DropDownList>
What I need to do is have the text box tbADName to be associated with a datasource that uses a query such as this select Name from ActiveJobs where Ref = dlRef.DataValueField.
Is this possible or do I need to use another construct to display this information?
You can use the following function
onchange="showText(this.options[this.selectedIndex].text);"
Adding in your dropdown it will be
<asp:DropDownList ID="dlRef" runat="server" DataSourceID="DataRef" DataTextField="Ref"
DataValueField="Ref" style="z-index: 1; left: 155px; top: 68px; position: absolute;
width: 115px; height: 29px; bottom: 254px;" AutoPostBack="True"
onchange="showText(this.options[this.selectedIndex].text);">
</asp:DropDownList>
Create a function in java-script
function showText(value)
{
document.getElementById("textboxid").value=value
}
Edit 1
<head>
<title>DropDown</title>
<script type="text/javascript">
function chkind(){
var dropdown1 = document.getElementById('dlRef');
var textbox = document.getElementById('textbox');
var a = dropdown1.options[dropdown1.selectedIndex].text;
textbox.value = a;
}
}
</script>
</head>
<body>
<asp:DropDownList ID="dlRef" runat="server" DataSourceID="DataRef" DataTextField="Ref"
DataValueField="Ref" style="z-index: 1; left: 155px; top: 68px; position: absolute;
width: 115px; height: 29px; bottom: 254px;" AutoPostBack="True"
onchange="chkind()">
<option>Hi</option>
<option>Bye</option>
</select><br />
<asp:textbox id="textbox" type="text" runat="server" />
</body>
I'd use javascript to do this. Add an onchange=functionName() in your asp:DropDownList and handle the onchange in javascript to change the textbox text to the value in the dropdown list.
EDIT:
you could call the onchange event like this:
<asp:DropDownList ID="dlRef" runat="server" DataSourceID="DataRef" DataTextField="Ref"
DataValueField="Ref" style="z-index: 1; left: 155px; top: 68px; position: absolute;
width: 115px; height: 29px; bottom: 254px;" AutoPostBack="True" onchange="changeTextBox(this)">
</asp:DropDownList>
And your script like this:
<script>
function changeTextBox(data) {
document.getElementById("yourTextBoxId").value = data.value;
}
</script>
If you want the text displayed I'm guessing you should use the text property.
Note: As of html5 the script tags can be used like so without the type attribute.
I want to know how can i make my asp.net gridview scrollable vertically and horizontally without using CSS and html.
this is my code on how I make gridview scrollable
in CSS:
div#scroll
{
border: 1px solid #C0C0C0;
background-color: #F0F0F0;
width: 584px;
height: 180px;
overflow: scroll;
position: relative;
left: 39px;
top: 813px;
}
in HTML:
<div id = "scroll">
<asp:GridView ID="tblitem" runat="server" CellPadding="4"
ForeColor="#333333" GridLines="None"
style="z-index: 1; left: -2px; top: 0px; position: absolute; height: 57px; width: 584px"
AutoGenerateSelectButton="True" Visible="False">
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
</div>
I dont want to use this because when I hide my gridview, the div scroll that I make is visible.
Try the below link it will help you... here they use Jquery to Scroll Grid view and it was very simple...
Scroll Grid View
You can use grid inside div and make this div scrollable....
This is how i did
JavaScript:
function onLoad() {
FreezeGridViewHeader('MyGridViewID', 'WrapperDiv');
}
function FreezeGridViewHeader(gridID, wrapperDivCssClass) {
/// <summary>
/// Used to create a fixed GridView header and allow scrolling
/// </summary>
/// <param name="gridID" type="String">
/// Client-side ID of the GridView control
/// </param>
/// <param name="wrapperDivCssClass" type="String">
/// CSS class to be applied to the GridView's wrapper div element.
/// Class MUST specify the CSS height and width properties.
/// Example: width:800px;height:400px;border:1px solid black;
/// </param>
var grid = document.getElementById(gridID);
if (grid != 'undefined') {
grid.style.visibility = 'hidden';
var div = null;
if (grid.parentNode != 'undefined') {
//Find wrapper div output by GridView
div = grid.parentNode;
if (div.tagName == "DIV") {
div.className = wrapperDivCssClass;
div.style.overflow = "auto";
}
}
//Find DOM TBODY element and remove first TR tag from
//it and add to a THEAD element instead so CSS styles
//can be applied properly in both IE and FireFox
var tags = grid.getElementsByTagName('TBODY');
if (tags != 'undefined') {
var tbody = tags[0];
var trs = tbody.getElementsByTagName('TR');
var headerHeight = 8;
if (trs != 'undefined') {
headerHeight += trs[0].offsetHeight;
var headTR = tbody.removeChild(trs[0]);
var head = document.createElement('THEAD');
head.appendChild(headTR);
grid.insertBefore(head, grid.firstChild);
}
//Needed for Firefox
tbody.style.height =
(div.offsetHeight - headerHeight) + 'px';
tbody.style.overflowX = "hidden";
tbody.overflow = 'auto';
tbody.overflowX = 'hidden';
}
grid.style.visibility = 'visible';
}
}
HTML MARKUP:
<div id="gvholder">
//My gridviewcontrol
<asp:GridView ID="MyGridViewID" runat="server" >
<Columns>
......
......
......
<Columns>
</asp:GridView>
</div>
CSS
.WrapperDiv {
border: 1px solid #CCCCCC;
height: auto;
max-height: 400px;
width: auto;
}
.WrapperDiv TH {
position:relative;
font-size:12px;
font-weight:bold;
}
.WrapperDiv TR
{
/*NeededForIe*/
height:0px;
}
.WrapperDiv td
{
font-size:12px;
}
#gvholder
{
float:left;
top:10px;
width:auto;
border:1px solid #CCCCCC;
margin-top:10px;
margin-left:10px;
box-shadow:1px 2px 9px black;
}
Wrap the gridview with a div like you mentioned you didn't want to do, but to get around the "hide my gridview, the div scroll that I make is visible" you wrap that with a panel and make the Panel.Visible=true or false.
For me that hides the scrollable GridView without leaving space.