Dynamic Gridview binding in asp.net c# by getting data from StoredProcedure


Table Design:

TableDesign Data In Table:

DatainTable

Stored Procedure:

create procedure sp_GetCustomers
as
begin
select * from dbo.customer
end

Code in Default.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
    </div>
    </form>
</body>
</html>

Code in Default.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("Data Source=SourceName;Initial Catalog=DbName;User ID=sa;Password=YourPassword");
        SqlCommand cmd = new SqlCommand("sp_GetCustomers", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }
}

OutPut:

Dynamic Gridview binding in asp.net c# by getting data from StoredProcedure

How to set radwindow behaviors through ClientSide javascript


<script type=”text/javascript” language=”javascript”>
function ShowPopup() {
var oWnd = radopen(“Popups/Employees.aspx”, “radWin_Employees”);
oWnd.SetTitle(“Visitors”);
oWnd.set_initialBehaviors(Telerik.Web.UI.WindowBehaviors.None);
oWnd.set_behaviors(Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Move);
}
</script>

RadWindow position – always in the center of screen through ClientSide javascript


<script type="text/javascript" language="javascript">
            function ShowPopup() {
                var oWnd = radopen("Popups/Employees.aspx", "radWin_Employees");
                oWnd.SetTitle("Visitors");
                oWnd.SetSize(950, 502);
                oWnd.Center();
            }
        </script>

How to Set Visible=false/true or assign Text for ImageButton/LinkButton in a RadGrid command template


Normally we can’t find controls in grid using Codebehind but we can find these by Placing some code in OnItemDataBound Event
so first bind OnItemDataBound event and add following code snippet to it…

protected void radgrd_Charges_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridCommandItem)
        {
            GridCommandItem commandItem = (GridCommandItem)e.Item;
            ImageButton ibn_Print = (ImageButton)commandItem.FindControl("ibn_Print");
            LinkButton lnk_Print = (LinkButton)commandItem.FindControl("lnk_Print");
            ibn_Print.Visible = false;
            lnk_Print.Visible = false;
            ibn_Print.ImageUrl = "~/Images/PrintandSave.png";
            lnk_Print.Text = "Pritn & Save";
        }
    }

How to convert first letter of each word to uppercase of text entering in textbox in asp.net


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CamelCase.aspx.cs" Inherits="CamelCase" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
    <title></title>
    <script type="text/javascript" language="javascript">
      function myFunction(id) {
      var txt  = document.getElementById(id);
      txt.value = txt.value.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
     }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server" onkeyup="myFunction(this.id)"></asp:TextBox>
    </div>
    </form>
</body>
</html>

How to convert entering text in textbox to LowerCase or UpperCase using Javascript in asp.net


If we want to convert Values Entering in textbox to LowerCase or UpperCase we can user onkeyup client event for textbox.
and to convert to LowerCase/UpperCase We can use Javascript Methods toLowerCase/toUpperCase.
See the following example to Understand how to use above methods…

toUpperCase:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LowerToUpper.aspx.cs" Inherits="LowerToUpper" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">
        function ToUpper(id) {
            document.getElementById(id).value = document.getElementById(id).value.toUpperCase();
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server" onkeyup="ToUpper(this.id)"></asp:TextBox>
    </div>
    </form>
</body>
</html>

toLowerCase:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LowerToUpper.aspx.cs" Inherits="LowerToUpper" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">
        function ToLower(id) {
            document.getElementById(id).value = document.getElementById(id).value.toLowerCase();
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server" onkeyup="ToLower(this.id)"></asp:TextBox>
    </div>
    </form>
</body>
</html>

How to add Dynamic Colspan for td in xslt..?


<tr>
                                        <td style="border-top: 1px solid black;padding: 5px;">
                                            <xsl:for-each select="ChargeGroupNames">
                                                <xsl:variable name="norows" select="count(ChargeGroupsVo)"></xsl:variable>
                                                <xsl:if test="$norows &gt; 1">
                                                    <xsl:attribute name="colspan">
                                                        <xsl:value-of select="$norows + 2"/>
                                                    </xsl:attribute>
                                                </xsl:if>
                                            </xsl:for-each>
                                        </td>
                                    </tr>