我正在使用一个网格视图,我希望能够单击每一行以显示我正在显示的对象中的另一个字段。感觉很容易解决,但也许我很愚蠢,因为我在任何地方都找不到它......
ASP代码:
<asp:GridView ID="gvMessages" runat="server" AutoGenerateColumns = "false"
CaptionAlign="NotSet" CellPadding="5">
<Columns>
<asp:BoundField HeaderText="Avsändare" DataField="Sender" />
<asp:BoundField HeaderText="Ämne" DataField="Head" />
</Columns>
</asp:GridView>
代码隐藏:
protected void Page_Load(object sender, EventArgs e)
{
gvMessages.DataSource = con.GetMails(con.GetId(Membership.GetUser().UserName));
gvMessages.DataBind();
}
不确定所有这些对于问题来说都是必要的,但这是我的 wcf 项目中的方法,它用对象信息填充我的复合类
public List<MailInfo> GetMails(int id)
{
using (var client = new datingEntities())
{
var result = client.Mail.Where(x => x.SentTo == id).Select(x => new MailInfo
{
Message = x.Mail1,
Reciever = x.SentTo,
Read = (bool)x.IsRead,
Sender = (int)x.SentFrom,
Head = x.Subject
}).ToList();
return result;
}
}
复合类:
[DataContract]
public class MailInfo : Mail
{
[DataMember]
public string Message { get; set; }
[DataMember]
public int Reciever { get; set; }
[DataMember]
public bool Read { get; set; }
[DataMember]
public int Sender { get; set; }
[DataMember]
public string Head { get; set; }
}