HOW TO GET LIST TYPE VALUE IN TEXTBOX IN SILVERLIGHT ??


dear all,
 
  want display emp name db textbox in silverlight. see below code.
 
//################################################################################################################ 
private void button1_click(object sender, routedeventargs e) 
{
servicereference1.service1client conenction = new servicereference1.service1client();
conenction.getemployeecompleted += new eventhandler<servicereference1.getemployeecompletedeventargs>(getallemployee);
conenction.getemployeeasync();
 
//##########################################  problem raising area / question area  ######################################################################
void getallemployee(object sender, servicereference1.getemployeecompletedeventargs e)
{

datagridview1.itemssource = e.result.tolist();       // line working excellent display in gridview

txt_empname.text = e.result.tostring();  // line not display data in textbox. //this displaying [silverlightapp1.service reference1.employee] in emptextbox.

//messagebox.show(txt_empname.text);

}

//##################  my service code working here working fine ###############################################
public class service1
{
string conenctionstring = system.configuration.configurationmanager.connectionstrings["swe"].connectionstring;
[operationcontract]
public list<employee> getemployee()
{
// employee employee = new employee();
list<employee> employee = new list<employee>();
using (sqlconnection con = new sqlconnection(conenctionstring))
{
using (sqlcommand cmd = new sqlcommand())
{
cmd.connection = con;
cmd.commandtext = "select empname employee empno=101";
cmd.commandtimeout = 600;
con.open();
sqldatareader reader = cmd.executereader();
while (reader.read())
{
employee emp = new employee();
// emp.empno = convert.toint32(reader[0].tostring());
emp.empnme = reader[0].tostring();  //reading emp_name.
//emp.empaddres = reader[2].tostring();
//emp.empsalary = convert.toint32(reader[3].tostring());
//emp.empeducation = convert.toint32(reader[4].tostring());
employee.add(emp);
}
}
}
return employee.tolist();
}
 
//###########################################  end of service code here  ################################################### 

you're trying put entire collection in textbox.

you need cast list , pick one.

you use linq, like

txt_empname.text = (string)e.result.tolist().firstordefault(); 

or convert tolist once , use first 1 of them ( 0 ) textbox, lot itemssource.


hope helps.

technet articles: wpf: mvvm step 1; technet articles




Silverlight  >  Silverlight 5



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

BizTalk Server 2013 Azure VM Log Shipping and HA for hosts

How to Share webservice object to all user