asp.net - GridView DataBind() not working on Submit button -
i have grid view on page, on clicking submit button, row added database table grid view not update itself, when navigate page, , come again, grid view shows newly added record.
i cant figure out why happening, check number of rows in grid using debug mode, grid's rows.count shows 1 row, grid cant display it
and not doing thing gridview's data source in code behind, binded sqldatasource in design view.
code behind submit button:
protected void btnsubmit_click(object sender, eventargs e) { eauctionentities ea = new eauctionentities(); bid b = new bid(); b.bidderemail = session["useremail"].tostring(); b.biddername = session["username"].tostring(); b.bidend = convert.todatetime(txtendson.text); b.bidplacedon = datetime.now.date; b.bidprice = convert.todecimal(txtyourbid.text.trim()); b.isavailable = true; b.prod = convert.toint32(request.querystring["id"]); b.bidminprice = convert.todecimal(txtbidstart.text.trim()); b.iswon = false; ea.bids.addobject(b); if (ea.savechanges() == 1) { lblbid.text = "bid added !"; gvcurrentbids.databind(); } ea.dispose(); } aspx code gridview , datasource:
<asp:gridview id="gvcurrentbids" runat="server" backcolor="white" bordercolor="#cccccc" borderstyle="none" borderwidth="1px" cellpadding="3" datasourceid="dstotalbids" width="100%"> <columns> <asp:boundfield datafield="biddername" headertext="biddername" sortexpression="biddername" /> <asp:boundfield datafield="bidprice" headertext="bidprice" sortexpression="bidprice" /> <asp:boundfield datafield="bidend" headertext="bidend" sortexpression="bidend" /> </columns> <footerstyle backcolor="white" forecolor="#000066" /> <headerstyle backcolor="#006699" cssclass="headerfreez" font-bold="true" forecolor="white" /> <pagerstyle backcolor="white" forecolor="#000066" horizontalalign="left" /> <rowstyle forecolor="#000066" /> <selectedrowstyle backcolor="peachpuff" /> <sortedascendingcellstyle backcolor="#f1f1f1" /> <sortedascendingheaderstyle backcolor="#007dbb" /> <sorteddescendingcellstyle backcolor="#cac9c9" /> <sorteddescendingheaderstyle backcolor="#00547e" /> </asp:gridview> <asp:sqldatasource id="dstotalbids" runat="server" connectionstring="<%$ connectionstrings:eauctionconnectionstring %>" selectcommand="select [biddername], [bidprice], [bidend] [bid] (([isavailable] = @isavailable) , ([prod] = @prod))"> <selectparameters> <asp:parameter defaultvalue="true" name="isavailable" type="boolean" /> <asp:querystringparameter name="prod" querystringfield="id" type="int32" /> </selectparameters> </asp:sqldatasource> i have tried calling grid's databind method inside page load, cant update after submit button click
Comments
Post a Comment