我的网格视图中的按钮出现问题。它没有回复我的Response.Redirect("secondHistory.aspx")
和我的Console.WriteLine("hih")
。这是HTML代码
<asp:GridView runat="server" AutoGenerateColumns="false" ID="GridView1" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnRowCommand="GridView_RowCommand" Width="1027px">
<Columns>
<asp:BoundField DataField="ExcelID" HeaderText="Excel ID" />
<asp:BoundField DataField="excelName" HeaderText="Excel Name" />
<asp:BoundField DataField="excelDescription" HeaderText="Excel Description" />
<asp:BoundField DataField="date / time" HeaderText="Date / Time" />
<asp:BoundField DataField="empID" HeaderText="Employee ID" />
<asp:BoundField DataField="empName" HeaderText="Employee Name" />
<asp:BoundField DataField="engID" HeaderText="Engineer ID" />
<asp:BoundField DataField="engName" HeaderText="Engineer Name" />
<asp:BoundField DataField="firstApproval" HeaderText="First Approval(Engineer)" />
<asp:TemplateField HeaderText="Second Approval (Manager)">
<ItemTemplate>
<asp:Button ID="acceptBtn" runat="server"
CommandName="Accept"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"
Text="Accept" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
这是按钮的后端代码。
protected void GridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Accept")
{
// Retrieve the row index stored in the
// CommandArgument property.
int index = Convert.ToInt32(e.CommandArgument);
// Retrieve the row that contains the button
// from the Rows collection.
GridViewRow row = GridView1.Rows[index];
// Add code here to add the item to the shopping cart.
Console.WriteLine("hih");
Response.Redirect("secondHistory.aspx");
}
}
以下是填写表格的代码(如果必要的话)。
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("ExcelID", typeof(int));
dt.Columns.Add("excelName", typeof(string));
dt.Columns.Add("excelDescription", typeof(string));
dt.Columns.Add("date / time", typeof(string));
dt.Columns.Add("empID", typeof(int));
dt.Columns.Add("empName", typeof(string));
dt.Columns.Add("engID", typeof(int));
dt.Columns.Add("engName", typeof(string));
dt.Columns.Add("firstApproval", typeof(string));
dt.Columns.Add("secondApproval", typeof(string));
for(int i = 0; i < textfiles.Length; i++)
{
textList.Add(File.ReadAllText(textfiles[i]));
}
string[] textArray = textList.ToArray();
for (int i = 0; i < excelfiles.Length; i++)
{
dt.Rows.Add(i, excelfiles[i], textArray[i] , File.GetCreationTime(textfiles[i]), 837482, "*empName*", 917378, "*engName*", "Approved");
}
GridView1.DataSource = dt;
GridView1.DataBind();
}
请帮助谢谢!