Basic ASP C#

I hope this first tutorial can help you to answer below question:

  • How to load AspxGridView
  • How to read Web.Config file
  • How to get ConnectionString of SQLDataSource from Web Config
  • How to set parameter of SQLDataSource

My Aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<%@ Register assembly="DevExpress.Web.ASPxGridView.v10.2, Version=, Culture=neutral, PublicKeyToken=zzzzz" namespace="DevExpress.Web.ASPxGridView" tagprefix="dx" %>
<%@ Register assembly="DevExpress.Web.ASPxEditors.v10.2, Version=, Culture=neutral, PublicKeyToken=zzzzz" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <script language="javascript" type="text/javascript">
// <!CDATA[
// ]]>
    <form id="form1" runat="server">
        <dx:ASPxButton ID="ASPxButton1" runat="server" onclick="ASPxButton1_Click" 
        <br />
        <dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="True" 
            DataSourceID="SqlDataSource1" KeyFieldName="PKId">
            <Settings ShowFilterRow="True" />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            SelectCommand="MY_SP" SelectCommandType="StoredProcedure">
                <asp:Parameter Name="PARAM_1" Type="DateTime" />
                <asp:Parameter Name="PARAM_2" Type="String" />

My Aspx.cs

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace WebApplication1
    public partial class _Default : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
            // how to get web config value & set to sql datasource
            SqlDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings["LBUConnectionString"].ConnectionString;
            // load data from aspxgridview
        protected void ASPxButton1_Click(object sender, EventArgs e)
            // inject variable or parameter to sqldatasource
            SqlDataSource1.SelectParameters["PARAM_1"].DefaultValue = DateTime.Now.ToString();
            SqlDataSource1.SelectParameters["PARAM_2"].DefaultValue = "20180101";


Leave a Reply

Your email address will not be published. Required fields are marked *

Afiseaza emoticoanele Locco.Ro