I have a problem with my buttons in the grid view. It is not responding to my Response.Redirect("secondHistory.aspx")
and my Console.WriteLine("hih")
. Here is the HTML code
<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>
and here is the backend code of the button.
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");
}
}
Here is the code to populate the table if its necessary.
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();
}
Please help thanks!