Friday, November 30, 2012

Change Gender (Male to Female, Female To Male) In Sql Server


UPDATE emp SET gender =
CASE gender WHEN 'M' THEN 'F' WHEN 'F' THEN 'M' ELSE gender END

Wednesday, November 7, 2012

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

By default the timeout of an SQL 'statement' is set to 30 seconds. If SQL Server takes more than 30 seconds to complete your task, you'll receive a timeout. You may want to set the timeout yourself. The timeout property is called CommandTimeout, it's a property of the SqlCommand object.

Using myCommand As New SqlCommand()
 ' Set the new command timeout to 60 seconds
 ' in stead of the default 30
 myCommand.CommandTimeout = 60
End Using
 
or
 
using (SqlCommand myCommand = new SqlCommand())
{
   // Set the new command timeout to 60 seconds
   // in stead of the default 30
   myCommand.CommandTimeout = 60; 
} 

Tuesday, November 6, 2012

Refresh parent page on close of Window showModalDialog

Parent Page :
<head runat="server">
<script type="text/javascript" language="javascript">

function EditParent()
{    
var uid=document.getElementById('<%=hdnUserId.ClientId%>').value
var id=document.getElementById('<%= hdnId.ClientId %>').value
                        window.showModalDialog("childpage.aspx?childid="+id+"&UserId="+uid,"childpage","dialogHeight: 500px; dialogWidth: 800px; dialogTop: 200px; dialogLeft: 150px; edge: Raised; center: Yes; resizable: Yes; status: Yes;scroll: No");
               
}

</script>
</head>

Child Page:

<head runat="server">

<base target="_self"></base>

</head>


Removing list items from the DropDownList

DropDownList1.Items.RemoveAt(0);
But if you want to loop anyway, here is the loop :
foreach (ListItem item in DropDownList1.Items) 
{ 
 // your condition

}
 
Or if you know the index of the item to remove, use RemoveAt method :


 
ListItem itemToRemove = DropDownList1.Items.FindByValue("value");
if (itemToRemove != null)
{
    DropDownList1.Items.Remove(itemToRemove);
}
 

Friday, November 2, 2012

Refresh Parent page on close of popup

Parent Page:
<script type="text/javascript" language="javascript">
        function EditDetail(id)
        {    
            var userid=document.getElementById('<%= hdnUserId.ClientId %>').value
            window.open("DailyDetails.aspx?leadDetailid="+id+"&UserId="+userid,"DailyDetails",'width=800,height=500,top=10,left=200,resizable=yes,scrollbars=yes');          
        }
 </script>

Child Page:
Write this child page code behind page:

Private Function modifyDailydtls() As Boolean
 Page.ClientScript.RegisterStartupScript(GetType(String), "close", "<script language='javascript'>window.opener.document.forms[0].submit();self.close();</script>")
End Function

ValidationGroup and javascript validation both used in asp.net page

Some time Validation Group and  java script validation are not work at both used page.

So You want ValidationGroup and  javascript validation in asp.net page then you have to  write.this way.

<script type="text/javascript" language="javascript">
<asp:Button CssClass="button" ID="btnSave" runat="server" Text="Save" Width="40px"
                                                    ValidationGroup="FestivalMaster" OnClientClick="return validationOnSave()" />
                                                <asp:Button CssClass="button" ID="btnReset" runat="server" Text="Reset" Width="40px" />
</script>

<body>
    <form id="form1" runat="server">
        <div>
 function validationOnSave()
    {
       if (Page_ClientValidate("FestivalMaster")) // this same name as your ValidationGroup name
      {
         // write your validation
     }
  } 

</div>
    </form>
       
  </body>