I have a nested Datagrid with access database. Its basically a Daily report system. I got few last minute changes and they sounds tricky. Please help on the following :
1. The two columns Date1 and Day, Where Date1 is PKey in DR_Details_Nitin.mdb, should be merged into 1 as now i want system day and date to be picked instead of predefined and user selecting it.
2. There is this tricky requirement, I do not want user to insert next day details in advance, however he she can fill previous 3 days details. so this means user should not see or not allowed to insert coming days details in advance.
3. Instead of edit and update option on the gridview1, i want submit button so that as it is clicked a mail is sent to respective person.
You will have to use a customvalidator for second issue.
Try using a customevalidator for checking
If date <= today.date or date <= today.adddays(3) Then
customvalidator.isvalid=false
else
customvalidator.isvalid=false
End If
Let us know is this works for you.
Regards,
Gaurav Majithia
Mark the post as answer, if it helped you in solving your question.
Help the community to get better and more helpful.
For Online Bulk SMS Visit http://sms.gamatech.in
There was a logical error in above code which i posted, I hope you rectified and corrected. I have edited the post.
For 1st issus, do 1 thing combine the date and days when the row is created, using the rowcreated event of gridview.
Something like below code.
Protected Sub GridView2_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView2.RowCreated
Dim txtdate As TextBox
txtdate = CType(e.Row.FindControl("txtDate"), TextBox)
txtdate.Text=FormatDateTime(Date,1)
End Sub
Try and let me know.
Regards,
Gaurav Majithia
Mark the post as answer, if it helped you in solving your question.
Help the community to get better and more helpful.
For Online Bulk SMS Visit http://sms.gamatech.in
Go to edit columns of gridview select the edit column and change buttontype to button.
If you want to write custome code for onclick event of that button, convert that column to template by selecting the column edit and clicking the link below property box in edit column dialogbox.
After that select the gridview and click exit template, select your EDIT column in that and you will be able to edit the button and write onclick code for that button.
Do not forget to mark as Answer for each post which resolved your queries.
Regards,
Gaurav Majithia
Mark the post as answer, if it helped you in solving your question.
Help the community to get better and more helpful.
For Online Bulk SMS Visit http://sms.gamatech.in
Thank you so much for your replies and apologise for my novice knowledge in asp.net.
as you said about rowcreated event. I do not have any if you have seen my code. rows are not added/created on any event instead they are added in the footer of gridview.
RowCreated is a event which is fired when a row is created either thru datasource or using code.
For example if you want to do some calculation after the data is retrived from DB and before displaying it in gridview you can do it using rowcreated event.
Taking an example of a table consisting columns Name| sales|Cost
but while displaying in dridview you want a column which will show total cost of sales you can do it at rowcreated event.
I hope there is no confusion in rowcreated event now. Let me know if still there is.
Regards,
Gaurav Majithia
Mark the post as answer, if it helped you in solving your question.
Help the community to get better and more helpful.
For Online Bulk SMS Visit http://sms.gamatech.in
Here it is, First part is solve from your help... remaining one is this...
Now i get system date inserted into my access database. if you see my code above, its a nested grid. What i want is if the GRIDVIEW1 date is more then 3 days old, GRIDVIEW 2 EDIT option should be disabled.
Learning++
Member
22 Points
172 Posts
Datagrid Issues, Please help !!!
Feb 01, 2010 06:58 AM|LINK
Hello all
I have a nested Datagrid with access database. Its basically a Daily report system. I got few last minute changes and they sounds tricky. Please help on the following :
1. The two columns Date1 and Day, Where Date1 is PKey in DR_Details_Nitin.mdb, should be merged into 1 as now i want system day and date to be picked instead of predefined and user selecting it.
2. There is this tricky requirement, I do not want user to insert next day details in advance, however he she can fill previous 3 days details. so this means user should not see or not allowed to insert coming days details in advance.
3. Instead of edit and update option on the gridview1, i want submit button so that as it is clicked a mail is sent to respective person.
Please please please help me on this !
My aspx and code behind are here :
aspx:
<%@ Page Language="C#" MasterPageFile="~/Shared/POMasterPage.master" AutoEventWireup="true" Theme="Default" CodeFile="DR_Nitin.aspx.cs" Inherits="_DR_Nitin" Title="Daily Report Details" %> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <script language=javascript type="text/javascript"> function expandcollapse(obj,row) { var div = document.getElementById(obj); var img = document.getElementById('img' + obj); if (div.style.display == "none") { div.style.display = "block"; if (row == 'alt') { img.src = "Images/minus.gif"; } else { img.src = "Images/minus.gif"; } img.alt = "Close to view other Purchase Orders"; } else { div.style.display = "none"; if (row == 'alt') { img.src = "Images/plus.gif"; } else { img.src = "Images/plus.gif"; } img.alt = "Expand to show Job NetPayble"; } } </script> <br /> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="15" valign="top"><img src="Images/blue_top_left.jpg" width="15" height="20" /></td> <td class="table_heading"> <asp:Label runat="server" ID="lblScreenTitle" meta:resourceKey="lblScreenTitle" SkinID="PageHeader"></asp:Label> </td> <td width="15" valign="top"><img src="Images/blue_top_right.jpg" width="15" style="height: 22px" /></td> </tr> <tr> <td width="15" valign="top" class="table_leftbkg"><img src="Images/blue_top1_left.jpg" width="15" height="11" /></td> <td rowspan="2" valign="top" class="table_content"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td align="center"> <table width="100%" cellpadding="1" cellspacing="0"> <tr> <td align="center" style="width: 35%"> <img alt="" src="Images/DR.jpg" style="width: 256px; height: 135px" /></td> </tr> </table> </td> </tr> <tr> <td align="right"> </td> </tr> <tr> <td align="center"> <asp:Button ID="btnReport" runat="server" Text="Report" onclick="btnReport_Click1" /> <asp:Button ID="btnReturn" runat="server" Text="Return to Start Page" onclick="btnReturn_Click" /> </td> </tr> <tr> <td align="center"> </td> </tr> <tr> <td align="center"> <asp:GridView ID="GridView1" AllowPaging="True" BackColor="#F1F1F1" AutoGenerateColumns=False DataSourceID="AccessDataSource1" DataKeyNames="Date1" style="Z-INDEX: 101; LEFT: 8px; " ShowFooter=True Font-Size=Small Font-Names="Verdana" runat="server" GridLines=None OnRowDataBound="GridView1_RowDataBound" OnRowCommand = "GridView1_RowCommand" OnRowUpdating = "GridView1_RowUpdating" BorderStyle=Outset OnRowDeleting = "GridView1_RowDeleting" OnRowDeleted = "GridView1_RowDeleted" OnRowUpdated = "GridView1_RowUpdated" AllowSorting=True> <RowStyle BackColor="Gainsboro" /> <AlternatingRowStyle BackColor="White" /> <HeaderStyle BackColor="#0083C1" ForeColor="White"/> <FooterStyle BackColor="White" /> <Columns> <asp:TemplateField> <ItemTemplate> <a href="javascript:expandcollapse('div<%# Eval("Date1") %>', 'one');"> <img id="imgdiv<%# Eval("Date1") %>" alt="Click to show/hide Job Details for Employee <%# Eval("Date1") %>" width="9px" border="0" src="Images/plus.gif"/> </a> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Date" SortExpression="Date1"> <ItemTemplate><asp:Label ID="lblDate" Text='<%# Eval("Date1")%>' ReadOnly="True" runat="server"></asp:Label></ItemTemplate> <EditItemTemplate> <asp:Label ID="lblDate" Text='<%# Eval("Date1") %>' runat="server"/> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Day" SortExpression="Day1"> <ItemTemplate><%# Eval("Day1")%></ItemTemplate> <EditItemTemplate> <asp:DropDownList ID="lblDay" runat="server"> <asp:ListItem Value="MONDAY"></asp:ListItem> <asp:ListItem Value="TUESDAY"></asp:ListItem> <asp:ListItem Value="WEDNESDAY"></asp:ListItem> <asp:ListItem Value="THURSDAY"></asp:ListItem> <asp:ListItem Value="FRIDAY"></asp:ListItem> <asp:ListItem Value="SATURDAY"></asp:ListItem> <asp:ListItem Value="SUNDAY"></asp:ListItem> </asp:DropDownList> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Employee ID" SortExpression="Emp_ID"> <ItemTemplate><%# Eval("Emp_ID") %></ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txtEmp_ID" Text='<%# Eval("Emp_ID") %>' runat="server" ReadOnly="True" BackColor="Gray"/> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="First Name" SortExpression="First_Name"> <ItemTemplate><%# Eval("First_Name")%></ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txtFirst_Name" Text='<%# Eval("First_Name") %>' runat="server" ReadOnly="True" BackColor="Gray"></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Last Name" SortExpression="Last_Name"> <ItemTemplate><%# Eval("Last_Name") %></ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txtLast_Name" Text='<%# Eval("Last_Name") %>' runat="server" ReadOnly="True" BackColor="Gray"></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Designation" SortExpression="Designation"> <ItemTemplate><%# Eval("Designation")%></ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txtDesignation" Text='<%# Eval("Designation") %>' runat="server" ReadOnly="True" BackColor="Gray" ></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:CommandField HeaderText="Edit" ShowEditButton="True" /> <asp:TemplateField> <ItemTemplate> <tr> <td colspan="100%"> <div id="div<%# Eval("Date1") %>" style="display:none;position:relative;left:15px;OVERFLOW: auto;WIDTH:97%" > <asp:GridView ID="GridView2" AllowSorting="true" BackColor="White" Width=100% Font-Size=X-Small AutoGenerateColumns=false Font-Names="Verdana" runat="server" DataKeyNames="Date1" ShowFooter=true OnPageIndexChanging="GridView2_PageIndexChanging" OnRowUpdating = "GridView2_RowUpdating" OnRowCommand = "GridView2_RowCommand" OnRowEditing = "GridView2_RowEditing" GridLines=None OnRowUpdated = "GridView2_RowUpdated" OnRowCancelingEdit = "GridView2_CancelingEdit" OnRowDataBound = "GridView2_RowDataBound" OnRowDeleting = "GridView2_RowDeleting" OnRowDeleted = "GridView2_RowDeleted" OnSorting = "GridView2_Sorting" BorderStyle=Double BorderColor="#0083C1"> <RowStyle BackColor="Gainsboro" /> <AlternatingRowStyle BackColor="White" /> <HeaderStyle BackColor="#0083C1" ForeColor="White"/> <FooterStyle BackColor="White" /> <Columns> <asp:TemplateField HeaderText="Job ID" SortExpression="Task_id"> <ItemTemplate> <asp:Label ID="lblPO_Task_id" Text='<%# Eval("Task_id") %>' runat="server"></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:Label ID="lblPO_Task_id" Text='<%# Eval("Task_id") %>' runat="server"></asp:Label> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Description" SortExpression="Description"> <ItemTemplate><%# Eval("Description")%></ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txtDescription" Text='<%# Eval("Description")%>' runat="server" TextMode="MultiLine"></asp:TextBox> </EditItemTemplate> <FooterTemplate> <asp:TextBox ID="txtDescription" Text='' runat="server" TextMode="MultiLine"></asp:TextBox> </FooterTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Status" SortExpression="Status"> <ItemTemplate><%# Eval("Status")%></ItemTemplate> <EditItemTemplate> <asp:DropDownList ID="ddlStatus" Text='<%# Eval("Status")%>' runat="server"> <asp:ListItem Value="Completed"></asp:ListItem> <asp:ListItem Value="Pending"></asp:ListItem> <asp:ListItem Value="In Progress"></asp:ListItem> <asp:ListItem Value="Not Yet Initiated"></asp:ListItem> </asp:DropDownList> </EditItemTemplate> <FooterTemplate> <asp:DropDownList ID="ddlStatus" runat="server"> <asp:ListItem Value="Completed"></asp:ListItem> <asp:ListItem Value="Pending"></asp:ListItem> <asp:ListItem Value="In Progress"></asp:ListItem> <asp:ListItem Value="Not Yet Initiated"></asp:ListItem> </asp:DropDownList> </FooterTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Time Hours" SortExpression="Time_Hours"> <ItemTemplate><%# Eval("Time_Hours")%></ItemTemplate> <EditItemTemplate> <asp:DropDownList ID="ddlTime_Hours" runat="server"> <asp:ListItem Value="0"></asp:ListItem> <asp:ListItem Value="1"></asp:ListItem> <asp:ListItem Value="2"></asp:ListItem> <asp:ListItem Value="3"></asp:ListItem> <asp:ListItem Value="4"></asp:ListItem> <asp:ListItem Value="5"></asp:ListItem> <asp:ListItem Value="6"></asp:ListItem> <asp:ListItem Value="7"></asp:ListItem> <asp:ListItem Value="8"></asp:ListItem> <asp:ListItem Value="9"></asp:ListItem> <asp:ListItem Value="10"></asp:ListItem> <asp:ListItem Value="11"></asp:ListItem> <asp:ListItem Value="12"></asp:ListItem> </asp:DropDownList> </EditItemTemplate> <FooterTemplate> <asp:DropDownList ID="ddlTime_Hours" runat="server"> <asp:ListItem Value="0"></asp:ListItem> <asp:ListItem Value="1"></asp:ListItem> <asp:ListItem Value="2"></asp:ListItem> <asp:ListItem Value="3"></asp:ListItem> <asp:ListItem Value="4"></asp:ListItem> <asp:ListItem Value="5"></asp:ListItem> <asp:ListItem Value="6"></asp:ListItem> <asp:ListItem Value="7"></asp:ListItem> <asp:ListItem Value="8"></asp:ListItem> <asp:ListItem Value="9"></asp:ListItem> <asp:ListItem Value="10"></asp:ListItem> <asp:ListItem Value="11"></asp:ListItem> <asp:ListItem Value="12"></asp:ListItem> </asp:DropDownList> </FooterTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Time Minutes" SortExpression="Time_Minutes"> <ItemTemplate><%# Eval("Time_Minutes")%></ItemTemplate> <EditItemTemplate> <asp:DropDownList ID="ddlTime_Minutes" Text='<%# Eval("Time_Minutes")%>' runat="server"> <asp:ListItem Value="0"></asp:ListItem> <asp:ListItem Value="5"></asp:ListItem> <asp:ListItem Value="10"></asp:ListItem> <asp:ListItem Value="15"></asp:ListItem> <asp:ListItem Value="20"></asp:ListItem> <asp:ListItem Value="25"></asp:ListItem> <asp:ListItem Value="30"></asp:ListItem> <asp:ListItem Value="35"></asp:ListItem> <asp:ListItem Value="40"></asp:ListItem> <asp:ListItem Value="45"></asp:ListItem> <asp:ListItem Value="50"></asp:ListItem> <asp:ListItem Value="55"></asp:ListItem> <asp:ListItem Value="60"></asp:ListItem> </asp:DropDownList> </EditItemTemplate> <FooterTemplate> <asp:DropDownList ID="ddlTime_Minutes" runat="server"> <asp:ListItem Value="0"></asp:ListItem> <asp:ListItem Value="5"></asp:ListItem> <asp:ListItem Value="10"></asp:ListItem> <asp:ListItem Value="15"></asp:ListItem> <asp:ListItem Value="20"></asp:ListItem> <asp:ListItem Value="25"></asp:ListItem> <asp:ListItem Value="30"></asp:ListItem> <asp:ListItem Value="35"></asp:ListItem> <asp:ListItem Value="40"></asp:ListItem> <asp:ListItem Value="45"></asp:ListItem> <asp:ListItem Value="50"></asp:ListItem> <asp:ListItem Value="55"></asp:ListItem> <asp:ListItem Value="60"></asp:ListItem> </asp:DropDownList> </FooterTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Total Time" SortExpression="Total_Time"> <ItemTemplate><%# Eval("Total_Time")%></ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txtTotal_Time" Text='<%# Eval("Total_Time")%>' runat="server" ReadOnly="True" BackColor="Gray"></asp:TextBox> </EditItemTemplate> <FooterTemplate> <asp:TextBox ID="txtTotal_Time" ReadOnly="True" BackColor="Gray" runat="server"></asp:TextBox> </FooterTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Time_Duration" SortExpression="Time_Duration"> <ItemTemplate><%# Eval("Time_Duration")%></ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txtTime_Duration" Text='<%# Eval("Time_Duration")%>' runat="server"></asp:TextBox> </EditItemTemplate> <FooterTemplate> <asp:TextBox ID="txtTime_Duration" Text='' runat="server"></asp:TextBox> </FooterTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Remarks" SortExpression="Remarks"> <ItemTemplate><%# Eval("Remarks")%></ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txtRemarks" Text='<%# Eval("Remarks")%>' runat="server"></asp:TextBox> </EditItemTemplate> <FooterTemplate> <asp:TextBox ID="txtRemarks" runat="server" ></asp:TextBox> </FooterTemplate> </asp:TemplateField> <asp:CommandField HeaderText="Edit" ShowEditButton="True" /> <asp:TemplateField HeaderText="Delete"> <ItemTemplate> <asp:LinkButton ID="linkDeletePO" CommandName="Delete" runat="server">Delete</asp:LinkButton> </ItemTemplate> <FooterTemplate> <asp:LinkButton ID="linkAddJob" CommandName="AddJob" runat="server">Add</asp:LinkButton> </FooterTemplate> </asp:TemplateField> </Columns> </asp:GridView> </div> </td> </tr> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/PO Access Database/DR_Details_Nitin.mdb" SelectCommand="SELECT * FROM [Emp_Details]" DeleteCommand="DELETE FROM [Emp_Details] WHERE (([Date1] = ?) OR ([Date1] IS NULL AND ? IS NULL))" InsertCommand="INSERT INTO [Emp_Details] ([Date1], [Emp_ID], [First_Name], [Last_Name], [Designation], [Day1], [Total_Hours]) VALUES (?, ?, ?, ?, ?, ?, ?)" UpdateCommand="UPDATE [Emp_Details] SET [Emp_ID] = ?, [First_Name] = ?, [Last_Name] = ?, [Designation] = ?, [Day1] = ?, [Total_Hours] = ? WHERE (([Date1] = ?) OR ([Date1] IS NULL AND ? IS NULL))"> <DeleteParameters> <asp:Parameter Name="Date1" Type="String" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="Emp_ID" Type="String" /> <asp:Parameter Name="First_Name" Type="String" /> <asp:Parameter Name="Last_Name" Type="String" /> <asp:Parameter Name="Designation" Type="String" /> <asp:Parameter Name="Day1" Type="String" /> <asp:Parameter Name="Total_Hours" Type="Decimal" /> <asp:Parameter Name="Date1" Type="String" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="Date1" Type="String" /> <asp:Parameter Name="Emp_ID" Type="String" /> <asp:Parameter Name="First_Name" Type="String" /> <asp:Parameter Name="Last_Name" Type="String" /> <asp:Parameter Name="Designation" Type="String" /> <asp:Parameter Name="Day1" Type="String" /> <asp:Parameter Name="Total_Hours" Type="Decimal" /> </InsertParameters> </asp:AccessDataSource></td> </tr> <tr> <td align="right"> <table width="100%"> <tr> <td align="left" style="width: 35%;"> </td> </tr> </table> </td> </tr> </table> <table width="100%" align="center"> <tr> <td> </td> </tr> </table></td> <td width="15" valign="top" class="table_rightbkg"><img src="Images/blue_top1_right.jpg" width="15" height="11" /></td> </tr> <tr> <td width="15" class="table_leftbkg"> </td> <td width="15" class="table_rightbkg"> </td> </tr> <tr> <td width="15"><img src="Images/bluetable_left_bot_cor.jpg" /></td> <td class="table_bottombkg"> </td> <td width="15"><img src="Images/bluetable_right_bot_cor.jpg" /></td> </tr> </table> </asp:Content>My Code Behind :
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.OleDb; public partial class _DR_Nitin : System.Web.UI.Page { #region Variables float TV; float s4; string strTotal_Hours; string gvUniqueID = String.Empty; int gvNewPageIndex = 0; int gvEditIndex = -1; string gvSortExpr = String.Empty; private string gvSortDir { get { return ViewState["SortDirection"] as string ?? "ASC"; } set { ViewState["SortDirection"] = value; } } #endregion //This procedure returns the Sort Direction private string GetSortDirection() { switch (gvSortDir) { case "ASC": gvSortDir = "DESC"; break; case "DESC": gvSortDir = "ASC"; break; } return gvSortDir; } //This procedure prepares the query to bind the child GridView private AccessDataSource ChildDataSource(string strDate, string strSort) { string strQRY = ""; AccessDataSource dsTemp = new AccessDataSource(); dsTemp.DataFile = "~/App_Data/PO Access Database/DR_Details_Nitin.mdb"; strQRY = "SELECT [Job_Details].[Date1],[Job_Details].[Task_id]," + "[Job_Details].[Description], [Job_Details].[Status], [Job_Details].[Time_Hours], [Job_Details].[Time_Minutes], [Job_Details].[Total_Time],[Job_Details].[Time_Duration], [Job_Details].[Remarks] FROM [Job_Details]" + " WHERE [Job_Details].[Date1] = '" + strDate + "'" + "UNION ALL " + "SELECT '" + strDate + "','','','','','','','','' FROM [Job_Details] WHERE [Job_Details].[Date1] = '" + strDate + "'" + "HAVING COUNT(*)=0 " + strSort; dsTemp.SelectCommand = strQRY; return dsTemp; } protected void Page_Load(object sender, EventArgs e) { } #region GridView1 Event Handlers //This event occurs for each row protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { GridViewRow row = e.Row; string strSort = string.Empty; // Make sure we aren't in header/footer rows if (row.DataItem == null) { return; } //Find Child GridView control GridView gv = new GridView(); gv = (GridView)row.FindControl("GridView2"); //Check if any additional conditions (Paging, Sorting, Editing, etc) to be applied on child GridView if (gv.UniqueID == gvUniqueID) { gv.PageIndex = gvNewPageIndex; gv.EditIndex = gvEditIndex; //Check if Sorting used if (gvSortExpr != string.Empty) { GetSortDirection(); strSort = " ORDER BY " + string.Format("{0} {1}", gvSortExpr, gvSortDir); } //Expand the Child grid ClientScript.RegisterStartupScript(GetType(), "Expand", "<SCRIPT LANGUAGE='javascript'>expandcollapse('div" + ((DataRowView)e.Row.DataItem)["Date1"].ToString() + "','one');</script>"); } //Prepare the query for Child GridView by passing the Report ID of the parent row gv.DataSource = ChildDataSource(((DataRowView)e.Row.DataItem)["Date1"].ToString(), strSort); gv.DataBind(); } //This event occurs for any operation on the row of the grid protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { //Check if Add button clicked if (e.CommandName == "AddPO") { try { //Get the values stored in the text boxes string strFirst_Name = ((TextBox)GridView1.FooterRow.FindControl("txtFirst_Name")).Text; string strLast_Name = ((TextBox)GridView1.FooterRow.FindControl("txtLast_Name")).Text; string strDesignation = ((TextBox)GridView1.FooterRow.FindControl("txtDesignation")).Text; string strDate = ((TextBox)GridView1.FooterRow.FindControl("txtDate")).Text; string strDay = ((TextBox)GridView1.FooterRow.FindControl("lblDay")).Text; string strEmp_ID = ((TextBox)GridView1.FooterRow.FindControl("txtEmp_ID")).Text; //Prepare the Insert Command of the DataSource control string strSQL = ""; strSQL = "INSERT INTO Emp_Details (Emp_ID, First_Name, Last_Name, " + "Designation, Date1, Day1) VALUES ('" + strEmp_ID + "','" + strFirst_Name + "','" + strLast_Name + "','" + strDesignation + "','" + strDate + "', '" + strDay + "')"; AccessDataSource1.InsertCommand = strSQL; AccessDataSource1.Insert(); ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Report added successfully');</script>"); //Re bind the grid to refresh the data GridView1.DataBind(); } catch (Exception ex) { ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + ex.Message.ToString().Replace("'", "") + "');</script>"); } } } //This event occurs on click of the Update button protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { //Get the values stored in the text boxes string strFirst_Name = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtFirst_Name")).Text; string strLast_Name = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtLast_Name")).Text; string strDesignation = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtDesignation")).Text; string strDate = ((Label)GridView1.Rows[e.RowIndex].FindControl("lblDate")).Text; string strEmp_ID = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtEmp_ID")).Text; string strDay = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("lblDay")).Text; try { //Prepare the Update Command of the DataSource control string strSQL = ""; strSQL = "UPDATE Emp_Details set First_Name = '" + strFirst_Name + "'" + ",Last_Name = '" + strLast_Name + "'" + ",Designation = '" + strDesignation + "'" + ",Emp_ID = '" + strEmp_ID + "'" + ",Day1 = '" + strDay + "'" + " WHERE Date1 = '" + strDate + "'"; AccessDataSource1.UpdateCommand = strSQL; AccessDataSource1.Update(); ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Report updated successfully');</script>"); } catch { } } //This event occurs after RowUpdating to catch any constraints while updating protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e) { //Check if there is any exception while deleting if (e.Exception != null) { ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + e.Exception.Message.ToString().Replace("'", "") + "');</script>"); e.ExceptionHandled = true; } } //This event occurs on click of the Delete button protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { //Get the value string strDate = ((Label)GridView1.Rows[e.RowIndex].FindControl("lblDate")).Text; //Prepare the delete Command of the DataSource control string strSQL = ""; try { strSQL = "DELETE from Emp_Details WHERE Date1 = '" + strDate + "'"; AccessDataSource1.DeleteCommand = strSQL; AccessDataSource1.Delete(); ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Report deleted successfully');</script>"); } catch { } } //This event occurs after RowDeleting to catch any constraints while deleting protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e) { //Check if there is any exception while deleting if (e.Exception != null) { ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + e.Exception.Message.ToString().Replace("'", "") + "');</script>"); e.ExceptionHandled = true; } } #endregion #region GridView2 Event Handlers protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView gvTemp = (GridView)sender; gvUniqueID = gvTemp.UniqueID; gvNewPageIndex = e.NewPageIndex; GridView1.DataBind(); } protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "AddJob") { try { GridView gvTemp = (GridView)sender; gvUniqueID = gvTemp.UniqueID; //Get the values stored in the text boxes string strDate = gvTemp.DataKeys[0].Value.ToString(); //Report ID is stored as DataKeyNames string strStatus = ((DropDownList)gvTemp.FooterRow.FindControl("ddlStatus")).Text; string strTime_Minutes = ((DropDownList)gvTemp.FooterRow.FindControl("ddlTime_Minutes")).Text; string strTime_Duration = ((TextBox)gvTemp.FooterRow.FindControl("txtTime_Duration")).Text; string strTotal_Time = ((TextBox)gvTemp.FooterRow.FindControl("txtTotal_Time")).Text; string strDescription = ((TextBox)gvTemp.FooterRow.FindControl("txtDescription")).Text; string strTime_Hours = ((DropDownList)gvTemp.FooterRow.FindControl("ddlTime_Hours")).Text; string strRemarks = ((TextBox)gvTemp.FooterRow.FindControl("txtRemarks")).Text; //strTotal_Hours = ((TextBox)GridView1.FooterRow.FindControl("txtTotal_Hours")).Text; //string strTotal_Hours = ((TextBox)gvTemp.FooterRow.FindControl("txtTotal_Hours")).Text; float s1 = float.Parse(strTime_Minutes); float s2 = float.Parse(strTime_Hours); TV = (s2 + (s1/60)); strTotal_Time = TV.ToString(); //Prepare the Insert Command of the DataSource control string strSQL = ""; strSQL = "INSERT INTO Job_Details (Date1, Description, Status, Time_Hours, Time_Minutes, Total_Time, Time_Duration, Remarks) VALUES ('" + strDate + "', '" + strDescription + "', '" + strStatus + "', '" + float.Parse(strTime_Hours) + "', '" + float.Parse(strTime_Minutes) + "', '" + float.Parse(strTotal_Time) + "','" + strTime_Duration + "','" + strRemarks + "')"; ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Job added successfully');</script>"); AccessDataSource1.InsertCommand = strSQL; AccessDataSource1.Insert(); GridView1.DataBind(); } catch (Exception ex) { ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + ex.Message.ToString().Replace("'", "") + "');</script>"); } } } protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e) { GridView gvTemp = (GridView)sender; gvUniqueID = gvTemp.UniqueID; gvEditIndex = e.NewEditIndex; GridView1.DataBind(); } protected void GridView2_CancelingEdit(object sender, GridViewCancelEditEventArgs e) { GridView gvTemp = (GridView)sender; gvUniqueID = gvTemp.UniqueID; gvEditIndex = -1; GridView1.DataBind(); } protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { GridView gvTemp = (GridView)sender; gvUniqueID = gvTemp.UniqueID; //Get the values stored in the text boxes string strPO_Task_id = ((Label)gvTemp.Rows[e.RowIndex].FindControl("lblPO_Task_id")).Text; string strTime_Minutes = ((DropDownList)gvTemp.Rows[e.RowIndex].FindControl("ddlTime_Minutes")).Text; string strTime_Duration = ((TextBox)gvTemp.Rows[e.RowIndex].FindControl("txtTime_Duration")).Text; string strRemarks = ((TextBox)gvTemp.Rows[e.RowIndex].FindControl("txtRemarks")).Text; string strDescription = ((TextBox)gvTemp.Rows[e.RowIndex].FindControl("txtDescription")).Text; string strTime_Hours = ((DropDownList)gvTemp.Rows[e.RowIndex].FindControl("ddlTime_Hours")).Text; string strStatus = ((DropDownList)gvTemp.Rows[e.RowIndex].FindControl("ddlStatus")).Text; string strTotal_Time = ((TextBox)gvTemp.Rows[e.RowIndex].FindControl("txtTotal_Time")).Text; float s1 = float.Parse(strTime_Minutes); float s2 = float.Parse(strTime_Hours); float TV = (s2 + (s1 / 60)); strTotal_Time = TV.ToString(); float s3 = float.Parse(strTime_Hours) + float.Parse(strTotal_Time); //Prepare the Update Command of the DataSource control AccessDataSource dsTemp = new AccessDataSource(); dsTemp.DataFile = "~/App_Data/PO Access Database/DR_Details_Nitin.mdb"; string strSQL = ""; strSQL = "UPDATE Job_Details set Total_Time = " + float.Parse(strTotal_Time) + "" + ",Description = '" + strDescription + "'" + ",Status = '" + strStatus + "'" + ",Time_Hours = '" + float.Parse(strTime_Hours) + "'" + ",Time_Minutes = '" + float.Parse(strTime_Minutes) + "'" + ",Time_Duration = '" + strTime_Duration + "'" + ",Remarks = '" + strRemarks + "'" + " WHERE Task_id = " + strPO_Task_id; dsTemp.UpdateCommand = strSQL; dsTemp.Update(); ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Job updated successfully');</script>"); //Reset Edit Index gvEditIndex = -1; GridView1.DataBind(); } catch { } } protected void GridView2_RowUpdated(object sender, GridViewUpdatedEventArgs e) { //Check if there is any exception while deleting if (e.Exception != null) { ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + e.Exception.Message.ToString().Replace("'", "") + "');</script>"); e.ExceptionHandled = true; } } protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e) { GridView gvTemp = (GridView)sender; gvUniqueID = gvTemp.UniqueID; //Get the value string strPO_Task_id = ((Label)gvTemp.Rows[e.RowIndex].FindControl("lblPO_Task_id")).Text; //Prepare the Update Command of the DataSource control string strSQL = ""; try { strSQL = "DELETE from Job_Details WHERE Task_id = " + strPO_Task_id; AccessDataSource dsTemp = new AccessDataSource(); dsTemp.DataFile = "~/App_Data/PO Access Database/DR_Details_Nitin.mdb"; dsTemp.DeleteCommand = strSQL; dsTemp.Delete(); ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Job deleted successfully');</script>"); GridView1.DataBind(); } catch { } } protected void GridView2_RowDeleted(object sender, GridViewDeletedEventArgs e) { //Check if there is any exception while deleting if (e.Exception != null) { ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + e.Exception.Message.ToString().Replace("'", "") + "');</script>"); e.ExceptionHandled = true; } } protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e) { //Check if this is our Blank Row being databound, if so make the row invisible if (e.Row.RowType == DataControlRowType.DataRow) { if (((DataRowView)e.Row.DataItem)["Task_id"].ToString() == String.Empty) e.Row.Visible = false; } } protected void GridView2_Sorting(object sender, GridViewSortEventArgs e) { GridView gvTemp = (GridView)sender; gvUniqueID = gvTemp.UniqueID; gvSortExpr = e.SortExpression; GridView1.DataBind(); } #endregion protected void btnPrint_Click(object sender, EventArgs e) { Response.Redirect("Report_PO.aspx"); } protected void btnReturn_Click(object sender, EventArgs e) { Response.Redirect("Start_Menu.aspx"); } protected void btnReport_Click1(object sender, EventArgs e) { Response.Redirect("Report_DR_Nitin.aspx"); } }Learning++
Member
22 Points
172 Posts
Re: Datagrid Issues, Please help !!!
Feb 01, 2010 09:09 AM|LINK
Okay, first issue resolved, Please help me on the second one.
Thanks in advance !
gaurav_majit...
Member
236 Points
71 Posts
Re: Datagrid Issues, Please help !!!
Feb 01, 2010 10:12 AM|LINK
You will have to use a customvalidator for second issue.
Try using a customevalidator for checking
Let us know is this works for you.
Gaurav Majithia
Mark the post as answer, if it helped you in solving your question.
Help the community to get better and more helpful.
For Online Bulk SMS Visit http://sms.gamatech.in
Learning++
Member
22 Points
172 Posts
Re: Datagrid Issues, Please help !!!
Feb 01, 2010 10:17 AM|LINK
Thank you for replyin. I will try this in a moment.
regarding the first query, i tried :
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"><FooterTemplate></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:TextBox ID="txtDate" Text='<%= FormatDateTime(Date, 1)%>' runat="server"></asp:TextBox></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </FooterTemplate></div><FooterTemplate>
<asp:TextBox ID="txtDate" Text='<%= FormatDateTime(Date, 1)%>' runat="server"></asp:TextBox>
</FooterTemplate>
But in the textbox it shows me <%= FormatDateTime(Date, 1)%> instead of day, date and time.
Can you please help me.
gaurav_majit...
Member
236 Points
71 Posts
Re: Datagrid Issues, Please help !!!
Feb 01, 2010 10:31 AM|LINK
There was a logical error in above code which i posted, I hope you rectified and corrected. I have edited the post.
For 1st issus, do 1 thing combine the date and days when the row is created, using the rowcreated event of gridview.
Something like below code.
Protected Sub GridView2_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView2.RowCreated Dim txtdate As TextBox txtdate = CType(e.Row.FindControl("txtDate"), TextBox) txtdate.Text=FormatDateTime(Date,1) End SubTry and let me know.
Gaurav Majithia
Mark the post as answer, if it helped you in solving your question.
Help the community to get better and more helpful.
For Online Bulk SMS Visit http://sms.gamatech.in
gaurav_majit...
Member
236 Points
71 Posts
Re: Datagrid Issues, Please help !!!
Feb 01, 2010 10:36 AM|LINK
For 3rd issue:
Go to edit columns of gridview select the edit column and change buttontype to button.
If you want to write custome code for onclick event of that button, convert that column to template by selecting the column edit and clicking the link below property box in edit column dialogbox.
After that select the gridview and click exit template, select your EDIT column in that and you will be able to edit the button and write onclick code for that button.
Do not forget to mark as Answer for each post which resolved your queries.
Gaurav Majithia
Mark the post as answer, if it helped you in solving your question.
Help the community to get better and more helpful.
For Online Bulk SMS Visit http://sms.gamatech.in
Learning++
Member
22 Points
172 Posts
Re: Datagrid Issues, Please help !!!
Feb 01, 2010 10:57 AM|LINK
Thank you so much for your replies and apologise for my novice knowledge in asp.net.
as you said about rowcreated event. I do not have any if you have seen my code. rows are not added/created on any event instead they are added in the footer of gridview.
Thank you for helping me !
:)
gaurav_majit...
Member
236 Points
71 Posts
Re: Datagrid Issues, Please help !!!
Feb 01, 2010 11:12 AM|LINK
RowCreated is a event which is fired when a row is created either thru datasource or using code.
For example if you want to do some calculation after the data is retrived from DB and before displaying it in gridview you can do it using rowcreated event.
Taking an example of a table consisting columns Name| sales|Cost
but while displaying in dridview you want a column which will show total cost of sales you can do it at rowcreated event.
I hope there is no confusion in rowcreated event now.
Let me know if still there is.

Gaurav Majithia
Mark the post as answer, if it helped you in solving your question.
Help the community to get better and more helpful.
For Online Bulk SMS Visit http://sms.gamatech.in
alaa9jo
Star
11375 Points
2036 Posts
Re: Datagrid Issues, Please help !!!
Feb 03, 2010 09:44 AM|LINK
HI,
Learning++,can you tell me what are the issues that are still not solved so far
Thanks
Ala'a Alnajjar
----------------------------------------------------
My Webblog
Learning++
Member
22 Points
172 Posts
Re: Datagrid Issues, Please help !!!
Feb 03, 2010 09:55 AM|LINK
:)
Here it is, First part is solve from your help... remaining one is this...
Now i get system date inserted into my access database. if you see my code above, its a nested grid. What i want is if the GRIDVIEW1 date is more then 3 days old, GRIDVIEW 2 EDIT option should be disabled.
How can i do this.
Thank you alaa9jo :)