c# - How to Bind a GridView from database -
how bind gridview?
i want display table data in gridview.
i have createed sql table empdetail
columns id, name, salary data
try below code according scenario
i hope helps you
protected void gridviewbind () { using (sqlconnection con = new sqlconnection("data source=rapidprogramming;integrated security=true;initial catalog=rpdb")) { con.open(); sqlcommand cmd = new sqlcommand("select name,salary table", con); sqldatareader dr = cmd.executereader(); gridview1.datasource = dr; gridview1.databind(); con.close(); } }
<asp:gridview id="gridview1" runat="server" backcolor="white" bordercolor="#3366cc" borderstyle="none" borderwidth="1px" cellpadding="4" style="text-align: center; margin-left: 409px" width="350px"> <footerstyle backcolor="#99cccc" forecolor="#003399" /> <headerstyle backcolor="#003399" font-bold="true" forecolor="#ccccff" /> <pagerstyle backcolor="#99cccc" forecolor="#003399" horizontalalign="left" /> <rowstyle backcolor="white" forecolor="#003399" /> <selectedrowstyle backcolor="#009999" font-bold="true" forecolor="#ccff99" /> <sortedascendingcellstyle backcolor="#edf6f6" /> <sortedascendingheaderstyle backcolor="#0d4ac4" /> <sorteddescendingcellstyle backcolor="#d6dfdf" /> <sorteddescendingheaderstyle backcolor="#002876" /> </asp:gridview>;
Comments
Post a Comment