Showing posts with label Asp.net Examples. Show all posts
Showing posts with label Asp.net Examples. Show all posts

Wednesday, August 14, 2013

Datasource Controls in Asp.net


The data source controls are available from asp.net 2.0(Not bound controls).Using this controls we can automate the task of creating data object.Normally we have to prepare data object programatically(using code).Whenever use these controls we may get some question regarding wizard approach features then one programmatic object will be created most importantly these controls provide complete customization options.The following data source controls are available in Asp.net

1.SQL Data source control
2.LINQ Data source control
3.Object Data source control
4.XML Data source control
5.Ado.net entity framework Data source control

1.Sql Data source control:
it is used to prepare data object from any SQL supported database Oracle,SqlServer,Access,My Sql,SYSbase,Informix,Ingres etc


Features:
The DS controls supports caching features . Data source controls does not Cache any data.with enable cache property of it we can add caching support.The reason to cache data is to avoid DB trips for every request.If data is cached then we retrieve data from they cache only by avoiding db.This will improve performance like anything.Different property for caching are also supported for maintaining time ,dependency etc
Conflict Detection(Concurrency control)
Using Data source controls when we manipulate data there is every possibility of occurring concurrency problems because web is for all and also our form can be accessed many users . DS controls provide conflict detection with 2 option

i)Override changes
ii)Compare all values

Monday, July 29, 2013

Bind data to Asp.net text box using jquery

Title: JQuery bind data to asp.net text box using Blur function

Description:
As per previous articles we have gone through different kind of data binding examples using jquery in asp.net.Now here we will learn about the usage of jquery functionality for web control.

Example:
Now i would like give an example to set the data to Text box in asp.net using jquery.This application will use to  set the food orders.As per requirement we need to assign the value to text box control based on food category Id.To accomplish this task  i have utilized  Jquery script function i:e Blur() which make the functionality what ever we used inside of it

$(document).ready(function() {
$("#<%= txtOrderList.ClientID %>").blur(function(){
var orderList = $(this).val();
$("#<%= txtOrderList1.ClientID %>".val(orderList); 
});

The above script will will bind the data to text box when the other text box focus has moved.You can use this functionality as per requirement very quickly.
This article may help you a lot..Keep visit my website

Tuesday, July 23, 2013

Serverside programming in Asp.net

1.All programs that are written as html/Js are executed in client system only.
2.The role of server for these programs is simply send a copy of program to client browser and its JS independent exceeds the code in client
3.Now when we write server side programs the program will be executed at server only .
4.The result will be sent back to client .All client side ans server side programs are based on execution only.
5.In web application extension are very important.
6.Many server side  environment are provided to develop server side scripting and web application

Friday, July 19, 2013

Components of .net framework

Many of the updated and code related things have discussed on er-liar. In this post i just give some basic Concepts of .net framework.
The components of .net frame work:

1.Common Language Run time(CLR)
2.Base class library
3.Framework Class Library

Components of CLR:
1.Common language specification(CLS)
2.common type system(CTS)
3.garbage collector
4.Just in time

Monday, July 15, 2013

how to compare two xml files in asp.net using c#

Title:How to compare XML files in Asp.net using C#

Description:

Now i would like to give an examples on Comparing of XML documents using C# code.Asp.net provide an algorithm which is "hash algorithm",can be used for encryption.So based on those methods i will do the comparison of files In the below method i have use two parameters which indicates the path of XML files

Examples:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Security.Cryptography;

private void CompareXMLDocumnet(string ActualDocumnet,string GenratedDocument)
{
if (File.Exists(ActualDocumnet) && File.Exists(GenratedDocument))
{
HashAlgorithm HA = HashAlgorithm.Create();
FileStream XmlFstream1 = new FileStream(ActualDocumnet, FileMode.Open);
FileStream XmlFstream2 = new FileStream(GenratedDocument, FileMode.Open);
byte[] Actual_Xmlhash1;
byte[] Genrated_Xmlhash2;
Actual_Xmlhash1= HA.ComputeHash(XmlFstream1);
Genrated_Xmlhash2= HA.ComputeHash(XmlFstream2);
XmlFstream1.Close();
XmlFstream2.Close();
if (Convert.ToBase64String(Actual_Xmlhash1) == Convert.ToBase64String(Genrated_Xmlhash2))
{
Response.Write(" similar="">
}
else
{
throw new Exception("Files are different");
}
}
}

Monday, July 1, 2013

Get dropdownlist selcted value in gridview in Asp.net

Title:
how Get Drop down List selected value  in grid view using c# in asp.net
Requirement: 
.Frame Work and Sql Server
Explanation:
Here i will show how to fire selected index event of drop down in grid view.When we work with drop down list in grid view ,Most  of  the confusion about how to get the selected value of DDL.By using this event(SelectedindexChanged) we can do it.
As per requirement have to display details of selected record details in report page.By using this ,will get Drop down selected value in grid view. In the above i have fetched the drop down list selected value which in grid view.

protected void ddlorders_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow GvOrderrow= (GridViewRow)ddlorders.NamingContainer;
DropDownList ddlOrdr_name= ((DropDownList)(GvOrderrow.FindControl(“ddlorders"))).SelectedValue;
if((ddlOrdr_name.SelectedValue.ToString()) =="")
{
Response.Write("No order Exist");
}
else
{
Respose.Redirect("Report.aspx?order='"+ CurrentOrdr+"'");
}


Saturday, June 8, 2013

Jquery highlight Gridview selected rows in asp.net

Title: How to highlight grid view rows using jquery in asp.net

Description:
using client script we can make lot functionality on design side.Now i would like explain how to use jquery on data controls in asp.net .Whenever we have to select specified rows with particular style on client side ,the jquery can solve this task

Example:
In previous articles we have seen Bind Data to Grid view,Edit,Delete,Update in Grid view in asp.net,Import Excel to Grid view asp net.Here i will show how to Highlight grid view selected rows.
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Gridview selected Row highlight using jquery</title>
<script src="http://code.jquery.com/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#<%=GVdynamic.UniqueID%> tr").click(function () {
$(this).css("font-weight", "bold");
$(this).css("background-color", "SkyBlue");
$(this).css("border", "2px solid Green");
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GVdynamic" runat="server" AutoGenerateColumns="False"
DataSourceID="sySql">
<Columns>
<asp:BoundField DataField="DyOrderID" HeaderText="DyOrderID" />
<asp:BoundField DataField="DyOrderName" HeaderText="DyOrderName" />
<asp:BoundField DataField="DyPhone" HeaderText="Phone" />
<asp:BoundField DataField="DyAddress" HeaderText="DyAddress" />
<asp:BoundField DataField="DyAmount" HeaderText="DyAmount" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="dySql" runat="server"
    ConnectionString="<%$ ConnectionStrings:Connection %>"
    SelectCommand="SELECT * FROM [dyOrders]"></asp:SqlDataSource>
</form>
</body>
</html>

Friday, May 17, 2013

Gridview inside gridview || Nested gridview in Asp.net

Title:How to use grid view inside grid view in asp.net using c#.net

Description:
Earlier we have seen how to Export grid view data to PDF,Bind data to grid view in asp.net.Here i will given an example for how to develop the nested grid view in asp.net.In this example the binding has done while page load event then the child grid view will populate on row data bound event.
Example:

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Gridview inside gridview or Nested GridView in asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GvParentOrderReport" runat="server" OnRowDataBound="GvOrderReport_RowDataBound"
AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="OrderId"
GridLines="Horizontal">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="Orderid" HeaderText="OrderId">
</asp:BoundField>
<asp:BoundField DataField="OrderName" HeaderText="OrderName" >
</asp:BoundField>
<asp:BoundField DataField="Phone" HeaderText="Phone" >
</asp:BoundField>
<asp:BoundField DataField="Address" HeaderText="Address" >
</asp:BoundField>
<asp:BoundField DataField="Amount" HeaderText="Amount" >
</asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<tr>
<td>
<asp:GridView ID="GvChildOrderNested" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="OrderId" HeaderText="OrderID"/>
<asp:BoundField DataField="OrderName" HeaderText="OrderName"/>
<asp:BoundField DataField="Phone" HeaderText="Phone"/>
<asp:BoundField DataField="Address" HeaderText="Address"/>
<asp:BoundField DataField="Amount" HeaderText="Amount"/>
</Columns>
</asp:GridView>
</div>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</form>
</body>
</html>

using System;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

public partial class _GridviewInsideGridview : System.Web.UI.Page
{
SqlConnection mcon = new SqlConnection("Data Source=Bhaskar\sqlexpress;Initial Catalog=Test;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
mcon.Open();
SqlCommand Parentcmd = new SqlCommand("select * from orders", mcon);
SqlDataAdapter Parentda = new SqlDataAdapter(Parentcmd);
DataSet Parentds = new DataSet();
Parentda.Fill(Parentds);
mcon.Close();
GvParentOrderReport.DataSource = Parentds;
GvParentOrderReport.DataBind();
}
}
     
protected void GvOrderReport_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
mcon.Open();
GridView GvChildOrderNested = (GridView)e.Row.FindControl("GvChildOrderNested");
SqlCommand Childcmd = new SqlCommand("select * from orders", mcon);
SqlDataAdapter Childda = new SqlDataAdapter(Childcmd);
DataSet Childds = new DataSet();
Childda.Fill(Childds);
mcon.Close();
GvChildOrderNested.DataSource = Childds;
GvChildOrderNested.DataBind();
}
}
}

Wednesday, May 15, 2013

How to bind data to gridview with jquery in asp.net

In previous articles i have given Cascading dropdownlist using jquery .In this post i would like to explain how to bind data to gridview using Jquery. Here we can observe the page method calling using jquery post method
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Bind data to grid using jquery in asp.net</title>
<script src=http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js></script>
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "JqueryBindGrid.aspx/BindOrderDataToGrid",
data: "{}",
dataType: "json",
success: function (resData) {
    for (var i = 0; i < resData.d.length; i++) {
        $("#GvOrderDetails").append("<tr><td>" + resData.d[i].OrderId + "</td><td>" + resData.d[i].OrderName + "</td><td>" + resData.d[i].Phone + "</td><td>" + data.d[i].Address + "</td><td>" + resData.d[i].Amount + "</td></tr>");
}
},
error: function (result) {
alert("Exception");
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GvOrderDetails" runat="server">
</asp:GridView>
</form>
</body>
</html>
Code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Web.Services;

public partial class JqueryBindGrid : System.Web.UI.Page
{
  
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable GVHeaderdt = new DataTable();
GVHeaderdt.Columns.Add("OrderId");
GVHeaderdt.Columns.Add("OrderName");
GVHeaderdt.Columns.Add("Phone");
GVHeaderdt.Columns.Add("Address");
GVHeaderdt.Columns.Add("Amount");
GVHeaderdt.Rows.Add();
GvOrderDetails.DataSource = GVHeaderdt;
GvOrderDetails.DataBind();
      
}
}
public class OrderReportDetails
{
public int OrderId { get; set; }
public string OderName { get; set; }
public string Phone { get; set; }
public string Address { get; set; }
public string Amount { get; set; }
}
[WebMethod]
public static OrderReportDetails[] BindOrderDataToGrid()
{
DataTable resDt = new DataTable();
List ORdetails = new List();
SqlConnection Dbcon = new SqlConnection(ConfigurationManager.AppSettings["DbOrdrCon"].ToString());
SqlCommand cmd = new SqlCommand("select * from Orders", Dbcon);
Dbcon.Open();
SqlDataAdapter Orda = new SqlDataAdapter(cmd);
Orda.Fill(resDt);
foreach (DataRow Ordt in resDt.Rows)
{
    OrderReportDetails OrderDetails = new OrderReportDetails();
    OrderDetails.OrderId = int.Parse(Ordt["OrderId"].ToString());
    OrderDetails.OderName = Ordt["OrderName"].ToString();
    OrderDetails.Phone = Ordt["Phone"].ToString();
    OrderDetails.Address = Ordt["Address"].ToString();
    OrderDetails.Amount = Ordt["Amount"].ToString();
    ORdetails.Add(OrderDetails);
}
Dbcon.Close();
return ORdetails.ToArray();
}
  
}

Tuesday, May 14, 2013

how to bind arraylist to gridview in asp.net

In previous articles we have seen how to bind the data to grid view, Bind data to dropdownlist,Bind data to dropdownlist in gridview,Export gridview to PDF.Here i would like to explain how to bind arraylist data to Grid view in asp.net.In the below i have used static array list for binding
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ArrayListToGridview.aspx.cs" Inherits="_ArrayListToGridview" %>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Bind ArrayList to Gridview</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GvBindArrayList" runat="server"
AutoGenerateColumns="False" >
</asp:Gridview>
</form>
</body>
</html>

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

public partial class _ArrayListToGridview : System.Web.UI.Page
{
protected void Page_Load(Object Sender, EventArgs E)
{
if (!IsPostBack) {
ArrayList Booknames = new ArrayList();
Booknames.Add ("Asp.net");
Booknames.Add ("C#.net");
Booknames.Add ("SharePoint");
Booknames.Add ("SqlServer");
Booknames.Add ("Jquery");
Booknames.Add ("Asp.netMVC");
GvBindArrayList.DataSource = Booknames;
GvBindArrayList.DataBind();
}
}
}

Monday, May 13, 2013

jquery redirect to another page in asp.net

Title:How to redirect the from one page to other page in asp.net using Jquery

Description:
Basically the scripting language are used to perform dynamic data processing on client side.It will be improve the performance of application
Example:
In previous examples i have given Validate dropdownlist using Jquery,JqueryUI Autocomplete textbox,Jquery Modal popup for mail in asp.net,Jquery Get next/previous month of year.Here i would like explain how to redirect to other page when click on the button in Asp.net using jquery. We can use location method in two ways as you can see in the script
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src=http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js></script>
<script type="text/javascript">
$(document).ready(function () {
$('#btnRedirect').click(function () {
window.location.href = 'About.aspx';
// or you can use
// location.href = 'About.aspx';
return false;
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="btnRedirect" runat="server" Text="Redirect" />
</form>
</body>
</html>

Thursday, May 2, 2013

gridview paging and sorting without postback in asp.net


In previous articles we have seen Bind data to dropdownlist in gridview,edit,delete,update in grdivew.In this post i will show how to avoid the post back while doing the sorting and paging in gridview.For this we need the set the EnableSortingAndPagingCallbacks to true,then it can perform client side callbacks to fetch the data.If we are using Template field.This property can not support.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Gridview Paging and Sorting with out postback</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GvSales" AllowSorting="True" Runat="server"
 EnableSortingAndPagingCallbacks="true" AllowPaging="true" 
AutoGenerateColumns="False" DataSourceID="SalesDb" 
       PageSize="4">
<Columns>
            <asp:BoundField DataField="SalesID" HeaderText="SalesID"
                 SortExpression="SalesID" />
             <asp:BoundField DataField="SalesPersonName" HeaderText="SalesPersonName"
                SortExpression="SalesPersonName" />
             <asp:BoundField DataField="SaleCity" HeaderText="SalesCity" SortExpression="SaleCity" />
             <asp:BoundField DataField="SalesAmt" HeaderText="Samount"
                 SortExpression="Samount" />
          </Columns>
       </asp:GridView>
<asp:SqlDataSource ID="SalesDb" runat="server"
            ConnectionString="<%$ ConnectionStrings:bhaskarConnectionString %>"
            SelectCommand="SELECT * FROM [Sales_Orders]"></asp:SqlDataSource>
 </div>
 </form>
</body>
</html>
Paging and sorting in Gridview

Tuesday, April 30, 2013

How to send a mail in asp.net

Title: How to send an email in asp.net using c#.net

Description:
In previous posts i have given send a mail with attachment in asp.net,Send mail using service,send a Email with html Format in Asp.Net.In the same way i just given an example on sending email concept in asp.net.The following example has two text boxes which are used to give the subject and name to mail message
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Send a mail in asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtSub" runat="server"></asp:TextBox>
<asp:TextBox ID="txtbody" runat="server"></asp:TextBox>
<asp:Button ID="btnsendmail" runat="server" Text="Send" onclick="btnsendmail_Click" />
</form>
</body>
</html>
Codebehind:
using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Mail.Net;

public partial class _sendmail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnsendmail_Click(object sender, EventArgs e)
{
try
{
SmtpClient SmtpmServer = new SmtpClient(SmtpserverName);
SmtpmServer.Credentials = new System.Net.NetworkCredential(Username, PWD);
MailMessage MlMsg = new MailMessage();
MlMsg.From = new MailAddress("bhaskar7698@gmail.com");
MlMsg.Body = txtbody.Text;;
MlMsg.IsBodyHtml = true;
MlMsg.To.Add(mulebhaskarareddy@gmail.com);
MlMsg.Subject = txtSub.Text;
SmtpmServer.Send(MlMsg);
Respose.Write("Mail sent successfully");
}
catch (Exception em)
{
Respose.Write(em.Message.Tostring());
}
}
}

Monday, April 29, 2013

Edit,delete,update records in gridview using sqldatasource in asp.net

Title: Edit Delete Update in Grid view in asp.net

Description:In previous post i have given how to edit,delete,update in grid view using row events,Bind data to grid view using SQL data source(here you can see how to use it).For this we need to set the  properties for grid view to enable the columns for db transaction.Might be get where the DML commands are executed?.The answer is the sqldatasource has properties to executes those commands when user perform those action on grid view

Example:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="OrderGrid.aspx.cs" Inherits="OrderGrid" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GvOrder" AllowSorting="True" Runat="server"
AutoGenerateEditButton="True" AutoGenerateDeleteButton="True" AutoGenerateColumns="False" DataSourceID="OrdrDb">
<Columns>
<asp:BoundField DataField="OrderID" HeaderText="OrderID"
SortExpression="OrderID" />
<asp:BoundField DataField="OrderName" HeaderText="OrderName"
SortExpression="OrderName" />
<asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
<asp:BoundField DataField="Address" HeaderText="Address"
SortExpression="Address" />
<asp:BoundField DataField="Amount" HeaderText="Amount"
SortExpression="Amount" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="OrdrDb" runat="server"
ConnectionString="<%$ ConnectionStrings:TestConnectionString %>"
SelectCommand="SELECT * FROM [Orders]" UpdateCommand="UPDATE [Orders] SET [OrderName] = @OrderName, [Phone] = @Phone,
[Address] = @Address, [Amount] = @Amount WHERE [OrderID] = @OrderID" DeleteCommand="Delete [Orders] WHERE [OrderID] = @OrderID"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
Result:
Display Order table table using Data source:
Bind data to gridview
Update Records using edit operation in grid view





Saturday, April 27, 2013

delete all gridview rows using checkbox in asp.net

Title:
How to delete rows in grid view using check box in asp.net

Introduction:
Hi all,I think you have seen so many articles and websites on grid view functionalists.But why i have given again the same delete records in grid view?".This question should get every one when you reading the title.The answer is,I would like to share the code or logic what i have done earlier in easy manner.Let go to the our task.I hope the below explanation is useful for us.Thanks to reading..

Example:
Some previous articles
select the multiple rows of grid view,
Get the check box in grid view using Jquery.
In this post i will show how to delete the all rows from grid view using check box in grid view.The design page have the grid view layout with item templates and and check which is used to select the specified rows in grid view to make functionality better
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Delete All Rows in grid view with check box in asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GvOrder" runat="server" AutoGenerateColumns="False" CellPadding="4" GridLines="None" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chk" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Order NO.">
<ItemTemplate>
<asp:Label ID="lb1OrderId" Text='<%#Eval("OrdrNo") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField><asp:TemplateField HeaderText="OrderName Name">
<ItemTemplate>
<%#Eval("Ordrname") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount">
<ItemTemplate>
<%#Eval("Amtsal") %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<asp:Button ID="btnchkall" runat="server" OnClick="btnchk_Click">Check All</asp:Button><asp:Button ID="btnDelete" runat="server" OnClick="btnDelete_Click">Delete</asp:Button>
</form>
</body>
</html>
Code behind:
The connection string settings in the config file has been made as per in the below snippet.It contain server and data base name.Before going to add this code we have to create a connection to database in web.config file. Here my connection name is "OrderDetailsConnection".

<appSettings>
<connectionStrings>
<add key="OrderDetailsConnection" value="server=bhaskar/SQLEXPRESS;database=Order_Db;uid=bhaskar;password=br123;" />
</connectionStrings>
</appSettings>

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class _GrdivewChkDelete : System.Web.UI.Page 
{
SqlConnection cn = new SqlConnection(ConfigurationSettings.AppSettings("OrderDetailsConnection");
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
BindOrdrGrid();
}
private void BindOrdrGrid()
{
SqlDataAdapter OrdrAd = new SqlDataAdapter("Select * from Order",ocn);
DataSet Ordrds = new DataSet();
OrdrAd.Fill(Ordrds);
GvOrder.DataSource = Ordrds;
GvOrder.DataBind();
}
protected void btnchkall_Click(object sender, EventArgs e)
{
CheckBox rchk;
for (int i = 0; i < GvOrder.Rows.Count; i++)
{
rchk = ((CheckBox)(GvOrder.Rows[i].FindControl("orbrcb")));
if (orbrcb.Checked == false)
//Check all check box in gridview
orbrcb.Checked = true;
}
}
protected void btnDelete_Click(object sender, EventArgs e)
{
CheckBox rchk;
String ordrId = String.Empty;
for (int i = 0; i < GvOrder.Rows.Count; i++)
{
rchk = ((CheckBox)(GvOrder.Rows[i].FindControl("orbrcb")));
if (orbrcb.Checked){//Get the Id from lable
ordrId +=((Label)(GvOrder.Rows[i].FindControl("lb1OrderId"))).Text + ",";
}
}//Get the Order_Id
ordrId = ordrId.Substring(0, ordrId.Length - 1);
cn.Open();
//Delete all grdivew records
SqlCommand cmd=new SqlCommand("delete from Order where Order_Id in("+ordrId.ToString()+")",cn);
cmd.ExecuteNonQuery();
BindOrdrGrid();
}
}
//In the above code i have used to delete the records using "IN"  in sql command.By using this we can delete the all records with in the list.Keep coming to get latest updates 

Tuesday, April 23, 2013

How to bind data to dropdownlist with arrarylist in asp.net


In previous post we have discussed on how to bind the Data in Gridview,Disable dropdownlist .In this post i will show how to bind data to dropdownlist using array list in asp.net.Here i will populate drop down for city names.
<html>
<head>
</head>
<body>
<form runat=server>
<asp:DropDownList id="ddlcity" runat="server" />
</form>
</body>
</html>
We have to used ispostback to avoid the populating drop down while every time loading the page

protected void Page_Load(Object Sender, EventArgs E) 
{
if (!IsPostBack) {
ArrayList citynames = new ArrayList();
citynames.Add ("NewYork");
citynames.Add ("Hyderabad");
citynames.Add ("Bombay");
ddlcity.DataSource = citynames;
ddlcity.DataBind();
}
}

Monday, April 22, 2013

how to get selected items from checkboxlist in asp.net c#


In previous post i have given how to get the id of checkbox using jqury ,check all checkbox in gridview.In this post i will show how to get the selected values of check box list in asp.net.I below piece of code i have looping thorough the check box list items on button click event .Then the resultant value has assigned to string
<html>
<head>
</head>
<body>
<form>
<asp:CheckBoxList ID="ChkOrdrList" runat="server">
<asp:ListItem>COmputers</asp:ListItem>
<asp:ListItem>Books</asp:ListItem>
<asp:ListItem>Laptop</asp:ListItem>
<asp:ListItem>Ipad</asp:ListItem>
</asp:CheckBoxList>
<div>   
<asp:Button ID="btngetOrdr" Text="Ok" OnClick="btlgetOrder_Click" runat="server" />
</div>
<asp:TextBox ID="txtOrdername" runat="server" />
</form>
</body>
</html>

public void btlgetOrder_Click(object Source, EventArgs e)
{
String strOrdr = "Checkboxlist selected Item is:";
for (int i = 0; i < ChkOrdrList.Items.Count; i++)
{
if (ChkOrdrList.Items[i].Selected)
{
strOrdr = strOrdr +","+ ChkOrdrList.Items[i].Text;
}
}
txtOrdername.Text = strOrdr;
}

how to create usercontrol with user defined properties in asp.net

In previous posts i have given examples on how to convert string to data table in asp.net,Gridview Examples,Add colums dynamically to gridview.Her i will show how to develop a scrolling label control with text,color,font  properties using csharp.The timers are used to get the time inteval of process
Place label control
Place Timer Control with enabled =true
Place one more timer with enabled =false

Code fro timer_TickEvent(--)
{
lblname.Top=lblname.Top-5;
if(lblname.Top<0)
{
Timer1.Enable=false;
Timer2.Enable=True;
}
}
Code for time2_tick event(...)
{
lblname.Top=lblname.Top+5;
if(lblname.Top>250)
{
Timer1.Enable=false;
Timer2.Enable=True;
}
}
//Code in General Declaration
//create properties
Publlic string Ltext
{
set {lblname.Text=value;}
get{return lblname.Texte;}
}

Publlic string Lbcolor
{
set {lblname.BackColor=value;}
get{return lblname.BackColor;}
}

Publlic string Lfont
{
set {lblname.Font=value;}
get{return lblname.Font;}

}
Publlic int Lspeed
{
set {timer1.interval=value;
timer1.interval=value;
}
get{return timer1.Interval;}

}
Build the project
note:Scrolling lable.dll is created under d:\myprojects\scrolling label \bin\debug folder
Open page and drag scrolling.dll into my controls tab of toolbox.Then user control slable has been added to tool box

Tuesday, January 8, 2013

Disable/enable Dropdownlist in asp.net using c#.net

In this post i will show how to disable a drop down in asp.net using c#.net.Here i have used two drop down lists to perform this task. Whenever  the first drop down  selected then another drop down will be disabled
Aspx:
<asp:DropDownList ID="ddloption" runat="server" onselectedindexchanged="ddloption_SelectedIndexChanged" 
       AutoPostBack="True">
<asp:ListItem>Please select</asp:ListItem>
<asp:ListItem>Hyderabad</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlcode" runat="server" 
AutoPostBack="True">
<asp:ListItem>Please select</asp:ListItem>
</asp:DropDownList>
Code :
protected void ddloption_SelectedIndexChanged(object sender, EventArgs e)
{
ddlcode.Enabled = false;
}
The above code is for drop down selected index event for first drop down list

Bel