今天我有幾個問題,我是ASP和C#中的新手,所以我需要一些幫助,問題在於下一個。 (我會嘗試最具體的可能)在gridview中處理按鈕事件
我已經創建了一個GridView,我從我的數據庫中填充,在我的GridView中,我添加了一列按鈕(詳細信息),這裏是問題。當我點擊一個按鈕時,我需要在瀏覽器中打開一個新窗口(我如何從C#執行此操作,或者僅在客戶端使用javascrip?),並且在需要顯示數據庫中的詳細信息後,首先需要從該按鈕的行中獲取ID,即GridView中的列ID,那麼如何獲取ID列的行值(單擊該按鈕)?
這是我的ASP代碼的GridView
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="false"
AllowPaging="true" CellPadding="3"
OnPageIndexChanging="grdData_PageIndexChanging" PagerSettings-Position="Top"
PagerStyle-ForeColor="Orange"
PageSize="10">
<Columns>
<asp:BoundField DataField="id" HeaderText="ID" />
<asp:BoundField DataField="request_type" HeaderText="RequestType"/>
<asp:BoundField DataField="priority" HeaderText="Priority" />
<asp:BoundField DataField="modality" HeaderText="Modality" />
<asp:BoundField DataField="name" HeaderText="Name" />
<asp:BoundField DataField="start_date" HeaderText="Start Date"/>
<asp:BoundField DataField="end_date" HeaderText="End Date" />
<asp:BoundField DataField="hour" HeaderText="Start Hour" />
<asp:BoundField DataField="requester" HeaderText="Requester Name" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Details" runat="server"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"
Text="Details" CssClass="botonformulario"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
我試試這個在後面的代碼,但我認爲不能正常工作。
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView1.Rows[index];
//my code here..
}
我試過在這個頁面做同樣的事情。
http://www.dotnetbull.com/2013/05/how-to-handle-click-event-of-linkbutton.html
和這一個了,
https://msdn.microsoft.com/en-us/library/bb907626.aspx
我真的不知道我在做什麼錯了,當我按一下按鈕沒有任何反應。 我試過放置斷點,但我注意到斷點從不發生
非常感謝您的時間,任何評論都會有所幫助。
謝謝,我會試試這個:) –