Thursday, July 9, 2015

How to hide Grid View column in ASP.net




protected void gvAppList_DataBound (object sender, EventArgs e)
        {
             GvDetails.Columns[1].Visible = false;

        }

Thursday, May 15, 2014

Javascript Confirmation message on DropDownList Selected Index Changed Event


 Suppose a  user entering records in fields and before save, changed the selected DropDownList suddenly there should be a message . Otherwise the values will be lose those are loaded under   DropDownList selected index change event.I took a another textbox to hold the previous selected index value of  DropDownList .(Also we can take HiddenField)


     protected void DDlPo_SelectedIndexChanged(object sender, EventArgs e)
        {
            DDlPo.Attributes.Add("onchange", "return OnSelectedIndexChange();");
            LoadMaterialBatchDetails();//this is load method

         }





   <script language="javascript" type="text/javascript">
            function OnSelectedIndexChange() {
                  var IndexValue = document.getElementById('DDlPo');               
                  var PreviousIndexValue = document.getElementById('Txt PreviousIndexValue ').value;
                  if (IndexValue.selectedIndex != PreviousIndexValue) {
                      if (confirm("Are you sure to select another Order Number, Data will be loss for this Order Number?") == true) {
                          document.getElementById('BtnClose').click();
                          IndexValue.selectedIndex = IndexValue.selectedIndex;
                      }
                      else {
                          IndexValue.selectedIndex = PreviousIndexValue;
                      }
                }
               
            }

        </script>





Thursday, March 6, 2014

Response.Redirect () in JavaScript


Sometimes we need to redirect our page on through JavaScript function and also in code behind using JavaScript . Here the solution

   1.  Redirection Without Parameter

 var url='<%# ResolveUrl("~/Modules/WorkOrder/WorkOrderAddTask.aspx") %>';
 windows.location.href=url;;

   2.  Redirection With Parameter

 var url='<%# ResolveUrl("~/Modules/WorkOrder/WorkOrderAddTask.aspx?WID=' + Wid + '&TID='+Tid+ '") %>';

 windows.location.href=url;

  3.  Redirection from CodeBehind

  ScriptManager.RegisterStartupScript(this, this.GetType(), "scriptid", "   window.top.location='" + Page.ResolveUrl("~/FrmLogin.aspx") + "';", true);

    3.  Redirection from CodeBehind With Parameter

  ScriptManager.RegisterStartupScript(this, this.GetType(), "scriptid", "   window.top.location='" + Page.ResolveUrl("~/FrmLogin.aspx?ID="+1+"&Name="+ variable ) + "';", true); 

I hope all will work must.

Monday, August 19, 2013

Thursday, August 8, 2013

Example of Repeater Control in Asp.Net







Source Code

<div>
        <asp:Repeater ID="myRepeater" runat="server">
            <HeaderTemplate>
                <table width="400" border="1">
                    <tr>
                        <th>
                            Roll </th>
                        <th>
                            Age  </th>
                        <th>
                            Date </th>
                        <th>
                            Name </th>
                    </tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr>
                    <td>
                        <%# Eval("roll") %> </td>
                    <td>
                        <%# Eval("age") %>  </td>
                    <td>
                        <%# Eval("infdate") %> </td>
                    <td>
                        <%# Eval("name") %>  </td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
                <tr>
                    <td colspan="4">
                        Example of Repeater Control
                    </td>
                </tr>
                </table>
            </FooterTemplate>
        </asp:Repeater>
    </div>

C# Code

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;


public partial class FrmRepeaterControl : System.Web.UI.Page
{
    SqlConnection con;
    SqlCommand cmd;
    SqlDataReader dr;
    SqlDataAdapter da;
    DataSet ds;
    protected void Page_Load(object sender, EventArgs e)
    {
        //Declare connection in web.config
        con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString);
        getRepeater();
    }

    private void getRepeater()
    {

        con.Open();
        cmd = new SqlCommand("select * from fms_demo", con);
        dr = cmd.ExecuteReader();
        myRepeater.DataSource = dr;
        myRepeater.DataBind();
        con.Close();
       
    }
}