c# - Gridview not appearing -
i somehow come strange error. gridview won't appear. here code - first .aspx
markup:
<asp:gridview id="zakljucani" runat="server" autogeneratecolumns="false" onrowcommand="zakljucani_rowcommand" pagesize="300" height="127px" style=" visibility:visible; border-color:red" > <columns> <asp:boundfield datafield="korisnickoime" headertext="korisnicko ime" visible="true" /> <asp:boundfield datafield="mail" headertext="mail" visible="true" /> <asp:boundfield datafield="datumzakljucavanja" headertext="datum vrijeme zaključavanja" /> <asp:boundfield datafield="hourselapsed" headertext="protekli sati" /> <asp:templatefield headertext="otključaj"> <itemtemplate> <asp:button id="button1" commandargument='<%#eval("korisnickoime")%>' runat="server" enabled='<%#convert.toint32(eval("hourselapsed"))>24%>' text="otključaj" /> </itemtemplate> </asp:templatefield> </columns> </asp:gridview>
and code
protected void page_load(object sender, eventargs e) { getdata(); } private void getdata() { string cs = configurationmanager.connectionstrings["konekcija"].connectionstring; using (sqlconnection con = new sqlconnection(cs)) { sqlcommand cmd = new sqlcommand("spzakljucaniracuni", con); cmd.commandtype = commandtype.storedprocedure; con.open(); zakljucani.datasource = cmd.executereader(); zakljucani.databind(); } } private void enableuseraccount(string username) { string cs = configurationmanager.connectionstrings["konekcija"].connectionstring; using (sqlconnection con = new sqlconnection(cs)) { sqlcommand cmd = new sqlcommand("otkljucajzakljucaniracun", con); cmd.commandtype = commandtype.storedprocedure; sqlparameter paramusername = new sqlparameter() { parametername = "@korisnickoime", value = username }; cmd.parameters.add(paramusername); con.open(); cmd.executenonquery(); } } protected void zakljucani_rowcommand(object sender, gridviewcommandeventargs e) { enableuseraccount(e.commandargument.tostring()); getdata(); }
the problem gridview doesn't appear. today worked fine, , later not.
i don't know if there error, or problem when binding. hope find mistake if there one.
add sqldatareader
sqldatareader dr; dr = cmd.executereader(); zakljucani.datasource = dr;
Comments
Post a Comment