how to binding gridview with data from two different tables C# -
how can binding gridview data 2 different tables? have 3 tables: players, playerteam , teams. gridview has next data: playerid, name, surname, ... table players, , teamid, teamname... table teams. table playerteam marge tables players , teams via ids. i'am using tableadapter solve problem.
when want edit row in gridview, make changes in form (change data in textbox) , select team dropdownlist, can't save changes.
using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols; namespace rukomet { public partial class igracui : system.web.ui.page { dsigrac.tbligracrow igrac; dsklub.tblklubrow klub; protected void page_load(object sender, eventargs e) { if (this.ispostback) return; this.ucitajklub(); this.dohvatiigraca(); this.prikaziigracevepodatke(); } private void pokupipodatkesforme() { this.igrac.maticnibroj = this.txtmaticnibroj.text; this.igrac.ime = this.txtime.text; this.igrac.prezime = this.txtprezime.text; this.igrac.brojdresa = this.txtbrojdresa.text; this.igrac.pogoci = convert.toint32(this.txtpogoci.text); this.igrac.opomene = convert.toint32(this.txtopomene.text); this.igrac.dvijeminute = convert.toint32(this.txtdvijeminute.text); this.igrac.diskvalifikacija = convert.toint32(this.txtdiskvalifikacija.text); this.igrac.lijecnicki = convert.todatetime(this.txtlijecnicki.text); this.klub.klubid = convert.toint32(this.ddlklubovi.selectedvalue); } private void prikaziigracevepodatke() { if (igrac.igracid == -1) return; this.txtmaticnibroj.text = igrac.maticnibroj; this.txtime.text = igrac.ime; this.txtprezime.text = igrac.prezime; this.txtbrojdresa.text = igrac.brojdresa; this.txtpogoci.text = igrac.pogoci.tostring(); this.txtopomene.text = igrac.opomene.tostring(); this.txtdvijeminute.text = igrac.dvijeminute.tostring(); this.txtdiskvalifikacija.text = igrac.diskvalifikacija.tostring(); this.txtlijecnicki.text = igrac.lijecnicki.toshortdatestring(); if (this.viewstate["selected"] != null) { ddlklubovi.selectedvalue = convert.tostring(this.viewstate["selected"]); } } private void dohvatiigraca() { dsigrac.tbligracdatatable tbligrac = new dsigrac.tbligracdatatable(); if (request.params["igracid"] == null) { this.igrac = tbligrac.newtbligracrow(); this.igrac.igracid = -1; } else { dsigractableadapters.tbligractableadapter adapterigrac = new dsigractableadapters.tbligractableadapter(); int id = convert.toint32(this.request.params["igracid"]); adapterigrac.fillbyigracid(tbligrac, id); this.igrac = (dsigrac.tbligracrow)tbligrac.rows[0]; } } void ucitajklub() { dsigrac.tblklubdatatable klub = new dsigrac.tblklubdatatable(); dsigractableadapters.tblklubtableadapter adapterklub = new dsigractableadapters.tblklubtableadapter(); adapterklub.fill(klub); this.ddlklubovi.datatextfield = "imekluba"; this.ddlklubovi.datavaluefield = "klubid"; this.ddlklubovi.datasource = klub; this.ddlklubovi.databind(); } protected void btnodustani_click(object sender, eventargs e) { this.response.redirect("glavnaforma.aspx"); } protected void btnspremi_click(object sender, eventargs e) { this.dohvatiigraca(); this.pokupipodatkesforme(); dsigractableadapters.tbligractableadapter adapterigrac = new dsigractableadapters.tbligractableadapter(); if (this.igrac.igracid == -1) { adapterigrac.insert( this.igrac.maticnibroj, this.igrac.ime, this.igrac.prezime, this.igrac.brojdresa, this.igrac.pogoci, this.igrac.opomene, this.igrac.dvijeminute, this.igrac.diskvalifikacija, this.igrac.lijecnicki); this.klub.klubid); } else { adapterigrac.update(this.igrac); } this.response.redirect("glavnaforma.aspx"); } } }
you should post code better answer think understand asking. accomplish use c# webgrid in html queries 3 tables this:
@{ var db=database.open("contracts"); var selectcommand = "select requests.*, contractors.agency+'/'"+ "+contractors.firstname+' '+contractors.lastname contractor,programs.division "+ "from requests, contractors, programs "+ "where contractnumber not null "+ "and contractnumber <> '' "+ "and scannedcontractdate not null "+ "and amendmentcount = 0 "+ "and contractors.id = requests.contractorid "+ "and requests.programid = programs.id "; } <h2>page title</h2> <div>@grid.gethtml( tablestyle: "grid", headerstyle: "head", alternatingrowstyle: "alt", columns: grid.columns( grid.column("division"), grid.column("contractnumber", header:"contract number"), grid.column("contractor"), grid.column("startdate", header:"start date", cansort: true), grid.column("enddate", header:"end date", cansort: true), grid.column("amount"), grid.column("scannedcontractdate", header:"contract date", cansort: true), grid.column("maxamend", header:"amendments") ) ) </div>
i hope answers question!
Comments
Post a Comment