Let me explain this.
1) I have a form with a bunch of controls (drop down, text box and calendar pop up (controlled by javascript) and not asp.net calendar control.
2) When the user clicks submit button after filling out the form, the value get inserted into the database (SQL Server):
Some of the code below:
protected void btn_insert_Click(object sender, EventArgs e)
{
if (CCConnection.State == ConnectionState.Closed)
{
CCConnection.Open();
}
// here i am using the store procedure named tb_gallery_insert to insert the record inside the database.
SqlCommand cmd = new SqlCommand("Insert_Form_Fields", CCConnection);
Console.WriteLine(cmd);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = CCConnection;
cmd.Parameters.AddWithValue("@TicketNumber", txt_Ticket_number.Text);
....... until all my paramters are added
3) On page load all I want to happen is show the results submitted to the database (all rows) in a grid view - to which it is doing:
protected void Page_Load(object sender, EventArgs e)
{
//here i declare the connection of the connectionstring to attach the database with the application
CCConnection.ConnectionString = ConfigurationManager.ConnectionStrings["CCConnection"].ConnectionString;
CCConnection.Open();
if (CCConnection.State == ConnectionState.Closed)
{
CCConnection.Open();
}
CCConnection.Close();
if (!IsPostBack)
{
grd_bind();
}
}
The grd_bind() function, using a stored procedure, simply select all values from the Table to display in Gridview.
4) When looking at the page/gridview the user has the option to Edit the Gridview record, or delete it.
5) When the user clicks the edit link on the gridview record, each of the fields open and become editable
6) When the user changes those values and clicks update, I want to save these updated values back to the database using a Stored Procedure. I am trying to do this in the RowUpdating, event using and Update_Procedure stored procedure...as below:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
if (CCConnection.State == ConnectionState.Closed)
{
CCConnection.Open();
}
TicketNumber = (((TextBox)(GridView1.Rows[e.RowIndex].FindControl("Edit_TicketNumber"))).Text);
NewFilm= (((DropDownList)(GridView1.Rows[e.RowIndex].FindControl("Edit_NewFilmDropDownList"))).Text);
MovieName = (((TextBox)(GridView1.Rows[e.RowIndex].FindControl("Edit_MovieName"))).Text);
SqlCommand cmd = new SqlCommand("Update_Procedure", cnn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = cnn;
cmd.Parameters.Add("@ID", SqlDbType.Int).Value = ID;
cmd.Parameters.Add("@TicketNum", SqlDbType.VarChar, 50).Value = TicketNumber;
cmd.Parameters.Add("@New_Film", SqlDbType.VarChar, 50).Value = New_Film;
cmd.Parameters.Add("@MovieName", SqlDbType.VarChar, 50).Value = MovieName;
cmd.ExecuteNonQuery();
cmd.Dispose();
GridView1.EditIndex = -1;
grd_bind();
7) What I also want in the row updating is if the user clicks the edit button, but then decides he/she does not want to update anymore but rather insert a new record, when he/she clicks on anything other then the fields on the row to be editted (not just a cancel button as in comment 8), it show close the edit functionality. What is happening now is if the user changes his/her mind about editting, and for instance, clicks the next page, if I go back to the page that record is still in edit mode. I don't want that.
What I also want to add, but need some help as well, is a file upload control, next to each record in the gridview, that when the user clicks edit, they will see a new input box, with a upload button to attach word docs, excel spreadsheets extra. In the event that they want to change that after updating, they can also do it. If they do attach a word doc, in a gridview colum they see just a word icon that is clickable and can open the doc (not sure if that is possible)
7) I also have some cancel functionality on row if users changes his or her mind. He/she clicks cancel button.
8) Gridview mark up:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
onrowcancelingedit="GridView1_RowCancelingEdit"
onrowdeleting="GridView1_RowDeleting"
onrowediting="GridView1_RowEditing"
onrowupdating="GridView1_RowUpdating"
onselectedindexchanging="GridView1_SelectedIndexChanging"
OnPageIndexChanging="GridView1_PageIndexChanging"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
OnSorting="GridView1_Sorting" PageSize="20" AllowPaging="True" CellPadding="4" ForeColor="#333333" GridLines="None"
CssClass="Grid_DataTable">
<Columns>
<%--here i am using templatefields to for binding the gridview--%>
<asp:TemplateField HeaderText="ID" SortExpression="Intake" Visible="false">
<EditItemTemplate>
<asp:TextBox ID="ID" runat="server" width="30px" Text='<%# Eval("ID") %>'> </asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Ticket Number" SortExpression="Ticket Number">
<EditItemTemplate>
<asp:TextBox ID="Edit_Ticket_number" runat="server" Width="100px" Text='<%# Eval("Ticket_Number") %>' ReadOnly="True" BackColor="Silver"> </asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Ticket_Number") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="New Film" SortExpression="New Film">
<EditItemTemplate>
<asp

ropDownList ID="Edit_NewFilmDropDownList" runat="server" SelectedValue='<%# Eval("New_Film") %>' >
<asp:ListItem>Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
</asp

ropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Eval("New_Film") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Movie Name" SortExpression="Movie name">
<EditItemTemplate>
<asp:TextBox ID="Edit_MovieName" runat="server" TextMode="MultiLine" Text='<%# Eval("Movie_Name") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" width="100px" Text='<%# Eval("Movie_Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Delete"
onclientclick="return confirm('Stop\n Are you sure you want to delete this column!')">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Update">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="false"
CommandName="Update">Update</asp:LinkButton>
<asp:LinkButton ID="LinkButton4" runat="server" CausesValidation="False"
CommandName="Cancel">Cancel</asp:LinkButton>
</ItemTemplate>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="True"
CommandName="Edit">Edit</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Delete">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Update">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="false"
CommandName="Update">Update</asp:LinkButton>
<asp:LinkButton ID="LinkButton4" runat="server" CausesValidation="False"
CommandName="Cancel">Cancel</asp:LinkButton>
</ItemTemplate>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="True"
CommandName="Edit">Edit</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
8) I don't have any page sorting yet and was trying to work on that, but need more time.
Hopefully this make sense?
Thanks SO MUCH jbenson.