How to use DataRow class in ASP.NET

Lets take an example to bind DropDownList using DataRow class.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <asp:Button ID="Button1" runat="server" Height="37px" onclick="Button1_Click"
            Text="Bind DropDownList" Width="130px" />
        <br />
        <br />
        <asp:DropDownList ID="DropDownList1" runat="server">


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 Default4 : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)

    protected void Button1_Click(object sender, EventArgs e)
        using (SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True"))
            SqlCommand cmd = new SqlCommand("select * from [mytab]", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
                        if (DropDownList1.Items.Capacity == 0)
                            foreach (DataRow dr in dt.Rows)
                                string name = dr["name"].ToString();



How to use DataRow class in ASP.NET

How to use DataRow class in ASP.NET How to use DataRow class in ASP.NET Reviewed by Jacob Lefore on September 19, 2013 Rating: 5

No comments