JavaScript confirm after click on button in GridView

G

googleThis

I have a GridView control on a ASP.NET 2.0 page. I load the GridView
with a SqlDataReader that gets its data
from a stored procedure.

Here is how the grid is defined:

<asp:GridView ID="gridCareer" runat="server"
AutoGenerateColumns="False" OnRowCommand="gridCareer_RowCommand">
<Columns>
<asp:BoundField DataField="TrainingPlanID" >
<HeaderStyle CssClass="HiddenColumn" />
<ItemStyle CssClass="HiddenColumn" />
</asp:BoundField>
<asp:BoundField DataField="CourseNumber" HeaderText="Course
Number" SortExpression="CourseNumber" />
<asp:BoundField HeaderText="Course Name" DataField="CourseName"
/>
<asp:BoundField HeaderText="Status" DataField="Status" />
<asp:ButtonField Text="Remove" HeaderText="Remove"
DataTextField="CourseID" ButtonType="Image"
ImageUrl="~/images/delete.gif" >
<ControlStyle CssClass="UserButton" />
<ItemStyle HorizontalAlign="Center" />
</asp:ButtonField>
</Columns>
</asp:GridView>

When the button on the GridRow is clicked, the RowCommand event is
fired:

protected void gridCareer_RowCommand(object sender,
GridViewCommandEventArgs e)
{

// Convert the row index stored in the CommandArgument
// property to an Integer.

int Index = Convert.ToInt32(e.CommandArgument.ToString());
int TrainingPlanID =
Convert.ToInt32(gridCareer.Rows[Index].Cells[0].Text);

string CorpID = Session["CorpID"].ToString();

SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["TMS_user"].ConnectionString);

try
{
conn.Open(); // connect to the database

SqlCommand cmd = new SqlCommand("dbo.TrainingPlanCourseRemove",
conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter retValParm = cmd.Parameters.Add("@UpdateResult",
SqlDbType.Int);
retValParm.Direction = ParameterDirection.Output;
cmd.Parameters.AddWithValue("@TrainingPlanID", TrainingPlanID);
cmd.Parameters.AddWithValue("@EmployeeID", EmployeeID);
cmd.Parameters.AddWithValue("@CorpID", CorpID);

// the sproc will return a success code in the result set, 0 for
success, -1 for failure
int RetVal = Convert.ToInt32(cmd.ExecuteNonQuery());
}
finally
{
conn.Close();
}
GetCareerDevTrainingProgress(EmployeeID);
}

Here is how I call the stored proc to load data on page_load and after
the RowCommand event:

protected void GetCareerDevTrainingProgress(int EmployeeID)
{
// define the connection to the database
SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["TMS_user"].ConnectionString);
try
{
conn.Open(); // connect to the database
// create a command object to call the stored proc FindAClass
and assign the connection
SqlCommand cmd = new SqlCommand("CareerDevTrainingProgress",
conn);
cmd.CommandType = CommandType.StoredProcedure;
// the sproc will return a row count
SqlParameter retValParm = cmd.Parameters.Add("@RowCount",
SqlDbType.Int);
retValParm.Direction = ParameterDirection.ReturnValue;

cmd.Parameters.AddWithValue("@EmployeeID", EmployeeID);

SqlDataReader reader = cmd.ExecuteReader(); // exec the stored
proc
gridCareer.DataSource = reader;

gridCareer.DataBind();
}
finally
{
conn.Close();
}
}

This all works just fine server-side, but I would like to be able to
pop a JavaScript
confirm box when the user clicks the button in the grid that shows the
CommandArgument,
which I load with the employee ID when the grid is loaded. I can't
seem to find a way to
capture the command arg in JavaScript; it just shows up as 'undefined'.
Is there a
way to do that, or is there a different technique to communicate the
Employee ID to
the user? Thanks, Dave.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top