Saturday, June 28, 2008

gridview with SqlDatasource

<asp:GridView ID="gv" Runat="Server"
AutoGenerateColumns="true"
BorderColor="#000080"
BorderWidth="2px"
HorizontalAlign="Center"
Width="90%" >
</asp:GridView>

codebehind file/////////
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SqlDataSource Source= new SqlDataSource();
Source.ConnectionString = ConfigurationManager.
ConnectionStrings["ConnectionString"].ConnectionString;
Source.DataSourceMode = SqlDataSourceMode.DataReader;
Source.ProviderName = "System.Data.SqlClient";
Source.SelectCommand = "SELECT companyname, companyaddress, companycity FROM companydetail ORDER BY companyname";
gv.DataSource = Source;
gv.DataBind();
}
}

No comments :

Post a Comment

AJAX, asp, Asp.net, asp.net and sql server security, Asp.net IntemIndex, C#, Css, DataBinder.Eval, DataKeyNames, Datalist, Datapager, DataSet, DataTable, DropDownList, FindControl, gridview, JavaScript, jquery, Listview, Paging, Regex, RegularExpression, Repeater, Server side validation, Sql Server, timer, timercallback, Validation, XML, xmlnode, XPath