Unable to get posted file name in GridView when uploading file.
Here is what I tried with.
ASPX File content is shown below:
<asp:GridView ID="GVProtocol" runat="server" AllowPaging="True"
HorizontalAlign="Center" CssClass="DGList" HeaderStyle-CssClass="DGHeader"
RowStyle-CssClass="DGRow" AlternatingRowStyle-CssClass="DGRowAlt" OnRowCommand="GVProtocol_RowCommand"
OnPageIndexChanging="GVProtocol_PageIndexChanging" Height="90px" Width="100%" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="SL NO" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="20">
<ItemTemplate>
<%# (( ( GridView ) ( ( GridViewRow ) Container ).Parent.Parent ).PageSize + Container.DataItemIndex + 1)- 15 %>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:BoundField HeaderText="Name" DataField="NAME" />
<asp:BoundField HeaderText="Unit" DataField="UNIT" />
<asp:BoundField HeaderText="Standard Value" DataField="STANDARD_VALUE" />
<asp:TemplateField HeaderText="Upload XML" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:FileUpload ID="FileUpload" runat="server" EnableViewState="true" />
<asp:Button runat="server" ID="btnUpload" Text="upload" CommandArgument="<%# Container.DataItemIndex %>" CommandName="upload" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="FilePath" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="200">
<ItemTemplate>
<asp:Label runat="server" ID="lblFilePath">-</asp:Label>
<asp:LinkButton ID="btnDownload" runat="server" CommandName="download" CommandArgument="<%# Container.DataItemIndex %>"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle CssClass="pagerStyle" />
<HeaderStyle Wrap="False" CssClass="DGHeader" />
<RowStyle CssClass="DGRow" />
<AlternatingRowStyle CssClass="DGRowAlt" HorizontalAlign="Center" />
</asp:GridView>
This is the CodeBehind file for the above ASPX content:
protected void GVProtocol_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
int Index = Convert.ToInt32(e.CommandArgument);
if (e.CommandName == "upload")
{
string strFilePathTemp = Server.MapPath("~/ProtocolCommunication/");
//int Index = ((GridViewRow)((sender as Control)).NamingContainer).RowIndex;
LinkButton lbDownload = (LinkButton)GVProtocol.Rows[Index].FindControl("btnDownload");
lbDownload.Text = "<span class='glyphicon glyphicon-download-alt'>";
Label lblFilePathTemp = (Label)GVProtocol.Rows[Index].FindControl("lblFilePath");
lblFilePathTemp.Text = strFilePathTemp;
FileUpload fileUpload = (FileUpload)GVProtocol.Rows[Index].FindControl("FileUpload");
if(fileUpload != null)
{
string fileName = Path.GetFileName(fileUpload.PostedFile.FileName);
fileUpload.PostedFile.SaveAs(strFilePathTemp + fileName);
}
}
if (e.CommandName == "download")
{
Label lblFilePathTemp = (Label)GVProtocol.Rows[Index].FindControl("lblFilePath");
string fileNameAndPath = lblFilePathTemp.Text.ToString();
string file = Path.GetFileName(fileNameAndPath);
Response.ContentType = ContentType;
Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(fileNameAndPath));
Response.TransmitFile(Server.MapPath("~/ProtocolCommunication/"));
Response.End();
}
}
catch(Exception ex)
{
throw ex;
}
}
Looking for possible solution for the above problem.
I got solution,,by using
asp:updatePanel control with postbacktrigger to hold the control ID's which are dynamically created in girdview. and using this you can upload and download files to any of the gridview row.
Related
I have a custom GridView in asp.net Page. In PageLoad data will be bound to the grid.
protected void Page_Load(Object sender, EventArgs e)
{
InitDisplayMode(sender);
}
private void InitDisplayMode(Object sender)
{
pnlDetails.Visible = SafetyKeyId != -1;
if (!Page.IsPostBack)
{
BindValues();
}
// some other stuff
}
private void BindValues()
{
MyStrongTypedDataTable tbl = new BusinessObject.GetData();
dataGrid.DataSource = tbl;
dataGrid.DataBind();
}
Grid View Makrup
<asp:GridView ID="dataGrid" runat="server" AutoGenerateColumns="False" OnRowCreated="OnRowCreated"
AllowSorting="true" BorderWidth="0" CellPadding="2" CssClass="subitem w100p"
AllowPaging="true" PageSize="25" RowStyle-Wrap="false" HeaderStyle-Wrap="false"
OnPageIndexChanging="PageGrid" OnRowDataBound="dataGrid_RowDataBound" PagerSettings-Mode="Numeric"
PagerSettings-Position="Bottom" OnSorting="SortGrid" OnRowDeleting="RowDeleting">
<RowStyle CssClass="itemRowStyle"/>
<AlternatingRowStyle CssClass="alternatingItemRowStyle"/>
<HeaderStyle CssClass="headerRowStyle"/>
<Columns>
<asp:TemplateField ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle">
<ItemTemplate>
<asp:HyperLink ID="lnkDetail" runat="server" meta:resourcekey="lnkDetail" ImageUrl='<%# "~/App_Themes/" + Page.Theme + "/icons/16/icon_file.png" %>'
NavigateUrl="~/BrandMgmt/BrandMgmtPublicKey.aspx?"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle">
<ItemTemplate>
<asp:HyperLink ID="lnkEdit" runat="server" meta:resourcekey="lnkEdit" ImageUrl='<%# "~/App_Themes/" + Page.Theme + "/icons/16/icon_edit.png" %>'
NavigateUrl="~/BrandMgmt/BrandMgmtPublicKey.aspx?"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle">
<ItemTemplate>
<asp:ImageButton ID="cmdDelete" Width="16" Height="16" runat="server" ImageUrl='<%# "~/App_Themes/" + Page.Theme + "/icons/16/icon_delete.png" %>'
CommandName="Delete" CommandArgument='<%# Eval("SafetyKeyId") %>' OnCommand="OnDelete"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="KeyOwnerIdentifier" HeaderText="KeyOwnerIdentifier" meta:resourcekey="ColumnKeyOwnerIdentifier"
ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle" SortExpression="KeyOwnerIdentifier"/>
<asp:BoundField DataField="SafetyKeyName" HeaderText="SafetyKeyName" meta:resourcekey="ColumnSafetyKeyName"
ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle" SortExpression="SafetyKeyName"/>
<asp:BoundField DataField="SafetyKeyTypeId" HeaderText="SafetyKeyTypeId" meta:resourcekey="ColumnSafetyKeyTypeId"
ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle" SortExpression="SafetyKeyTypeId"/>
<asp:BoundField DataField="KeyIndex" HeaderText="KeyIndex" meta:resourcekey="ColumnKeyIndex"
ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle" SortExpression="KeyIndex"/>
<asp:BoundField DataField="FromDate" HeaderText="FromDate" meta:resourcekey="ColumnFromDate"
ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle" SortExpression="FromDate"/>
<asp:BoundField DataField="ToDate" HeaderText="ToDate" meta:resourcekey="ColumnToDate"
ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle" SortExpression="ToDate"/>
<asp:TemplateField ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle"
meta:resourcekey="ColumnPublicKey" SortExpression="PublicKey">
<ItemTemplate>
<div style="max-width: 200px; overflow-y: scroll;">
<asp:Label runat="server" Text='<%# Eval("PublicKey") %>'/>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Grid hat 3 ImageButtons for detail view, editing and deleting per row. DetaliView Button adds additional Table with data to the Page. Editing makes this Table editable. If the grid is sorted and any of those buttons is beeing clicked, Page loads and any sorting is lost.
How can I maintain the sort setting in PostBack after clicking any of those buttons?
I have a gridview in which I have a column name "Selection". I want whenver a admin selects Not Selected option the respective user should get an email on his ID that he has been rejected. Please see the gridview code for your reference:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" AllowPaging="true" Width="920"
PageSize="5" OnPageIndexChanging="gv_Applicants_PageIndexChanging" OnRowCommand="gv_Applicants_RowCommand"
EmptyDataText="No Applicants Found."
AllowSorting="true"
OnSorting="gv_Applicants_Sorting"
OnRowDataBound="gv_Applicants_RowDataBound" RowStyle-CssClass="a12" AlternatingRowStyle-CssClass="a22" ForeColor="#333333" GridLines="None" CssClass="table_box" HeaderStyle-Height="35px">
<AlternatingRowStyle BackColor="#F0F0F0" />
<Columns>
<asp:BoundField DataField="FirstName" HeaderText="First Name" HeaderStyle-Width="84" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" HeaderStyle-Width="106" />
<asp:BoundField DataField="ContactNumber" HeaderText="Contact" HeaderStyle-Width="98" />
<asp:BoundField DataField="Email" HeaderText="Email" HeaderStyle-Width="150" />
<asp:TemplateField HeaderText="Position" SortExpression="Position" HeaderStyle-Width="107">
<ItemTemplate>
<%# Eval("Job.Position") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Location" SortExpression="Location" HeaderStyle-Width="100">
<ItemTemplate>
<%# Eval("Job.Location") %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="AppliedDate" DataFormatString="{0:MMMM dd, yyyy}" HeaderText="Date of Application" ReadOnly="true" HeaderStyle-Width="121" />
<asp:TemplateField HeaderText="Action" HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:LinkButton ID='lnkView' CommandName='v' Text='View' runat='server' CommandArgument='<%# Eval("ApplicantId") %>'></asp:LinkButton>
|
<asp:LinkButton ID='lnkdel' CommandName='d' Text='Delete' runat='server' CommandArgument='<%# Eval("ApplicantId") %>' OnClientClick="return confirm('Are you sure to delete?');"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Selection">
<ItemTemplate>
<asp:Label ID="lblCountry" runat="server" Visible="true" />
<asp:DropDownList ID="ddlCountries" runat="server">
<asp:ListItem Text="None" Value="1"></asp:ListItem>
<asp:ListItem Text="Selected" Value="2"></asp:ListItem>
<asp:ListItem Text="Not Selected" Value="3"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#D8DADA" Font-Bold="True" />
<HeaderStyle BackColor="#D8DADA" Font-Bold="True" />
<PagerStyle BackColor="#D8DADA" HorizontalAlign="Center" />
<RowStyle BackColor="white" BorderStyle="Solid" BorderColor="#a8a8a8" BorderWidth="1px" Height="35" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
Eidted code:-
private void SendMail()
{
StringBuilder sbuilder = new StringBuilder();
sbuilder.Append("<div>");
sbuilder.Append("<p>Thanks for applying at RBL. You have been rejected</p>");
sbuilder.Append("</div>");
string str = sbuilder.ToString();
string ccEmail = "";
Common objCom = new Common();
string toId = ConfigurationManager.AppSettings["ddlEmail"].ToString();
objCom.SendEMail(toId, "Rejection Mail", sbuilder.ToString(), ccEmail, false, "");
}
protected void ddlSelection_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddl = (DropDownList)sender;
GridViewRow row = (GridViewRow)ddl.Parent.Parent;
if (ddl.SelectedValue == "Not Selected")
{
SendMail();
}
}
Try this,
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddl = e.Row.FindControl("ddlCountries") as DropDownList;
if(ddl != null)
{
ddl.SelectedIndexChanged += new EventHandler(ddlCountries_SelectedIndexChanged);
}
}
}
protected void ddlCountries_SelectedIndexChanged(object sender, EventArgs e)
{
string selectedValue = ((DropDownList)sender).SelectedValue;
if(selectedValue== "Not Selected")
{
// Write code here for sending mail
}
}
How can I use button onclick in DetailsView? So far I have this.
<asp:DetailsView ID="DetailsView1"
DefaultMode= "Edit" AutoGenerateEditButton="False" AutoGenerateInsertButton="True"
AutoGenerateDeleteButton="True" DataSourceID="SqlDataSource2" runat="server"
AutoGenerateRows="False" DataKeyNames="fileID" >
<Fields>
<asp:BoundField DataField="fileID" HeaderText="fileID" InsertVisible="False" ReadOnly="True" SortExpression="fileID" />
<asp:BoundField DataField="filenameName" HeaderText="filenameName" SortExpression="filenameName" />
<asp:TemplateField HeaderText="filePath" SortExpression="filePath">
<EditItemTemplate>
<asp:FileUpload ID="FileEditUpload1" Width="300px" runat="server" /> <br />
<asp:Button ID="Button1" runat="server" Text="Upload file" onclick="Button1_Click"/>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("filePath") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("filePath") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Createdby" HeaderText="Createdby" SortExpression="Createdby" Visible="False" />
<asp:BoundField DataField="CreatedDt" HeaderText="CreatedDt" SortExpression="CreatedDt" Visible="False" />
<asp:BoundField DataField="Updatedby" HeaderText="Updatedby" SortExpression="Updatedby" Visible="False" />
<asp:BoundField DataField="UpdatedDt" HeaderText="UpdatedDt" SortExpression="UpdatedDt" Visible="False" />
<asp:BoundField DataField="Active" HeaderText="Active" SortExpression="Active" Visible="False" />
</Fields>
</asp:DetailsView>
code-behind
protected void Button1_Click(object sender, EventArgs e)
{
//Get path from web.config file to upload
string FilePath = ConfigurationManager.AppSettings["FilePath"].ToString();
bool blSucces = false;
string filename = string.Empty;
string pathname = string.Empty;
string filePathName = string.Empty;
if (FileEditUpload1.HasFile)
{
}
You can access the fileUpload control from the DetailsView like this:
protected void Button1_Click(object sender, EventArgs e)
{
//Get path from web.config file to upload
string FilePath = ConfigurationManager.AppSettings["FilePath"].ToString();
bool blSucces = false;
string filename = string.Empty;
string pathname = string.Empty;
string filePathName = string.Empty;
//To access the file upload control
//First get the clicked button
Button btn = (Button)sender;
//Then get the detailsview row
DetailsViewRow drv = (DetailsViewRow)btn.Parent.Parent;
//Now you can access the FileUpload control
FileUpload FileEditUpload1 = (FileUpload)drv.FindControl("FileEditUpload1");
if (FileEditUpload1.HasFile)
{
//Do the rest of your code
}
}
Give it a try and if you faced any problems please inform me.
I have a GridView, In one column I have LinkButton control. I want to disable click from client side for certain condition on this column. Means for some rows it will not be possible for User to call onclick event and for some rows it is possible.
I want to achieve this from client side using javascript.
Or When User clicks on link, It will notify the User that this action can't be completed for this row.
<asp:GridView Width="100%" ShowHeader="true" ViewStateMode="Enabled" GridLines="Both" CellPadding="10" CellSpacing="5" ID="GridViewMultiplePOSAssociationId" runat="server" AllowSorting="false" AutoGenerateColumns="false" OnRowCommand="RewardGridMultiD_RowCommand"
AllowPaging="true" PageSize="8" OnRowDataBound="grdViewCustomers_OnRowDataBound" PagerSettings-Position="Top" PagerSettings-Mode="NumericFirstLast" PagerSettings-FirstPageText="First" PagerSettings-LastPageText="Last" DataKeyNames="POS Id">
<RowStyle CssClass="table_inner_text" BackColor="WhiteSmoke" BorderColor="CornflowerBlue" Wrap="true" ForeColor="Black" Height="30px" />
<HeaderStyle CssClass="table_head_text" />
<Columns>
<asp:TemplateField ItemStyle-Width="80px">
<ItemTemplate>
<a href="JavaScript:divexpandcollapse('div<%# Eval(" POS Id ") %>');">
<img alt="Details" id="imgdiv<%# Eval("POS Id") %>" src="images/plus.png" />
</a>
<div id="div<%# Eval(" POS Id ") %>" style="display: none;">
<asp:GridView ID="grdViewOrdersOfCustomer" runat="server" AutoGenerateColumns="false" CssClass="ChildGrid">
<RowStyle CssClass="table_inner_text" BackColor="SkyBlue" BorderColor="Black" Wrap="true" ForeColor="White" Height="30px" />
<Columns>
<asp:BoundField ItemStyle-Width="150px" DataField="RULE FILE NAME" HeaderText="RULE FILE NAME" />
<asp:BoundField ItemStyle-Width="150px" DataField="RULE ID" HeaderText="RULE ID" />
<asp:BoundField ItemStyle-Width="150px" DataField="RULE TYPE ID" HeaderText="RULE TYPE ID" />
<asp:BoundField ItemStyle-Width="150px" DataField="START TIME" HeaderText="START TIME" />
<asp:BoundField ItemStyle-Width="150px" DataField="EXPIRY TIME" HeaderText="EXPIRY TIME" />
</Columns>
</asp:GridView>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="80px" ItemStyle-Width="80px" ItemStyle-HorizontalAlign="Center" HeaderText="Row Number">
<ItemTemplate>
<asp:Label ID="LabelRowNumberId" runat="server" Text='<%#Eval("Row Number") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="80px" ItemStyle-Width="80px" ItemStyle-HorizontalAlign="Center" HeaderText="POS Id">
<ItemTemplate>
<asp:Label ID="LabelPOSID" runat="server" Text='<%#Eval("POS Id") %>'></asp:Label>
<%-- <asp:LinkButton ID="LinkbtnPOSId" CommandArgument='<%#Eval("POS Id") %>' CommandName="ClickPOS" Text='<%#Eval("POS Id") %>' runat="server" CausesValidation="false"></asp:LinkButton>--%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="80px" ItemStyle-Width="250px" ItemStyle-HorizontalAlign="Center" HeaderText="Action">
<ItemTemplate>
<asp:LinkButton ID="HyperLinkAssociate" CommandArgument='<%#Eval("POS Id") %>' CommandName="Associate" Text="Associate" runat="server" OnClientClick="return OnClientClickAssociateRewardRuleFile(this);" CausesValidation="false"></asp:LinkButton>/
<asp:LinkButton ID="HyperLinkReplace" CommandArgument='<%#Eval("POS Id") %>' CommandName="Replace" Text="Replace" runat="server" OnClientClick="return OnClientClickReplaceRewardRuleFile(this);" CausesValidation="false"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="80px" ItemStyle-Width="250px" ItemStyle-HorizontalAlign="Center" HeaderText="Status">
<ItemTemplate>
<asp:Label runat="server" ID="LabelStatusPendingPOSId" Text='<%#Eval("Status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
In GridViewMultiplePOSAssociationId there is one column "Status" which has label LabelStatusPendingPOSId, LabelStatusPendingPOSId text is set Applied, Not Applied at the time of Binding. For Rows which has Status Applied, User should not be able to click on LinkButton Associate/Replace else He is allowed to click.
use this code OnRowDataBound for Your Grid
protected void grdViewCustomers_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.DataRow)
{
LinkButton LinkbtnPOSId=(LinkButton)e.Row.FindControl("LinkbtnPOSId");
Label LabelStatusPendingPOSId = (Label)e.Row.FindControl("LabelStatusPendingPOSId");
Boolean boolStatus = LabelStatusPendingPOSId.Text == "Applied" ? true : false;
//LinkbtnPOSId.Attributes.Add("onclick", "function CheckStatus('" + boolStatus.ToString() + "')");
LinkbtnPOSId.Enabled = boolStatus;
}
}
Try this..
You can loop through the Gridview and make the particular control disable...
I am writing the code in javascript pageload function...
function PageLoad(sender, args)
{
for (var i = 0; i <= RowCount; i++)
{
document.getElementById('Gridview1_HyperLinkAssociate_' + i.toString() + '').disabled = true;
}
}
Set RowCount as the number of rows of the Gridview...
I have a Strange issue that is i have develop a web application in one of the form i am using Gridview control with command button to view the row data.If in Gridview data have only record then link button working fine if it is more than one record not working link buttons i can't under stand, this is very strange issue to me i have use !Page.IsPostBack also in pageload event,please help me .....
protected void grdmanageloans_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Info")
{
try
{
int loanid = Convert.ToInt32(e.CommandArgument);
Session["Loanid"] = loanid;
Session["Edit"] = "Edit";
TabContainer1.ActiveTabIndex = 1;
Session["TabContainer1"] ="loantab";
Session["Tabloan"] = "Tabloan";
Response.Redirect("Mortgageclient.aspx");
}
catch { }
}
if (e.CommandName == "Delete")
{
try
{
int LoanId = Convert.ToInt32(e.CommandArgument);
var PmtScheduleHistory = from del in mortgageentity.Pmt_Schedule_History where del.Loan.Loan_ID == LoanId select del;
var LoanPayment = from del in mortgageentity.Payments where del.Loan_ID == LoanId select del;
if (PmtScheduleHistory.Count() > 0)
{
var DelPmtScheduleHistory = (from del in mortgageentity.Pmt_Schedule_History where del.Loan.Loan_ID == LoanId select del).First();
mortgageentity.DeleteObject(DelPmtScheduleHistory);
mortgageentity.SaveChanges();
}
var Getpayments = from db in mortgageentity.Payments where db.Loan_ID == LoanId select db;
if (Getpayments.Count() > 0)
{
foreach (var i in Getpayments)
{
mortgageentity.DeleteObject(i);
mortgageentity.SaveChanges();
}
}
if (LoanPayment.Count() > 0)
{
var DelPmtScheduleHistory = (from del in mortgageentity.Payments where del.Loan_ID == LoanId select del.Payment_Status.PaymentStatus_ID).First();
mortgageentity.DeleteObject(DelPmtScheduleHistory);
mortgageentity.SaveChanges();
}
var deletedata = (from del in mortgageentity.Loans where del.Loan_ID == LoanId select del).First();
mortgageentity.DeleteObject(deletedata);
mortgageentity.SaveChanges();
BindData();
}
catch { }
}
if (e.CommandName == "AddNewloan")
{
Session["Addnewloan"] = "Addloan";
Response.Redirect("Information.aspx");
}
}
Here is my .aspx page
<asp:GridView ID="grdmanageloans" runat="server" AutoGenerateColumns="False" AllowSorting="True"
GridLines="Both" PageSize="10" AllowPaging="true" OnRowCommand="grdmanageloans_RowCommand"
OnSelectedIndexChanged="grdmanageloans_SelectedIndexChanged" ShowFooter="true"
OnPageIndexChanging="grdmanageloans_PageIndexChanging" OnRowDataBound="grdmanageloans_Rowdatabound">
<AlternatingRowStyle BackColor="#F3F9FB" />
<RowStyle BackColor="#FEFEFE" VerticalAlign="Top" />
<HeaderStyle BackColor="#F3F9FB" />
<FooterStyle BackColor="#F3F9FB" />
<RowStyle Wrap="False" />
<HeaderStyle ForeColor="#1F476F" />
<Columns>
<asp:TemplateField HeaderText="LoanID" Visible="true">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblloanid" runat="server" Text='<%# Bind("Loan_ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Loan Number">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblLoanNumber" runat="server" Text='<%# Bind("LoanNumber") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Month Pay Amt" HeaderStyle-Wrap="false">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblMonthPayAmt" runat="server" Text='<%#Getammount(Eval("MonthPayAmt","{0:F2}")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblpropaddress" runat="server" Text='<%# Bind("PropAddress") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="City">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblpropcity" runat="server" Text='<%# Bind("PropCity") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="State">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblpropstate" runat="server" Text='<%# Bind("PropState") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ClientID" Visible="false">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblclientid" runat="server" Text='<%# Bind("Client_ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:LinkButton ID="lnkeinfo" runat="server" CausesValidation="false" CommandName="Info"
CommandArgument='<%#Eval("Loan_ID")%>'>Information</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Try this:
<asp:LinkButton ID="lnkeinfo" runat="server" CausesValidation="false" CommandName="Info"
CommandArgument='<%# Bind("Loan_ID") %>'>Information</asp:LinkButton>
Why don't you use a RESTful architecture to not save those parameters in Session and make pages kind'ev tightly coupled? Just create links named Info in your Grid instead of buttons (which post back data) with those parameters appended to the end of them as querystring. This is nicer approach and the result is the same.