Wednesday, 10 April 2013

Important codes

To Register the JavaScript Function from code behind
ScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.NewGuid().ToString(), "Javascript:AddDate();", true);

To Register the JavaScript Function in $(document).ready on every AJAX or Simple requests.
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(DatePick);

To Delete all rows from Sql Table and start Identity from 1.
DBCC CHECKIDENT('TableName',RESEED,0)

To Confirm before any click event. 
OnClientClick='return confirm("Are you sure you want to Submit?")'


To get selected value of Dropdown list using JavaScript. 
var drpLeave = document.getElementById('<%= drpLeaveType.ClientID %>');           
var LeaveType = drpLeave.options[drpLeave.selectedIndex].value;

To get the cell value of Gridview using JavaScript. 
var AvailableLeaves = document.getElementById('<%= gvLeaveStatistics.ClientID %>').rows[1].cells[0].innerText;


To get the value of Label. 
var NoOfDays = document.getElementById('<%= lblNoOfDay.ClientID %>').innerText;


To Select & Deselect all the CheckBox in GridView on Header CheckBox select.
First Add Item Template for CheckBox in Column of GridView.
<asp:TemplateField HeaderText="Action">
 <HeaderTemplate>
<div>
<asp:CheckBox ID="chkSelectAll" runat="server" CssClass="styled headercheck" />                                  
</div>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>

Now Write this function in Header Part.
<script type="text/javascript">
    $(document).ready(function () {
        $("#<%=GridView1.ClientID%> input[id*='chkSelectAll']:checkbox").click(function () {
            if ($(this).is(':checked'))
                $("#<%=GridView1.ClientID%> input[id*='CheckSelect']:checkbox").attr('checked', true);
            else
                $("#<%=GridView1.ClientID%> input[id*='CheckSelect']:checkbox").attr('checked', false);
        });
    });
</script>


To get all the checked CheckBox and Id of that row from GridView on Button Click.
First Add Item Template for CheckBox in Column of GridView.
<asp:TemplateField HeaderText="Action">
 <HeaderTemplate>
<div>
<asp:CheckBox ID="chkSelectAll" runat="server" CssClass="styled headercheck" />                                  
</div>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>

Now write the following code on Button Click Event.
foreach (GridViewRow row in GridView1.Rows)
            {
                CheckBox Chk = (CheckBox)row.FindControl("CheckSelect");
                Label Lbl = (Label)row.FindControl("Label1");
                if (chk != null && chk.Checked)
                {
                    Id = Lbl.Text;
                }
            }


RowDatabound of GridView.
ImageButton Name = (ImageButton)e.Row.FindControl("imgUser");

RowComman of GridView
LinkButton Name = (LinkButton)e.Row.Cell[0].Controls[0];

GridViewRow ClickedRow = ((LinkButton)e.commandSource).NamingContainer as GridviewRow;
Label lblID = (Label)ClickedRow.FindControl("lblID");

ButtonClick of Gridview
GridViewRow ClickedRow = ((LinkButton)sender).NamingContainer as GridViewRow;
Label lblID = (Label


Give alert before Redirect the page
ScriptManager.RegisterStartupScript(this,this.GetType(),"redirect","alert('Time OutAlert'); window.location='" + Request.ApplicationPath +"Nextpage.aspx';",true);


Read Permission in IIS for Folders.
IUser
IISUser
NetworkService

No comments:

Post a Comment