Today we will learn how to use gridview in asp.net using c# to display records using dataset,datatable?
In .cs page
GridView1.DataSource = DataTable or Dataset
GridView1.DataBind()
In aspx page
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField HeaderText="CandidateName" DataField="name" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField HeaderText="Email" DataField="emailid" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField HeaderText="DateTime" DataField="DateTime" ItemStyle-HorizontalAlign="Center" />
<asp:TemplateField HeaderText="Phone" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="CanName" runat="server" Text='<% #Bind("fname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<ItemTemplate>
<asp:Label ID="LblClass" runat="server" Text='<%#Bind("Class") %>'>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="DDLClass" Width="100%" runat="server" DataSource='<%#Class%>' DataTextField="Class" DataValueField="id" >
<asp:listitem value="1" Text="1"></asp:listitem>
<asp:listitem value="2" Text="2"></asp:listitem>
<asp:listitem value="3" Text="3"></asp:listitem> </asp:DropDownList>
</EditItemTemplate>
</Columns>
</asp:GridView>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment