I think every one was aware of chrome browser in this if we select History we will get all the browsing data. When we hover the mouse on a particular row a check box was visible and when we select that the button was enabled how to do this type of scenario
Set the checkbox to display:none and then try this
protected void RecordsGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover","checkbox.style.display='block'");
e.Row.Attributes.Add("onmouseout", "checkbox.style.display='none'");
}
}
#User: Hi you can make check box visible using j query for that follow folowing link in which it highlight row, but using same funda you can make check box visible and button also.
http://www.dotnetcurry.com/ShowArticle.aspx?ID=250
http://jquerybyexample.blogspot.com/2011/06/highlight-row-on-mouseover-in-gridview.html
Try this
$(function(){
$("#gridviewname tr").live("hover",function(){
$(this).find("input[id*='chkName']").show();
},
function(){
$(this).find("input[id*='chkName']").hide();
});
$("#gridviewname tr").live("click",function(){
if($(this).find("input[id*='chkName']").attr("checked"))
{
$(this).find("input[id*='chkName']").removeAttr("checked");
$(this).find("input[id*='chkName']").hide();
}
else
{
$(this).find("input[id*='chkName']").attr("checked",true);
$(this).find("input[id*='chkName']").show();
}
});
});
Related
I have a Gridview with a link button in the first column. Once the link button is clicked I want to open a window, but I also want to disable the link button.
Not working
Once I click on the link button the window behavior is the expected one. However, the link button is not disabled. Therefore is permitting me to click on it over and over again.
The front end is:
<asp:LinkButton runat="server" ID="lnkbtnView" CommandArgument='<%# Eval("Id")%>' OnCommand="GetViewOnClientClick" >View<br/></asp:LinkButton>
GetviewonClientClick method:
protected void GetViewOnClientClick(object sender, EventArgs e)
{
LinkButton lb = (LinkButton)sender;
GridViewRow row = (GridViewRow)lb.NamingContainer;
if (row != null)
{
int index = row.RowIndex;
LinkButton link = (LinkButton)row.FindControl("lnkbtnView");
link.Enabled = false;
}
}
Why is not working as expected?
That's what I want to solve. I suspect I might have to do a rebinding or something related, but I don't quite understand what is really going on. Therefore, I don't know how to implement it.
I never found the solution to edit the control in that method. What I did instead was to read on the cycles of the grid view events.
https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview_events(v=vs.110).aspx
If you read the previous link, you'll know that once you click on a record it is going to trigger a call to the RowDataBound event. Therefore; in the RowDataBound event you'll have access to the control and apply logic to edit the control's properties (such as color, disabled, enabled...).
Therefore, because I have two types of records in this grid view, I needed to store and to make persistent what records were clicked.
This is my fix to keep track of the clicked rows:
protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
gvs.SetHeaderArrows(e);
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
int Id = (int)(e.Row.RowIndex);
int? inspID = convert.ToIntQ(DataBinder.Eval(e.Row.DataItem, "InspectionID"));
string rowclicked = string.Format("clickedrow{0}", Id);
if (convert.ToIntQ(Session[rowclicked]) != null)
{
if (Id == Convert.ToInt32(Session[rowclicked]))
{
LinkButton button = (LinkButton) e.Row.FindControl("lnkbtnView");
button.ForeColor = Color.Gray;
button.Enabled = false;
}
else
{
LinkButton button = (LinkButton)e.Row.FindControl("lnkbtnView");
button.ForeColor = Color.DarkBlue;
button.Enabled = true;
}
}
I have created a page with a button that opens up a new page, a pop-up if you will.
btnToolbarSearch.Attributes.Add("onclick", "window.open('DagbokSearch.aspx','','height=600,width=600');return false");
On this new page that opens up I have a gridview where you get the below info. (You do a search on the "from date" to the "to date" and get the records in between.)
The first column where it says "Gå till" is a link
<asp:HyperLinkField DataNavigateUrlFields="Foretag"
DataNavigateUrlFormatString="userProfile.aspx?ID={0}"
Text="Gå till" />
I would like this link to get me back to the previous page and open up the object with the corresponding id, I'm not sure how to accomplish this. Maybe there is a better way then the one I'm using but I'm still learning.
You should be able to use the window.opener property to get a reference to the parent window. You can then set it's URL to the selected link, and close the popup window.
Something like this should do the trick:
// Place this near your closing </body> tag
// NB Uses jQuery and event delegation
$(function() {
$('table').on('click', 'tr > td:first > a', function(event) {
if (window.opener) {
event.preventDefault();
window.opener.location.href = this.href;
window.close();
}
});
});
You can set its NavigateUrl property in the Rowdatabound event of the gridview. Like;
protected void gvDogBok_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
((HyperLink)e.Row.Controls[1].Controls[1]).NavigateUrl = "~/userProfile.aspx?ID="+((YourType)e.Row.DataItem).ID+"";
}
}
I'm not sure if what you are asking can be done. I would advice you to use a floating div popup instead. This way you dont have to leave the current page and go to a new tab. This should solve your problem and does avoid problems with popup blockers.
Here are some examples: http://www.javascripttoolbox.com/lib/popup/example.php
Use this one
protected void gvDogBok_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
((HyperLink)e.Row.Controls[1].Controls[1]).Attribute.Add("onclick", "window.opener.location =userProfile.aspx?ID="+ ((YourType)e.Row.DataItem).ID+"; window.close();";
}
}
You can set JavaScript:window.location.replace(url); to the clientside onclick of the HyperLink. window.location.replace(url) will reload the page.
btnToolbarSearch.Attributes.Add("onclick", "var windowHandle = window.open('DagbokSearch.aspx','','height=600,width=600');return false");
and on hyperlink cleint side onclick
hyperLink.Attributes.Add("onclick", "windowHandle.close();window.location.replace(url);return false");
My datagridview is in RowHeaderSelect mode. So clicking on the RowHeader selects the whole row.
However, at any point, when i use context menu shortcuts or shortcut keys from the keyboard, i need to check if a whole row is currently selected, or just a single cell, and perform actions accordingly. How do I check this?
you can check with e.CommandName property.
Check foolowing patch of code>>
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
SXEngine.Classx USER = (SXEngine.Classx)Session["APPOBJ"];
if (e.CommandName == "Select")
{
USER.bRowSelect = true;
}
else
{
USER.bRowSelect = false ;
}
}
Study this link to get more info regarding different properties of gridview>>
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.selectedindexchanging.aspx
Use CommandName method of RowCommand event's argument e.
like
if(e.CommandName=="Select")
{
//code
}
I have gridview which has columns of data and a button below the "Apply" to perform some action.
One column in Gridview is a checkbox column. When you select checkboxes and click apply a confirm message pops up asking "Are you sure?" with option of "Yes" and "No".
But if no check box is checked i want to show a popup to user to select a checkbox before performing an action and not show the confirm message popup.
What i have now is if no checkbox is selected the confirm message pops up first and if i press "yes" then an alert message pops up to select atleast one checkbox. If i press cancel no pop up shows.
Here is my code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ApplyAction_Button.Attributes.Add("onclick", "return confirm('Are you sure?');");
}
}
protected void ApplyAction_Button_Click(object sender, EventArgs e)
{
// Gets the selected checkboxes in the gridview
ArrayList selectedMachines = new ArrayList();
GetSelectedMachineIds(selectedMachines);
if (selectedMachines.Count == 0)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('Please select a machine for the action to be applied');</script>");
return;
}
// Action to be applied
}
I am trying to avoid the use of postback.
Another question:
Is there a server side confirm message box in asp.net?
Any help will be appreciated. Thanks
You can set your button visible to false, once check box is checked then you can show the button.
another way is to use javascript to check if checkbox is checked
code behind
ApplyAction_Button.Attributes.Add("onclick", "ShowConfirm();");
javascript
function ShowConfirm()
{
//check if checkbox is checked if is checked then display confirm message else display alert message
if( "assumed checkbox is checked"){
return confirm("message here");
}
else{
alert("message here");
}
}
try to see this thread
Checkbox in gridview
Determining a which checkbox is checked on a datagrid and updating DB
Regards
This is a follow up to my previous question:
link text
In gridview's column i have a linkbutton and a label under it.
I want to hide/unhide label when linkbutton is clicked. I use javascript because i don't want any postbacks.
The code:
protected void gvwComments_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lButton = ((LinkButton)e.Row.Cells[2].FindControl("lbtnExpand"));
Label label = ((Label)e.Row.Cells[2].FindControl("lblBody"));
lButton.Attributes.Add("onclick", string.Format("HideLabel('{0}'); return false;", label.ClientID));
}
}
function HideLabel(button) {
var rowObj = document.getElementById(button);
if (rowObj.style.display == "none") {
rowObj.style.display = "block";
}
else {
rowObj.style.display = "none";
}
}
The problem is that when I unhide the label by clicking on button, linkbutton is shifted a a bit upper it's original position in the cell.
Is it possible to preserve linkbutton's position in the gridviews cell?
I would suggest you change your CSS from display:none to display:hidden which will hide the control but maintain the space preventing the jumping around.
The trick is to use the keyword "this" and then get a reference to the row and change the label from there.
I have a post here, where I have a GridView with a CheckBox column and a Name column. When the CheckBox is checked the background color of the Name on that row changes. I do this starting with this attribute in the CheckBox's column:
onclick="toggleSelected(this)"
then I have a JavaScript function that finds the row and changes the next cell:
function toggleSelected(sender) {
// note that at this point the "this" is now "sender" -which is the checkbox
// get a reference to the row using the helper function - see below.
var row = GetParentElementByTagName(sender, "TR");
if (sender.checked)
row.cells[1].className = "selected";
else
row.cells[1].className = '';
}
This uses the helper function:
function GetParentElementByTagName(element, tagName) {
var element = element;
while (element.tagName != tagName)
element = element.parentNode;
return element;
}
You have a slightly different requirment so you would use something like:
var lbl = row.cells[1].childNodes[0].getElementsByTagName('label')
to get a reference to your label.