Sunday, January 11, 2015

Import Excel Data to Datatable or Dataset or Gridview in Asp.net C#

Introduction:

Here I will explain how to Import excel data into datatable or dataset in ASP.NET C#, or Import data from excel to gridview in asp.net using OLEDB in C#

The below code in your aspx page
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Read and Display Data From an Excel File (.xsl or .xlsx) in ASP.NET</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<b>Please Select Excel File: </b>
<asp:FileUpload ID="fileuploadExcel" runat="server" />  
<asp:Button ID="btnImport" runat="server" Text="Import Data" OnClick="btnImport_Click" />
<br />
<asp:Label ID="lblMessage" runat="server" Visible="False" Font-Bold="True" ForeColor="#009933"></asp:Label><br />
<asp:GridView ID="grvExcelData" runat="server">
<HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" />
</asp:GridView>
</div>
</form>
</body>
</html>

How to Get Gridview Footer Controls id in JavaScript

Introduction:

Here I will explain how to access asp.net gridview footer control ids or values in JavaScript or find controls inside gridview in JavaScript or find asp.net gridview footer controls (textbox, dropdownlist, checkbox, radio button etc..) values or ids in JavaScript.

Syntax to Get Gridview Footer Controls in JavaScript

<script type="text/javascript">
function GetGridFooterRowvalues() {
var fuid = document.getElementById('<%=((TextBox)gvUserInfo.FooterRow.FindControl("txtUserId")).ClientID %>');
if (fuid != null && funame != null && fueducation != null) {
alert('UserId:' + fuid.value)
}
}
</script>

Saturday, January 10, 2015

How to Delete Row from Gridview With JavaScript Confirmation in C#, Asp.net

Introduction:

Here I will explain how to delete row from gridview in asp.net using c# , with Java Script confirmation message . when you Click on Delete button it will show you confirmation box to Delete Yes or No.

The below code in your .aspx page

Tuesday, January 06, 2015

How to Count Number of Online Users in Asp.Net Using C#, VB.NET

 I will explain how to count number of online users of website in asp.net using C#

 To get number of online visitors for website we need to use methods in Global.asax file for that first add Global.asax file in your application

Open Visual Studio ->> Create New Website ->>  Right click on Solution Explorer -->> Select Add New Item -->>  Select Global Application Class file and click OK

Now open Global.asax file and write the code like as shown below

Difference between String and Stringbuilder in C#, Asp.net

 I will explain what is difference between string and stringbuilder in c# using asp.net.

String:
String is immutable. Immutable means once we create string object we cannot modify. Any operation like insert, replace or append happened to change string simply it will discard the old value and it will create new instance in memory to hold the new value.

Example:
string str = "AoA";
// create a new string instance instead of changing the old one
str += "Good";
str += " morning";

Copy Selected Gridview Rows to Another Gridview in Asp.net

Here I will explain how to Copy Selected Gridview Rows to Another Gridview in Asp.netusing c#, vb.net

Here is the HTML of the page with 2  Gridview

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Tranfer selected gridview rows to another gridview in Asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="gvDetails" AutoGenerateColumns="false" CellPadding="5" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>

Tuesday, December 30, 2014

Checkboxs Enable / Disable in Asp.net Gridview Based on Condition in C#, VB.NET

Introduction:

Here I will explain how to enable or disable checkbox in gridview based on condition in asp.net  using C# and VB.NET.

We use gridview rowdatabound event for enable / disable checkbox in gridview based on conditions.
The below Code is the Event for enable / disable checkbox.

protected void gvDetails_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
CheckBox chk = (CheckBox)e.Row.FindControl("chkSelect");
if (e.Row.Cells[4].Text == "Hyderabad")
{
chk.Enabled = false;
}
else
{
chk.Enabled = true;
}
}
}

How to Get Selected Row Cell value from Gridview in Asp.net C#

Introduction:

Here I will explain how to get selected row cell value from gridview in asp.net using C# and VB.NET or get cell values from selected row cell values from gridview when checkbox selected in asp.net using C# and VB.NET.

The below code to get checkbox selected row values from gridview.
foreach(GridViewRow  gvrow in gvDetails.Rows)
  {
  CheckBox chk = (CheckBox)gvrow.FindControl("chkSelect");
  if (chk != null & chk.Checked)
  {
  str += gvDetails.DataKeys[gvrow.RowIndex].Value.ToString() + ',';
  strname += gvrow.Cells[2].Text+',';
  }
}

Monday, December 29, 2014

How to highlight search results in Gridview using asp.net C#

Introduction:
In this article I will explain how to search records in gridview and highlight search keywords in gridview using asp.net.

Here my requirement is I have a web page that contains Search textbox, button and gridview with some data now I want to display data in gridview whenever user enter text in textbox and hit search button after that I need to highlight that resultant keyword in gridview using asp.net. To implement this first design the table in database and give name UserInfomation

ASP.Net - Add Items to Dropdownlist Programmatically on Button Click in C#

Introduction:

Here I will explain how to add items to dropdownlist programmatically on button click in asp.net using c# and vb.net or dynamically add items to dropdownlist on button click in asp.net using c# and vb.net.

To implement this first create new application and write the code in aspx page as shown below
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Dynamically Add items to dropdownlist in asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<b>Enter Name</b><asp:TextBox ID="txtName" runat="server" /><asp:Button ID="btnAdd"
runat="server" Text="Add Items" onclick="btnAdd_Click" /><br />
Select UserName: <asp:DropDownList ID="ddlUsername" runat="server"/>
</div>
</form>
</body>
</html>