小弟刚学SL,现在在数据绑定这里遇到问题,请教各位大大,其中:lb_Books是listBox
WebRequest request = asyncResult.AsyncState as WebRequest;
Stream stream = request.EndGetRequestStream(asyncResult);
StreamWriter sw = new StreamWriter(stream);
// sw.Write(string.Format("No={0}",lb_Books.SelectedIndex.ToString()));//这样写直接报跨线程访问无效
sw.Write(string.Format("No={0}", new GetValue(GetVal)));//这种自定义委托实现
sw.Flush();
sw.Close();
sw.Dispose();
stream.Close();
stream.Dispose();
//以下是委托部分:
private delegate string GetValue();
private string GetVal()
{
return lb_Books.SelectedIndex.ToString();
}
//ashx中,在获取提交的No时,得到时数据:
context.Request.Form["No"]
结果:"SilverLightControl.SilverlightControl GetValue"本来应该获取的是lb_Books选中的索引值
context.Response.Write(context.Request.Form["No"]);