write a C# program to display the customer number and name in a data grid. Forma
ID: 3765474 • Letter: W
Question
write a C# program to display the customer number and name in a data grid. Format the grid control so that it is professionally aesthetically appealing. Allow the user to add records to the database. If your designed solution involves the use of a disconnected database, post the changes back to the live database. Be sure to check the database records to make sure the changes have been made. For an added challenge, write program statements, as opposed to using the database configuration tools wizard.
Explanation / Answer
drop the datagrid
<asp:DataGrid ID= "datagrid1" runat="server"></asp:DataGrid>
<html >
<head runat="server">
<title>Paging</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataGrid ID= "datagrid1" runat="server" AllowPaging="True" BackColor="#DEBA84" BorderColor="#804000" BorderStyle="None" BorderWidth="2px" CellPadding="3" PageSize="4" CellSpacing="2" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" ShowFooter="True" >
<SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" Mode="NumericPages"
PageButtonCount="4" />
<ItemStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
</asp:DataGrid>
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=(local);Initial Catalog=customer;Integrated Security=True");
SqlDataAdapter da = new SqlDataAdapter("select*from customer",con);
con.Open();
DataSet ds = new DataSet();
da.Fill(ds);
datagrid1.DataSource = ds;
datagrid1.DataBind();
con.Close();
}
protected void datagrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
datagrid1.CurrentPageIndex = e.NewPageIndex;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.