There is a simple way to view data in gridview.
We manage it by using datasource and then choose your stored procedure.
But this time, I don't use it.
I make my grid view by drag an drop the gridview from toolbox.
This is my.aspx
<asp:GridView ID="gridviewKelas" runat="server" AutoGenerateColumns="False" Width="100%" CssClass="table table-bordered table-striped" AllowPaging="true" OnRowUpdating="gridviewDataKaryawan_RowUpdating" DataKeyNames="Class_Id" OnRowEditing="gridviewKelas_RowEditing" OnRowCancelingEdit="gridviewKelas_RowCancelingEdit" OnRowDeleting="gridviewKelas_RowDeleting">
<Columns>
<asp:TemplateField HeaderText="ID Kelas" ItemStyle-Width="150">
<ItemTemplate>
<asp:Label ID="lblClass_Id" runat="server" Text='<%# Eval("Class_Id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Nama Kelas" ItemStyle-Width="150">
<ItemTemplate>
<asp:Label ID="lblClass_Name" runat="server" Text='<%# Eval("Class_Name") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtClassName" runat="server" Text='<%# Eval("Class_Name") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorAlamat" runat="server" ErrorMessage="Nama kelas tidak boleh kosong" ControlToValidate="txtClassName"></asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status Kelas" ItemStyle-Width="150">
<ItemTemplate>
<asp:Label ID="lblStatus" runat="server" Text='<%# Eval("Status") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtStatus" runat="server" Text='<%# Eval("Status") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorNomorHP" runat="server" ErrorMessage="Status kelas tidak boleh kosong" ControlToValidate="txtStatus"></asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Link" ShowEditButton="true" ShowDeleteButton="true" ItemStyle-Width="150"/>
</Columns>
</asp:GridView>
Then in my.aspx.cs while I reload the page I call the method that declare the stored procedure
BED_MANAGEMET_APP.Models.M_Class kelas = new Models.M_Class();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
private void BindData()
{
gridviewKelas.DataSource = kelas.GetDataAll(); << the method that call stored procedure
gridviewKelas.DataBind();
}
-------
:D :D
No comments:
Post a Comment