Sunday, August 18, 2013

MultiView in Asp.net


Code:   


       MultiView1.ActiveViewIndex = 0;



MultiView1.ActiveViewIndex = 1;


.aspx 

<asp:MultiView ID="MultiView1" runat="server">
                    <asp:View ID="CourseDetails" runat="server" >
                        <table class="style1">
                            <tr>
                                <td class="style2">
                                    Course</td>
                                <td>
                                    <asp:TextBox ID="txtCourse" runat="server"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td class="style2">
                                    Fees</td>
                                <td>
                                    <asp:TextBox ID="txtFees" runat="server"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td class="style2">
                                    Duration</td>
                                <td>
                                    <asp:TextBox ID="txtDuration" runat="server"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td class="style2">
                                    &nbsp;</td>
                                <td>
                                    <asp:Button ID="btnSave" runat="server" Text="Save" onclick="btnSave_Click" />
                                </td>
                            </tr>
                        </table>
                    </asp:View>
                    <asp:View ID="BookDetails" runat="server">
                        <table class="style1">
                            <tr>
                                <td class="style2">
                                    BookName</td>
                                <td>
                                    <asp:TextBox ID="txtBook" runat="server"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td class="style2">
                                    Auother</td>
                                <td>
                                    <asp:TextBox ID="txtAuthor" runat="server"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td class="style2">
                                    Price</td>
                                <td>
                                    <asp:TextBox ID="txtPrice" runat="server"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td class="style2">
                                    &nbsp;</td>
                                <td>
                                    <asp:Button ID="btnAdd" runat="server" Text="Add" />
                                </td>
                            </tr>
                        </table>
                    </asp:View>
                    <asp:View ID="StudentsDetails" runat="server">
                        <table class="style1">
                            <tr>
                                <td class="style2">
                                    RegNo</td>
                                <td>
                                    <asp:TextBox ID="txtReg" runat="server"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td class="style2">
                                    Name</td>
                                <td>
                                    <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td class="style2">
                                    Branch</td>
                                <td>
                                    <asp:DropDownList ID="ddlBranch" runat="server" Height="16px" Width="128px">
                                        <asp:ListItem>--select--</asp:ListItem>
                                        <asp:ListItem>CS</asp:ListItem>
                                        <asp:ListItem>EC</asp:ListItem>
                                    </asp:DropDownList>
                                </td>
                            </tr>
                            <tr>
                                <td class="style2">
                                    &nbsp;</td>
                                <td>
                                    <asp:Button ID="btnUpdate" runat="server" Text="Update" />
                                </td>
                            </tr>
                        </table>
                    </asp:View>
                </asp:MultiView>

Chart in Asp.net

.aspx

  <asp:Chart ID="Chart1" runat="server" Palette="Bright">
                        <series>
                            <asp:Series Name="Series1">
                            </asp:Series>
                        </series>
                        <chartareas>
                            <asp:ChartArea Name="ChartArea1">
                            </asp:ChartArea>
                        </chartareas>
                    </asp:Chart>

Code (Example)

 protected void btnChart_Click(object sender, EventArgs e)
    {
        string sel = "select * from tbl_employee";
        DataTable dt = new DataTable();
        dt = obj.selectQuery(sel);
        Chart1.DataSource = dt;
        Chart1.Legends.Add("Salary").Title = "Salary";
        Chart1.ChartAreas["ChartArea1"].AxisX.Title = "Name";
        Chart1.ChartAreas["ChartArea1"].AxisY.Title = "Salary";
        Chart1.Series["Series1"].XValueMember = "empname";
        Chart1.Series["Series1"].YValueMembers = "empsalary";
      Chart1.Series["Series1"].ToolTip = "#VALY, #VALX";
        Chart1.DataBind();


    }

Captcha in Asp.Net

Add   Asp.net Folder  ---  >  Bin
Paste two files ---- >  MSCaptcha.xml   and    MSCaptcha.dll  into  folder Bin
Add a control  Captch to ToolBox--- > ( right button on toolbox---> ChooseItems --- >browse --- > select MSCaptcha.dll   from folder Bin ( new control CaptchaControl will add to ToolBox and use that Control)).

Modify your web.config file, by adding this line to
<httpHandlers>
<add verb="GET" path="CaptchaImage.axd" type="MSCaptcha.CaptchaImageHandler, MSCaptcha"/>
</ httpHandlers>



protected void btnSave_Click(object sender, EventArgs e)
    {
      
       ccJoin.ValidateCaptcha(txtCode.Text); // here check captcha control
      
         if (!ccJoin.UserValidated)
         {
             lblmsg.Text = "Invalid Captcha";
             lblmsg.ForeColor = System.Drawing.Color.Red;
         }
         else
         {
             string insert = "insert into tbl_userreg(fname,uname,password)values('"+txtfname.Text+"','"+txtuname.Text+"','"+txtpwd.Text+"')";
             obj.execute_Query(insert);
             lblmsg.Text = "Datat Entered Successfully";
             lblmsg.ForeColor = System.Drawing.Color.Green;
         }
    }



Tree in Asp.Net



.aspx

<asp:TreeView ID="TreeView1" runat="server">

                    </asp:TreeView>


Code (Example)

 protected void fillTree()
    {
        string sel = "select * from tbl_product";
        DataSet ds = new DataSet();
        ds = obj.selectData(sel);
        DataRow[] Rows = ds.Tables[0].Select("ParentId IS NULL"); // Get all parents nodes
        for (int i = 0; i < Rows.Length; i++)
        {
            TreeNode root = new TreeNode(Rows[i]["ProductName"].ToString(), Rows[i]["ProductId"].ToString());
            root.SelectAction = TreeNodeSelectAction.Expand;

            CreateNode(root, ds.Tables[0]);  // to create child nodes
            TreeView1.Nodes.Add(root);
         
        }
   

    }


   public void CreateNode(TreeNode node, DataTable Dt)
    {
        DataRow[] Rows = Dt.Select("ParentId =" + node.Value);
        if (Rows.Length == 0) { return; }
        for (int i = 0; i < Rows.Length; i++)
        {
            TreeNode Childnode = new TreeNode(Rows[i]["ProductName"].ToString(), Rows[i]["ProductId"].ToString());
            Childnode.SelectAction = TreeNodeSelectAction.Expand;
            node.ChildNodes.Add(Childnode);
            CreateNode(Childnode, Dt);
        }
    }