c# - how to get value of selected row in DropDown and Grid view -
i have 2 question... 1. have gridview bind data form database way
datasource = company.getallcompany(); dgvcompanys.autogeneratecolumns = false; dgvcompanys.datasource = _datasource; dgvcolnameen.datapropertyname = "myenglishname"; dgvcoladdress.datapropertyname = "myaddress"; dgvcolcode.datapropertyname = "mycode"; dgvcolkeyid.datapropertyname = "mykeyid";
it's worked want keyid of selected row
private void dgvcompanys_selectionchanged(object sender, eventargs e) { if (dgvcompanys.selectedrows.count > 0) { mtxtcode.text=dgvcompanys.selectedrows[0].cells[1].value.tostring(); } }
this code have error object reference not set instance of object.
have this? question 2.i have textboxdropdownlist(devcomponent) , sourced way:
list<company> _datacompany; _datacompany = company.getallcompany(); cmbcompany.displaymember = "myenglishname"; cmbcompany.datasource = _datacompany;
that worked correctly want keyid of rows selected in dropdown have do?
question 1 : perhaps dataset have 1 column, right code :
dgvcompanys.selectedrows[0].cells[0].value.tostring();
question 2 not clear me, can access selected item :
dropdown.selecteditem.tostring()
Comments
Post a Comment