0
我想在我的GridView中使用一個按鈕來傳遞ID從我選擇的行到我的數據庫,我將它與數據庫中的GUID進行比較,然後將它傳遞給我的「顯示」功能從數據庫中獲取帖子。如何使用從gridwiew_rowcommand返回的值來搜索數據庫?
現在我不知道如何從我的按鈕中獲取對象「visadabok」到我的「顯示」。
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
}
else
{
//TextBox68.Text = Request["ID"];
if (!string.IsNullOrEmpty(TextBox68.Text))
{
Show(GridView1_RowCommand());
}
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Valj")
{
var valj = new Guid((string)e.CommandArgument);
var visadagbok = (from x in DagbokFactoryBase.All
where (x.ID == valj)
select x).FirstOrDefault();
return visadagbok;
}
}
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="AddButton" runat="server"
CommandName="Valj"
CommandArgument="<%# ((GridViewRow) Container).ID %>"
Text="Gå till" />
</ItemTemplate>
</asp:TemplateField>
'GridView1_RowCommand'是'void' - 因此它實際上並不返回任何東西。你想把它歸還給「哪裏」? – Darren