I am facing a problem with below code. When I click on Repsendbtn it stores the same session value of UsrNme into both columns Receiver and Sender, where it is supposed to save session value into Receiver and into Sender the value of tolbl
<asp:FormView ID="repmsgform" runat="server" DataKeyNames="mailno" Width="100%" >
<ItemTemplate>
<div class="col-lg-12">
<form class="well span8">
<div class="row">
<div class="span3">
<label>From</label>
<asp:Label ID="tolbl" runat="server" CssClass="form-control" Text='<%# Bind("Receiver") %>'></asp:Label>
<label>To</label>
<asp:Label ID="frmlbl" runat="server" CssClass="form-control" Text='<%# Bind("sender") %>'></asp:Label>
<label>Ads Title</label>
<asp:Label ID="MsgTitLbl" runat="server" CssClass="form-control" Text='<%# Bind("Mestitle") %>'></asp:Label>
<asp:Label ID="adsnummsglbl" runat="server" Text='<%# Bind("AdsID") %>' Visible="false" ></asp:Label>
<asp:Label ID="mailnolbl" runat="server" Text='<%# Bind("mailno") %>' Visible="false" ></asp:Label>
</div>
<div class="span5">
<label>Message</label>
<asp:TextBox ID="TextBox15" runat="server" TextMode="MultiLine" Height="150px" CssClass="form-control"></asp:TextBox>
</textarea>
</div>
<asp:Label ID="msgsentlbl" runat="server" Font-Size="Medium" ForeColor="#669900"></asp:Label>
<asp:Button runat="server" ID="Repsendbtn" Text="Send" CssClass="btn btn-primary pull-right" OnCommand=" Repsendbtn_Command" CommandArgument='<%# Bind ("mailno") %>'/>
<asp:Button ID="Closebtn" runat="server" Text="Close" CssClass="btn btn-default pull-right" OnCommand=" Closebtn_Command" />
</div>
</form>
</div>
</ItemTemplate>
</asp:FormView>
Code:
protected void Repsendbtn_Command(object sender, CommandEventArgs e)
{
if (Session["UsrNme"] != null)
{
using (SqlConnection cn = new SqlConnection(sc))
{
string SendMsgSQL = #"INSERT INTO mails (AdsID, Mestitle, Message, Receiver, sender, Date) VALUES (#AdsID, #Mestitle, #Message, #Receiver, #sender, #Date)";
using (SqlCommand SendMsgcmd = new SqlCommand(SendMsgSQL, cn))
{
cn.Open();
var user = Session["UsrNme"];
SendMsgcmd.Parameters.AddWithValue("#Receiver", user);
SendMsgcmd.Parameters.AddWithValue("#Message", ((TextBox)repmsgform.FindControl("TextBox15")).Text);
SendMsgcmd.Parameters.AddWithValue("#Mestitle", ((Label)repmsgform.FindControl("MsgTitLbl")).Text);
SendMsgcmd.Parameters.AddWithValue("#AdsID", ((Label)repmsgform.FindControl("adsnummsglbl")).Text);
SendMsgcmd.Parameters.AddWithValue("#Date", DateTime.Now);
SendMsgcmd.Parameters.AddWithValue("#sender", ((Label)repmsgform.FindControl("tolbl")).Text);
SendMsgcmd.ExecuteNonQuery();
viewmsgView.Visible = true;
}
}
}
else
{
// Consider throwing an error (if these fields are required)
}
}
Related
I have a GridView in which I'm letting users edit previously generated estimates. Everything works fine till I hit recalculate button but after that, all the row values go haywire.
Below is a screenshot of the layout for your reference.
In that, All the details are being fetched from database and few of them are editable and after changing the values, below there is a refresh button which I'm using to recalculate. but my loop is causing them to calculate incorrectly. Please help me rectify my mistake.
below is my aspx code:
<div class="card-body">
<div class="row">
<div class="col-md-12">
<asp:GridView ID="grdPurchaseBill" runat="server" CssClass="table table-bordered table-responsive table-sm" AutoGenerateColumns="False" ShowFooter="false">
<Columns>
<asp:TemplateField HeaderText="Product" ItemStyle-Wrap="false" ControlStyle-Width="100%" ItemStyle-Width="100%">
<ItemTemplate>
<asp:TextBox ID="txtProduct" runat="server" CssClass="form-control form-control-sm" Width="100%" Style="width: 100%;" AutoCompleteType="Disabled" autocomplete="off" Text='<%# Eval("product") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Weight" ItemStyle-Wrap="false" HeaderStyle-Wrap="false">
<ItemTemplate>
<asp:TextBox ID="txtWeight" runat="server" CssClass="form-control form-control-sm" Text='<%# Eval("weight") %>' Width="100%" Style="width: 100%;"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="# of Bags" ItemStyle-Wrap="false" ControlStyle-Width="100%" HeaderStyle-Wrap="false">
<ItemTemplate>
<asp:TextBox ID="txtBags" runat="server" CssClass="form-control form-control-sm" Text='<%# Eval("bags") %>' Width="100%" Style="width: 100%;"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Shortage %" ItemStyle-Wrap="false" ControlStyle-Width="100%" HeaderStyle-Wrap="false">
<ItemTemplate>
<asp:TextBox ID="txtShortagePercent" runat="server" CssClass="form-control form-control-sm" Text='<%# Eval("shortage_percent") %>' Width="100%" Style="width: 100%;"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Shortage" ItemStyle-Wrap="false" ControlStyle-Width="100%" HeaderStyle-Wrap="false">
<ItemTemplate>
<asp:TextBox ID="txtShortage" runat="server" CssClass="form-control form-control-sm" Text='<%# Eval("shortage") %>' Width="100%" Style="width: 100%;" Enabled="false"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Net Weight" ItemStyle-Wrap="false" ControlStyle-Width="100%" HeaderStyle-Wrap="false">
<ItemTemplate>
<asp:TextBox ID="txtNetWeight" runat="server" CssClass="form-control form-control-sm" Text='<%# Eval("net_weight") %>' Width="100%" Style="width: 100%;" Enabled="false"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Unit Price" ItemStyle-Wrap="false" HeaderStyle-Wrap="false" ControlStyle-Width="100%">
<ItemTemplate>
<asp:TextBox ID="txtRate" runat="server" CssClass="form-control form-control-sm" Text='<%# Eval("rate") %>' Width="100%" Style="width: 100%;"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sub-Total" ItemStyle-Wrap="false" HeaderStyle-Wrap="false" ControlStyle-Width="100%">
<ItemTemplate>
<asp:TextBox ID="txtSubTotal" runat="server" CssClass="form-control form-control-sm" Text='<%# Eval("sub_total") %>' Width="100%" Style="width: 100%;" Enabled="false"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Hamali %" ItemStyle-Wrap="false" HeaderStyle-Wrap="false" ControlStyle-Width="100%">
<ItemTemplate>
<asp:TextBox ID="txtHamali" runat="server" CssClass="form-control form-control-sm" Text='<%# Eval("hamali_percent") %>' Width="100%" Style="width: 100%;"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Hamali Amt" ItemStyle-Wrap="false" HeaderStyle-Wrap="false" ControlStyle-Width="100%">
<ItemTemplate>
<asp:TextBox ID="txtHamaliAmount" runat="server" CssClass="form-control form-control-sm" Text='<%# Eval("hamali") %>' Width="100%" Style="width: 100%;" Enabled="false"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Driver Comm. " ItemStyle-Wrap="false" HeaderStyle-Wrap="false" ControlStyle-Width="100%">
<ItemTemplate>
<asp:TextBox ID="txtDriverCommission" runat="server" CssClass="form-control form-control-sm" Text='<%# Eval("driver_commission") %>' Width="100%" Style="width: 100%;"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Net Amt" ItemStyle-Wrap="false" ControlStyle-Width="100%" HeaderStyle-Wrap="false">
<ItemTemplate>
<asp:TextBox ID="txtNetAmount" runat="server" CssClass="form-control form-control-sm" Enabled="false" Text='<%# Eval("net_amount") %>' Width="100%" Style="width: 100%;"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Bill Date</label>
<div class="input-group margin input-group-sm">
<asp:TextBox ID="txtBDate" runat="server" CssClass="form-control form-control-sm" TabIndex="1" AutoCompleteType="Disabled" autocomplete="off"></asp:TextBox>
<ajax:CalendarExtender ID="ce1" runat="server" TargetControlID="txtBDate" Format="dd-MM-yyyy" />
<span class="input-group-btn">
<span class="fa fa-times"></span>
</span>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Name</label>
<div class="input-group input-group-sm">
<asp:TextBox ID="txtcname" runat="server" CssClass="form-control form-control-sm" TabIndex="2" CausesValidation="True" AutoCompleteType="Disabled" autocomplete="off"></asp:TextBox>
<asp:HiddenField ID="hfCustomerId" runat="server" />
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Phone</label>
<asp:TextBox ID="txtcmobile" runat="server" CssClass="form-control form-control-sm" TabIndex="3" AutoCompleteType="Disabled" autocomplete="off"></asp:TextBox>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Address</label>
<asp:TextBox ID="txtcaddress" runat="server" TextMode="MultiLine" TabIndex="6" CssClass="form-control form-control-sm"></asp:TextBox>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Lorry Freight</label>
<asp:TextBox ID="txtLorryFreight" runat="server" TabIndex="6" CssClass="form-control form-control-sm"></asp:TextBox>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Remarks</label>
<asp:TextBox ID="txtRemarks" runat="server" TabIndex="6" CssClass="form-control form-control-sm" TextMode="MultiLine"></asp:TextBox>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Total Amount</label>
<asp:Label ID="lblTotal" runat="server" CssClass="form-control form-control-sm lblTotal" Text="0" ForeColor="Blue" BackColor="#DEE2E6"></asp:Label>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Payable Amount</label>
<asp:Label ID="lblPayableAmt" runat="server" CssClass="form-control form-control-sm lblPayableAmt" Text="0" ForeColor="Blue" BackColor="#DEE2E6"></asp:Label>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Paid Amount</label>
<asp:TextBox ID="txtPaidAmt" runat="server" CssClass="form-control form-control-sm txtPaidAmt" OnTextChanged="CalculatePaidAmount" AutoPostBack="true" TabIndex="8" ForeColor="Blue" Text="0"></asp:TextBox>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Balance Amount</label>
<div class="input-group input-group-sm">
<label id="lblBalAmt" runat="server" class="form-control form-control-sm lblBalAmt" style="color: red; background-color: #DEE2E6;">0</label>
<span class="input-group-append">
<asp:LinkButton ID="lnkPayable" runat="server" OnClick="ReCalculate" CssClass="btn btn-outline-success btn-flat" Text="" TabIndex="9" CausesValidation="false"><i class="fa fa-sync"></i></asp:LinkButton>
</span>
</div>
</div>
</div>
</div>
</div>
And my aspx.cs code:
protected void GetBillDetails()
{
string query = "select * from estimates where bno='" + Request.QueryString["bno"].ToString() + "';";
grdPurchaseBill.DataSource = dal.GetData(query);
grdPurchaseBill.DataBind();
using (SqlConnection con = new SqlConnection(cm.constring))
{
con.Open();
using (SqlCommand cmd = new SqlCommand(query, con))
{
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
txtBDate.Text = dr["bill_date"].ToString();
txtcname.Text = dr["name"].ToString();
txtcmobile.Text = dr["mobileno"].ToString();
txtcaddress.Text = dr["address"].ToString();
txtLorryFreight.Text = dr["lorry_freight"].ToString();
txtRemarks.Text = dr["remarks"].ToString();
lblTotal.Text = dr["grand_total"].ToString();
lblPayableAmt.Text = dr["payable_amount"].ToString();
txtPaidAmt.Text = dr["paid_amount"].ToString();
lblBalAmt.InnerText = dr["balance_amount"].ToString();
bno.InnerText = Request.QueryString["bno"].ToString();
}
}
}
con.Close();
}
}
protected void ReCalculate(object sender, EventArgs e)
{
decimal PayableAmount = 0, PaidAmount = !string.IsNullOrEmpty(txtPaidAmt.Text) ? Convert.ToDecimal(txtPaidAmt.Text) : 0, NetWeight = 0, SubTotal = 0, NetAmount = 0;
foreach (GridViewRow Row in grdPurchaseBill.Rows)
{
TextBox txtProduct = Row.FindControl("txtProduct") as TextBox;
TextBox txtWeight = Row.FindControl("txtWeight") as TextBox;
TextBox txtBags = Row.FindControl("txtBags") as TextBox;
TextBox txtShortagePercent = Row.FindControl("txtShortagePercent") as TextBox;
TextBox txtShortage = Row.FindControl("txtShortage") as TextBox;
TextBox txtNetWeight = Row.FindControl("txtNetWeight") as TextBox;
TextBox txtRate = Row.FindControl("txtRate") as TextBox;
TextBox txtSubTotal = Row.FindControl("txtSubTotal") as TextBox;
TextBox txtHamali = Row.FindControl("txtHamali") as TextBox;
TextBox txtHamaliAmount = Row.FindControl("txtHamaliAmount") as TextBox;
TextBox txtDriverCommission = Row.FindControl("txtDriverCommission") as TextBox;
TextBox txtNetAmount = Row.FindControl("txtNetAmount") as TextBox;
Control txtShortagePercent_ctrl = Row.FindControl("txtShortagePercent") as TextBox;
if (txtShortagePercent_ctrl != null)
{
txtShortage.Text = (Convert.ToDecimal(txtWeight.Text) - (Convert.ToDecimal(txtWeight.Text) - (Convert.ToDecimal(txtWeight.Text)) * (Convert.ToDecimal(txtShortage.Text) / 100))).ToString("#0.00");
//txtHamaliAmount.Text = (calculateHamali(Convert.ToDecimal(txtWeight.Text), Convert.ToDecimal(txtHamali.Text))).ToString("#0.00");
decimal TotalHamali = Convert.ToDecimal(txtHamali.Text) > 0 ? ((Convert.ToDecimal(txtWeight.Text) / 100) * Convert.ToDecimal(txtHamali.Text)) : 0;
NetAmount += ((Convert.ToDecimal(txtSubTotal.Text) - TotalHamali));// + Convert.ToDecimal(txtDriverCommission.Text)
txtNetAmount.Text = NetAmount.ToString("#0.00");
txtHamaliAmount.Text = TotalHamali.ToString("#0.00");
NetWeight += (Convert.ToDecimal(txtWeight.Text) - (Convert.ToDecimal(txtWeight.Text) * Convert.ToDecimal(txtShortage.Text) / 100));
txtNetWeight.Text = NetWeight.ToString("#0.00");
txtShortage.Text = (Convert.ToDecimal(txtWeight.Text) - (Convert.ToDecimal(txtWeight.Text) - (Convert.ToDecimal(txtWeight.Text) * Convert.ToDecimal(txtShortage.Text) / 100))).ToString();
SubTotal += (Convert.ToDecimal(txtNetWeight.Text) * Convert.ToDecimal(txtRate.Text));
txtSubTotal.Text = SubTotal.ToString("#0.00");
TextBox totamt = Row.FindControl("txtNetAmount") as TextBox;
PayableAmount += Convert.ToDecimal(!string.IsNullOrEmpty(totamt.Text) ? totamt.Text : "0");
}
}
lblTotal.Text = (PayableAmount).ToString("#0.00");
lblPayableAmt.Text = (PayableAmount - Convert.ToDecimal(!string.IsNullOrEmpty(txtLorryFreight.Text) ? txtLorryFreight.Text : "0")).ToString("#0.00");
lblBalAmt.InnerText = (PaidAmount > 0 ? Convert.ToDecimal(lblPayableAmt.Text) - PaidAmount : Convert.ToDecimal(lblPayableAmt.Text) - 0).ToString("#0.00");
}
I have a modal inside an update panel which give information of student when click on argument in a grid view.
In my modal I have also 3 textbox in which the value need to be save when click in save button.
It is not triggering the save button.
Here is my code:
<div class="modal fade" id="studinfo" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Student Info</h4>
<button type="button" class="close"
data-dismiss="modal">
×</button>
</div>
<div class="modal-body">
<asp:UpdatePanel ID="updModal" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<div class="card h-100">
<div class="card-body">
<ul class="list-group list-group-flush">
<asp:TextBox ID="txtId" Visible="false" runat="server"></asp:TextBox>
<asp:Panel ID="typepannel" CssClass="list-group-item" runat="server">
<asp:Label ID="lbltype" runat="server"
Font-Bold="true" Text="Candidate Type: "></asp:Label>
<asp:Label ID="type" runat="server"
Text=''>
</asp:Label>
</asp:Panel>
<asp:Panel ID="colpanel" CssClass="list-group-item" runat="server">
<asp:Label ID="lblCol" runat="server"
Font-Bold="true" Text="College Attend: "></asp:Label>
<asp:Label ID="college" runat="server"
Text=''>
</asp:Label>
</asp:Panel>
<div class="list-group-item">
<asp:Label ID="lblName" runat="server"
Font-Bold="true" Text="Name: "></asp:Label>
<asp:Label ID="Name" runat="server"
Text=''>
</asp:Label>
</div>
<div class="list-group-item">
<asp:Label ID="lblNic" runat="server"
Font-Bold="true" Text="Nic: "></asp:Label>
<asp:Label ID="Nic" runat="server"
Text=''>
</asp:Label>
</div>
<div class="list-group-item">
<asp:Label ID="lblAge" runat="server"
Font-Bold="true" Text="Age: "></asp:Label>
<asp:Label ID="Age" runat="server"
Text=''>
</asp:Label>
</div>
<div class="list-group-item">
<asp:Label ID="lblAdress" runat="server"
Font-Bold="true" Text="Address: "></asp:Label>
<asp:Label ID="Address" runat="server"
Text=''>
</asp:Label>
</div>
<div class="list-group-item">
<asp:Label ID="lblacad" runat="server"
Font-Bold="true" Text="Academy: "></asp:Label>
<asp:Label ID="Academy" runat="server"
Text=''>
</asp:Label>
</div>
<h6 class="mt-3 mb-3">Parent in Charge</h6>
<div class="list-group-item">
<asp:Label ID="lblParent" runat="server"
Font-Bold="true" Text="Parent Name: "></asp:Label>
<asp:Label ID="parentName" runat="server"
Text=''>
</asp:Label>
</div>
<div class="list-group-item">
<asp:Label ID="lblNumber" runat="server"
Font-Bold="true" Text="Parent Contact Number: "></asp:Label>
<asp:Label ID="Number" runat="server"
Text=''>
</asp:Label>
</div>
<div class="list-group-item">
<asp:Label ID="lblEmail" runat="server"
Font-Bold="true" Text="Parent Email Address: "></asp:Label>
<asp:Label ID="Email" runat="server"
Text=''>
</asp:Label>
</div>
<div class="list-group-item">
<asp:Label ID="lblResult" runat="server"
Font-Bold="true" Text="Result: "></asp:Label>
<asp:DropDownList ID="ddlResult"
CssClass="select form-control"
runat="server">
</asp:DropDownList>
</div>
<div class="list-group-item">
<asp:Label ID="lblMarks" runat="server" Font-Bold="true" Text="Marks: "></asp:Label>
<asp:TextBox runat="server" ID="txtMarks"
CssClass="form-control form-control-lg" />
<asp:RequiredFieldValidator ID="rfvMarks" runat="server"
Display="Dynamic" ForeColor="Red"
ControlToValidate="txtMarks"
SetFocusOnError="true"
ErrorMessage="Marks is Mandatory">
</asp:RequiredFieldValidator>
<asp:CompareValidator ID="cmpVMarks" runat="server"
ControlToValidate="txtMarks"
Operator="DataTypeCheck"
Type="Double"
SetFocusOnError="true"
Display="Dynamic"
Text="Incorect data type"
ForeColor="Red"
ErrorMessage="Invalid">
</asp:CompareValidator>
<asp:RegularExpressionValidator ID="revPhone"
runat="server"
ControlToValidate="txtMarks"
SetFocusOnError="true"
Display="Dynamic"
ForeColor="Red"
ValidationExpression="^\d\d+(\.[1-9])?$"
ErrorMessage="Invalid">
</asp:RegularExpressionValidator>
</div>
<div class="list-group-item">
<asp:Label ID="lblpurcentage" runat="server"
Font-Bold="true" Text="Purcentage : "></asp:Label>
<asp:TextBox runat="server" ID="txtpur"
CssClass="form-control form-control-lg" />
<asp:RequiredFieldValidator
ID="rfvpur" runat="server"
Display="Dynamic" ForeColor="Red"
ControlToValidate="txtpur"
SetFocusOnError="true"
ErrorMessage="Purcentage is Mandatory">
</asp:RequiredFieldValidator>
<asp:CompareValidator ID="cvpur" runat="server"
ControlToValidate="txtpur"
Operator="DataTypeCheck"
Type="Double"
SetFocusOnError="true"
Display="Dynamic"
Text="Incorect data type"
ForeColor="Red"
ErrorMessage="Invalid">
</asp:CompareValidator>
</div>
</ul>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="btnSave" OnClick="btnSave_Click"
CssClass="btn btn-success btn-block" runat="server" Text="Save" />
</div>
</div>
To make this data appear in modal I used updModal.Update(); in the button where I use to call the modal.
Here is my code behind of save button:
protected void btnSave_Click(object sender, EventArgs e)
{
try
{
string id = txtId.Text;
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "update tblStudent set stud_result=#res,stud_purcentage=#pur,stud_totalMarks=#marks where stud_Id=#id";
cmd.Parameters.AddWithValue("#id", id);
cmd.Parameters.AddWithValue("#res", ddlResult.SelectedValue);
cmd.Parameters.AddWithValue("#pur", txtpur.Text.Trim());
cmd.Parameters.AddWithValue("#marks", txtMarks.Text.Trim());
con.Open();
cmd.Connection = con;
updModal.Update();
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, GetType(), "LaunchServerSide",
"$(function () { showUErrorModal(); });", true);
}
finally
{
con.Close();
}
}
When I have try to put the button inside the update panel it freeze the app when I triger the button.
Can someone please please help me with that? Thank you in advance.
So i did a research about textmode time but it doesn't seem to help me. My problem is when i tried to bind the data with time textmode it won't display anything I already tried removing the textmode so i can see if it can display data and it does. Here's my code in the front, hope you'll help me. Thank you in advance
<asp:Repeater runat="server" ID="rptrTRFFormItems" OnItemDataBound="rptrTRFFormItems_ItemDataBound">
<ItemTemplate>
<tr>
<td>
<asp:Label runat="server" ID="No" Text='<%# Container.ItemIndex + 1 %>' Visible="false">
</asp:Label>
</td>
<td>
<asp:LinkButton runat="server" ID="btnAddItemRow" CssClass="actionbtnstyle fa fa-plus-square" CausesValidation="false" OnClick="btnAddItemRows" Style="font-size: 20px;">
</asp:LinkButton>
</td>
<td>
<asp:LinkButton runat="server" ID="btnDeleteItemRow" CssClass="actionbtnstyle fa fa-minus-square" CausesValidation="false" OnClick="btnDeleteItemRows" Style="font-size: 20px;">
</asp:LinkButton>
</td>
<td>
<div runat="server" id="divInputGroup">
<span runat="server" id="spanInputGroup">
<asp:Label runat="server" ID="validatetbName">
</asp:Label>
</span>
<asp:TextBox runat="server" ID="tbName" Text='<%#Eval("Name") %>' CssClass="form-control rptrtbstyle" ondrop="return false" title="Required" data-toggle="tooltip" TabIndex="13" data-placement="bottom">
</asp:TextBox>
</div>
</td>
<td>
<asp:UpdatePanel runat="server" ID="rptriddate" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="tbDate" EventName="TextChanged" />
</Triggers>
<ContentTemplate>
<div runat="server" id="divInputGroup0">
<span runat="server" id="spanInputGroup0">
<asp:Label runat="server" ID="validatetbDate">
</asp:Label>
</span>
<asp:TextBox runat="server" ID="tbDate" CssClass="form-control js-datepicker rptrtbstyle" Style="cursor: pointer;" TabIndex="14" data-toggle="tooltip" data-placement="bottom" title="Required" OnTextChanged="tbDate_TextChanged" autocomplete="off" AutoPostBack="true">
</asp:TextBox>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td>
<div runat="server" id="divInputGroup2">
<span runat="server" id="spanInputGroup2">
<asp:Label runat="server" ID="validatetbPreferredTime">
</asp:Label>
</span>
<asp:TextBox runat="server" ID="tbPreferredTime" Text='<%#Eval("PreferredTime") %>' format="HH:mm" TextMode="Time" CssClass="form-control rptrtbstyle" data-toggle="tooltip" TabIndex="15" data-placement="bottom" title="Required">
</asp:TextBox>
</div>
</td>
<td>
<div runat="server" id="divInputGroup1">
<span runat="server" id="spanInputGroup1">
<asp:Label runat="server" ID="validatetbFromRptr">
</asp:Label>
</span>
<asp:TextBox runat="server" ID="tbFromRptr" Text='<%#Eval("FromRptr") %>' CssClass="form-control rptrtbstyle" data-toggle="tooltip" data-placement="bottom" TabIndex="16" title="Required" AutoPostBack="false">
</asp:TextBox>
</div>
</td>
<td>
<asp:LinkButton runat="server" ID="btnExchange" CssClass="actionbtnstyle fa fa-exchange" CausesValidation="false" Style="font-size: 20px;">
</asp:LinkButton>
</td>
<td>
<div runat="server" id="divInputGroup3">
<span runat="server" id="spanInputGroup3">
<asp:Label runat="server" ID="validatetbToRptr">
</asp:Label>
</span>
<asp:TextBox runat="server" ID="tbToRptr" Text='<%#Eval("ToRptr") %>' CssClass="form-control rptrtbstyle" TabIndex="17" data-toggle="tooltip" data-placement="bottom" title="Required">
</asp:TextBox>
</div>
</td>
</tr>
<%--</ContentTemplate> </asp:UpdatePanel>--%>
</ItemTemplate>
</asp:Repeater>
And here's the code to bind data from behind.
using(SqlConnection con = new SqlConnection(travelrequest))
{
using(SqlCommand cmd = con.CreateCommand())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "TRFSearchByRefernce";
cmd.Parameters.AddWithValue("#trfNo", txtSearchByReference.Text);
cmd.Parameters.AddWithValue("#fullname", lblFullname01.Text);
using(SqlDataAdapter adp = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
adp.Fill(dt);
if(dt.Rows.Count > 0)
{
rptrTRFFormItems.DataSource = dt;
rptrTRFFormItems.DataBind();
ViewState["CurrentTable"] = dt;
}
else
{
SetInitialRow();
}
}
}
}
and here's my stored procedure sql query
SELECT
[TRFGName] as Name
,[TRFGDate] as [Date]
,[TRFGTimeRef] as PreferredTime
,[TRFGFrom] as FromRptr
,[TRFGTo] as ToRptr
,[TRFGNo]
,[TRFGControlNo]
,[TRFRequester]
FROM [TRAVELREQUESTFORM].[TRAVEL].[TRAVELGRID] WHERE TRFGControlNo = #trfNo and TRFRequester = #fullname
I have an asp.net webforms c# application that has a FileUpload control inside the InsertItemTemplate of a FormView. When inserting the new record the correct path + filename is saved to the appropriate field in the database, but the file isn't saved to the Data folder. Here is the code behind:
protected void fv_ven_doc_det_DataBound(object sender, EventArgs e)
{
if (fv_ven_doc_det.CurrentMode == FormViewMode.Insert)
{
//Set the fk
TextBox venIdFkTxt = (TextBox)fv_ven_doc_det.FindControl("venIdFkTextBox");
if (venIdFkTxt != null)
{
venIdFkTxt.Text = hdn_ven_id.Value;
}
//Get the upload date - current date and time
hdn_doc_upload_dt_txt.Value = DateTime.Now.ToString();
string docuplddt = fv_ven_doc_det.FindControl("docUpldDtTextBox").ToString();
docuplddt = hdn_doc_upload_dt_txt.Value;
TextBox docuplddttxt = (TextBox)fv_ven_doc_det.FindControl("docUpldDtTextBox");
if (docuplddttxt != null)
{
docuplddttxt.Text = hdn_doc_upload_dt_txt.Value;
}
//Set the current status
TextBox crntDocStatTxt = (TextBox)fv_ven_doc_det.FindControl("docStatTextBox");
if (crntDocStatTxt != null)
{
crntDocStatTxt.Text = "4";
}
//Set the filename and save the file
int i = 0;
FileUpload fu = (FileUpload)(fv_ven_doc_det.FindControl("fu_doc_upld"));
string filename = fu.FileName;
if (fu.HasFile == true)
{
while (System.IO.File.Exists(Server.MapPath("~/Data/") + filename))
{
i++;
filename = fu.FileName + " (" + i.ToString() + ")";
}
fu.PostedFile.SaveAs(Server.MapPath("~/Data/") + filename);
}
TextBox filenameTxt = (TextBox)fv_ven_doc_det.FindControl("docPathTextBox");
{
filenameTxt.Text = (Server.MapPath("~/Data/") + filename);
}
}
}
Here is the InsertItemTemplate of the FormView:
<InsertItemTemplate>
<asp:TextBox Text='<%# Bind("venIdFk") %>' runat="server" ID="venIdFkTextBox" Visible="false" />
<asp:TextBox Text='<%# Bind("docPath") %>' runat="server" ID="docPathTextBox" Visible="false" />
<asp:TextBox Text='<%# Bind("docStat") %>' runat="server" ID="docStatTextBox" Visible="false" />
<asp:TextBox Text='<%# Bind("docUpldDt") %>' runat="server" ID="docUpldDtTextBox" Visible="false" />
<div class="row">
<div class="form-group col-md-3">
<strong>Title</strong><br />
<asp:TextBox Text='<%# Bind("docTitle") %>' runat="server" ID="docTitleTextBox" CssClass="form-control widecontrol" /><br />
</div>
<div class="form-group col-md-3">
<strong>Type</strong><br />
<asp:DropDownList ID="ddlVenDocType" runat="server" DataSourceID="sdc_doc_type" DataTextField="dtype" DataValueField="dtypeId" SelectedValue='<%# Bind("docType") %>' AppendDataBoundItems="true" CssClass="form-control widecontrol"><asp:ListItem Value="">--Please Select--</asp:ListItem></asp:DropDownList><br />
</div>
<div class="form-group col-md-3">
<strong>Organization</strong><br />
<asp:DropDownList ID="ddlVenDocOrg" runat="server" DataSourceID="sdc_orgs" DataTextField="org" DataValueField="orgId" SelectedValue='<%# Bind("docOrg") %>' AppendDataBoundItems="true" CssClass="form-control widecontrol"><asp:ListItem Value="">--Please Select--</asp:ListItem></asp:DropDownList><br />
</div>
<div class="form-group col-md-3">
<strong>Department</strong><br />
<asp:DropDownList ID="ddlVenDocDept" runat="server" DataSourceID="sdc_depts" DataTextField="dept" DataValueField="deptId" SelectedValue='<%# Bind("docDept") %>' AppendDataBoundItems="true" CssClass="form-control widecontrol"><asp:ListItem Value="">--Please Select--</asp:ListItem></asp:DropDownList><br />
</div>
</div>
<div class="row">
<div class="form-group col-md-3">
<strong>Prior Contract Code</strong><br />
<asp:TextBox Text='<%# Bind("PriorContCd") %>' runat="server" ID="PriorContCdTextBox" CssClass="form-control widecontrol" /><br />
</div>
<div class="form-group col-md-3">
<strong>Legal / Compliance Contract ID</strong><br />
<asp:TextBox Text='<%# Bind("LegCompContId") %>' runat="server" ID="LegCompContIdTextBox" CssClass="form-control widecontrol" /><br />
</div>
</div>
<div class="row">
<div class="form-group col-md-12">
<strong>Description</strong><br />
<asp:TextBox Text='<%# Bind("docDesc") %>' runat="server" ID="docDescTextBox" CssClass="form-control widecontrol" Rows="5" TextMode="MultiLine" /><br />
</div>
</div>
<div class="row">
<div class="form-group col-md-12">
<asp:FileUpload ID="fu_doc_upld" runat="server" />
<asp:RequiredFieldValidator ID="rfv_fu_doc_upld" runat="server" ErrorMessage="A file must be chosen to upload." ControlToValidate="fu_doc_upld" ForeColor="#ff0000" Font-Bold="true">*</asp:RequiredFieldValidator>
</div>
</div>
<asp:LinkButton runat="server" Text="Insert" CommandName="Insert" ID="InsertButton" CausesValidation="True" CssClass="cmdlinkpdg" /> <asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" ID="InsertCancelButton" CausesValidation="False" CssClass="cmdlinkpdg" />
</InsertItemTemplate>
I'm not getting any errors, it just doesn't save the file.
OK, it helps to stop and think about what actually needs to happen. I moved the filename / path and upload to OnItemInserting and it all works now.
Hi i want to make a footertemplate which can expand and collapse results like this image example in other topic: How do I add FooterTemplate to GridView with BoundFields
I want for default show 1 result, and after clicking in a icon on footertemplate show me more results like 4 or 5, i can show the code, thanks in advance.
The same work i have done on my project! I am pasting that work here. Please go through it, it might help you solving your problem
ASPX:
<asp:GridView Width="100%" border="1" ID="gwProfit" RowStyle-Wrap="true" runat="server" AutoGenerateColumns="false" AlternatingRowStyle-CssClass="alternaterow" RowStyle-VerticalAlign="Bottom" ShowFooter="True" HeaderStyle-Wrap="true" OnRowCommand="gwProfit_RowCommand" OnRowDataBound="gwProfit_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Start Date">
<ItemTemplate>
<div class="input-append">
<asp:TextBox class="input_disabled" ID="txtStartDate" runat="server" Width="110px" Height="22px" Text='<%# Bind("StartDate","{0}") %>'>
</asp:TextBox>
<button class="btn123" ID="ImgStartDate" runat="server" type="button" style="height:25px;">
<i class="icon-calendar"></i>
</button>
</div>
<ajaxToolkit:CalendarExtender ID="StartDate" runat="server" TargetControlID="txtStartDate" PopupButtonID="ImgStartDate" Format="dd-MMM-yyyy">
</ajaxToolkit:CalendarExtender>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox class="input_disabled" ID="txtNewStartDate" runat="server" Width="110px" Height="22px">
</asp:TextBox>
<button class="btn123" ID="ImgStartDate" runat="server" type="button" style="height:25px;">
<i class="icon-calendar"></i>
</button>
</div>
<ajaxToolkit:CalendarExtender ID="StartDate" runat="server" TargetControlID="txtNewStartDate"
PopupButtonID="ImgStartDate" Format="dd-MMM-yyyy">
</ajaxToolkit:CalendarExtender>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="End Date">
<ItemTemplate>
<asp:TextBox class="input_disabled" ID="txtEndDate" runat="server" Width="110px" Height="22px" Text='<%# Bind("EndDate","{0}") %>'>
</asp:TextBox>
<button class="btn123" ID="ImgEndDate" runat="server" type="button" style="height:25px;">
<i class="icon-calendar"></i>
</button>
<ajaxToolkit:CalendarExtender ID="EndDate" runat="server" TargetControlID="txtEndDate"
PopupButtonID="ImgEndDate" Format="dd-MMM-yyyy">
</ajaxToolkit:CalendarExtender>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox class="input_disabled" ID="txtNewEndDate" runat="server" Width="110px" Height="22px">
</asp:TextBox>
<button class="btn123" ID="ImgEndDate" runat="server" type="button" style="height:25px;">
<i class="icon-calendar"></i>
</button>
<ajaxToolkit:CalendarExtender ID="EndDate" runat="server" TargetControlID="txtNewEndDate"
PopupButtonID="ImgEndDate" Format="dd-MMM-yyyy">
</ajaxToolkit:CalendarExtender>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Profit Per Unit">
<ItemTemplate>
<asp:TextBox class="input_disabled" ID="txtProfitPerUnit" Width="100px" Height="22px" runat="server" Text='<%# Bind("ProfitPerUnit","{0}") %>'> </asp:TextBox>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox class="input_disabled" ID="txtNewProfitPerUnit" Width="100px" Height="22px" runat="server" Text="0"/>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action" ControlStyle-Width="14px" FooterStyle-Width="14px">
<ItemTemplate>
<input type="hidden" id="txtrec_status" name="txtrec_status" runat="server"/>
<asp:ImageButton ID="btnDelete" runat="server" CommandName="Delete" ImageUrl="~/images/delete.gif" AlternateText="Delete" CommandArgument="<%# ((GridViewRow) Container).RowIndex%>" UseSubmitBehavior="False" />
</ItemTemplate>
<FooterTemplate>
<asp:ImageButton ID="btnAdd" runat="server" CommandName="Add" ImageUrl="~/images/add.png" AlternateText="Add" UseSubmitBehavior="False"/>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
CodeBehind:
protected void gwProfit_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (ViewState["dtStartDate"] != null)
dtStartDate = (DataTable) ViewState["dtStartDate"];
if (e.CommandName.Equals("Add"))
{
TextBox txtStartDate = (TextBox)gwProfit.FooterRow.FindControl("txtNewStartDate");
TextBox txtEndDate = (TextBox)gwProfit.FooterRow.FindControl("txtNewEndDate");
TextBox txtProfitPerUnit = (TextBox)gwProfit.FooterRow.FindControl("txtNewProfitPerUnit");
if (txtEndDate.Text == "" || txtStartDate.Text == "" || txtProfitPerUnit.Text == "")
{
ScriptManager.RegisterStartupScript(this, GetType(), "alert", "alert('Please Select Start Date, End Date And Profit Per Unit.')", true);
}
else
{
dtStartDate.Rows.Add(dtStartDate.NewRow());
dtStartDate.Rows[dtStartDate.Rows.Count - 1]["CurrencyDeatailID"] = -2;
dtStartDate.Rows[dtStartDate.Rows.Count - 1]["StartDate"] = objFunc.toDate(txtStartDate.Text);
dtStartDate.Rows[dtStartDate.Rows.Count - 1]["EndDate"] = objFunc.toDate(txtEndDate.Text);
dtStartDate.Rows[dtStartDate.Rows.Count - 1]["ProfitPerUnit"] = objFunc.toDecimal(txtProfitPerUnit.Text);
if (dtStartDate.Rows.Count >= 0&&dtStartDate.Rows[0]["CurrencyDeatailID"].ToString()=="-1")
{
dtStartDate.Rows[0].Delete();
if (dtStartDate.Rows.Count > 0 && dtStartDate.Rows[0].RowState == DataRowState.Deleted)
dtStartDate.Rows.RemoveAt(0);
}
ViewState["dtStartDate"] = dtStartDate;
Profit_LoadGrid();
}
}
else if (e.CommandName.Equals("Delete"))
{
int index = objFunc.toInt(e.CommandArgument.ToString());
GridViewRow gvr = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);
int RemoveAt = gvr.RowIndex;
DataTable dt = new DataTable();
dt = (DataTable)ViewState["dtStartDate"];
dt.Rows.RemoveAt(RemoveAt);
dt.AcceptChanges();
ViewState["dtStartDate"] = dt;
Profit_LoadGrid();
}
}
It would be easy
Activate "AllowPaging" in your GridView.
Make Paging row invisible.
In every click of an icon increase "PageSize" for expanding or click of another icon decrease "PageSize" for collapsing.