Why DropDownList value is missing during postback? - c#

I have a DropDownList whose value is missing when I trigger post-back. Here my aspx, JavaScript and C# code.
Javascript:
<script type="text/javascript">
function stfocus(event) {
if (event.keyCode == 13) {
document.getElementById('tbfrompalletno').focus();
}
}
function tblocenter(event) {
if (event.keyCode == 13) {
__doPostBack('__Page', 'save');
}
}
</script>
ASPX:
<table>
<tr>
<td colspan="2" style="text-anchor: middle; text-align: center; border: thin solid #000000; background-color: #CCCCCC;">
<asp:Label ID="lblheader" runat="server" Text="Partial Pallet Transfer"></asp:Label>
</td>
</tr>
<tr>
<td colspan="2" style="text-align: left">
<asp:Label ID="Label_ErrorMsg" runat="server" Text="" BackColor="Red" ForeColor="White" />
<asp:Label ID="Label_Info" runat="server" Text="" BackColor="Green" ForeColor="White" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblwhscode" runat="server" Text="WHS Code:"></asp:Label>
</td>
<td>
<asp:DropDownList ID="cbwhscode" runat="server"
DataSourceID="sql_whs_code" DataTextField="whs_name" DataValueField="whs_code">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblfromloc" runat="server" Text="From Location:"></asp:Label>
</td>
<td>
<asp:TextBox ID="tbfromloc" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblfrompalletno" runat="server" Text="From Pallet:"></asp:Label>
</td>
<td>
<asp:TextBox ID="tbfrompalletno" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center;">
<asp:Button ID="btnsubmit" runat="server" Text="Submit" OnClick="btnsubmit_Click" UseSubmitBehavior="false" />
<asp:Button ID="btnback" runat="server" Text="Back" OnClick="btnback_Click" UseSubmitBehavior="false" />
<asp:Button ID="btnhome" runat="server" Text="Home" OnClick="btnhome_Click" UseSubmitBehavior="false" />
</td>
</tr>
</table>
<asp:SqlDataSource ID="sql_whs_code" runat="server" ConnectionString="<%$ ConnectionStrings:infologConnection %>"
SelectCommand="sp_select_auth_whs_code" SelectCommandType="StoredProcedure" OnSelecting="sql_whs_code_Selecting">
<SelectParameters>
<asp:Parameter Name="group_id" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
C# :
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.tbfromloc.Attributes.Add("onkeydown", "javascript:stfocus(event);");
this.tbfrompalletno.Attributes.Add("onkeydown", "javascript:tblocenter(event);");
ViewState["language"] = (string)Session["language"];
ViewState["group_id"] = (string)Session["group_id"];
this.loadsetting();
this.cbwhscode.DataBind();
if (this.cbwhscode.Items.Count > 0)
{
ListItem Check = this.cbwhscode.Items.FindByValue(Session["default_whs_code"].ToString());
if ((Check != null) && this.cbwhscode.Items.Contains(Check))
{
this.cbwhscode.SelectedValue = Session["default_whs_code"].ToString();
}
}
this.tbfromloc.Focus();
}
string parameter = Request["__EVENTARGUMENT"];
if (parameter = "save" ) this.btnsubmit_Click(sender, e);
}
protected void btnsubmit_Click(object sender, EventArgs e)
{
this.Label_ErrorMsg.Text = "";
this.Label_Info.Text = "";
string i_whs_code = this.cbwhscode.SelectedValue;
string i_pack_id = this.tbfrompalletno.Text;
string i_loc_code = this.tbfromloc.Text;
Tuple<bool, int, string> result = RF03BLL_Transfer.rf_partial_transfer_check_loc_pallet(i_whs_code, i_pack_id, i_loc_code);
bool o_succeed = result.Item1;
int o_msg_num = result.Item2;
string o_add_info = result.Item3;
if (o_succeed)
{
string strPost = "whscode=" + HttpUtility.UrlEncode(i_whs_code) +
"&palletno=" + HttpUtility.UrlEncode(i_pack_id) +
"&loccode=" + HttpUtility.UrlEncode(i_loc_code);
string path = "~/RF03F_Transfer/RF030202F_TransferPartialAddPacking.aspx?";
path += strPost;
Response.Redirect(path);
}
else
{
this.Label_ErrorMsg.Text = Module.getMsg(o_msg_num, ViewState["language"].ToString());
}
}
protected void sql_whs_code_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
e.Command.Parameters["#group_id"].Value = ViewState["group_id"].ToString();
}
My issue is: why value of DropDownList is missed?

Related

Change table row text and bgcolor on a listview value asp.net C

I have a listview and I am trying to change the text color and background color depending on the value of "callswaiting". This is written in C#.
I am trying to accomplish this:
If(Eval("availableAgents") < 1); Then
; If(Eval("callsWaiting" > 2) ,Then );
{
tblSheet.Style.Add("color", "black");
tblSheet.Style.Add("background-color", "red");
}
Else;
{
tblSheet.Style.Add("color", "black");
tblSheet.Style.Add("background-color", "orange");
}
End If;
Else;
{
tblSheet.Style.Add("color", "white");
tblSheet.Style.Add("background-color", "green");
}
End If;
Just stumped on how to update this to ASPX and C#.
My ASPX code is:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:ListView ID="ListView1" runat="server" DataSourceID="con_csq_agentDB" onitemdatabound="ListView1_ItemDataBound">
<AlternatingItemTemplate>
<tr id="MainTableRow" style="background-color: #ADADAD;">
<td style="background-color: gray; color: whitesmoke;">
<asp:Label ID="csqnameLabel" runat="server" Text='<%# Eval("csqname") %>' />
</td>
<td>
<asp:Label ID="callswaitingLabel" runat="server" Text='<%# Eval("callswaiting") %>' />
</td>
<td>
<asp:Label ID="convoldestcontactLabel" runat="server" Text='<%# Eval("convoldestcontact") %>' />
</td>
<td>
<asp:Label ID="loggedinagentsLabel" runat="server" Text='<%# Eval("loggedinagents") %>' />
</td>
<td>
<asp:Label ID="availableagentsLabel" runat="server" Text='<%# Eval("availableagents") %>' />
</td>
<td>
<asp:Label ID="talkingagentsLabel" runat="server" Text='<%# Eval("talkingagents") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<ItemTemplate>
<tr id="MainTableRow" style="background-color: #DCDCDC; color: #000000;">
<td style="background-color: gray; color: whitesmoke;">
<asp:Label ID="csqnameLabel" runat="server" Text='<%# Eval("csqname") %>' />
</td>
<td>
<asp:Label ID="callswaitingLabel" runat="server" Text='<%# Eval("callswaiting") %>' />
</td>
<td>
<asp:Label ID="convoldestcontactLabel" runat="server" Text='<%# Eval("convoldestcontact") %>' />
</td>
<td>
<asp:Label ID="loggedinagentsLabel" runat="server" Text='<%# Eval("loggedinagents") %>' />
</td>
<td>
<asp:Label ID="availableagentsLabel" runat="server" Text='<%# Eval("availableagents") %>' />
</td>
<td>
<asp:Label ID="talkingagentsLabel" runat="server" Text='<%# Eval("talkingagents") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table id="itemPlaceholderContainer" runat="server" data-height='100%'>
<tr runat="server" style="background-color: #113C77; color: #000000;">
<th runat="server"></th>
<th runat="server">Calls waiting</th>
<th runat="server">Current Wait</th>
<th runat="server">Agents Logged in</th>
<th runat="server">Ready</th>
<th runat="server">Talking</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
My C# code is:
public partial class csq_agent : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ListView1.DataSourceID = con_csq_agentDB.UniqueID;
}
}
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
ListViewDataItem dataitem = (ListViewDataItem)e.Item;
int callswaiting = (int)DataBinder.Eval(dataitem.DataItem, "callswaiting");
if (callswaiting == 3)
{
HtmlTableRow cell = (HtmlTableRow)e.Item.FindControl("MainTableRow");
cell.BgColor = "Red";
}
}
}

How i enable div from code behind in ontick event?

.aspx page
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick" >
</asp:Timer>
<br />
<br />
<table style="position: absolute; top: 600px; left: 167px; width: 1010px; height: 124px;">
<tr>
<td><asp:Label ID="Label13" runat="server"></asp:Label></td>
<td >DAYS</td>
<td><asp:Label ID="Label14" runat="server"></asp:Label></div></td>
<td > HOURS</td>
<td><asp:Label ID="Label15" runat="server"></asp:Label></td>
<td >MIN</td>
<td><asp:Label ID="Label16" runat="server"></asp:Label></td>
<td > SEC</td>
<td><asp:Label ID="Label17" Text="=Remaining For Vote Day" runat="server" ></asp:Label></td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div id="theDiv1" runat="server" style="height: 182px;display:none">
<table align="center" class="auto-style1" style="border-style: dashed; border-color: #008000; height: 179px; width: 366px; margin-left: 300px;">
<tr>
<td class="auto-style2"> </td>
<td>
<asp:Label ID="Label1" runat="server" Font-Bold="true" Font-Size="X-Large" Text="Voter login"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label ID="Label2" runat="server" Text="Name"> </asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server" Width="177px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label ID="Label3" runat="server" Text="Password"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" TextMode="Password" Width="179px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Log in" Width="65px" />
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">New User</asp:LinkButton>
</td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td>
<asp:LinkButton ID="LinkButton2" runat="server" OnClick="LinkButton2_Click">Forgot Password</asp:LinkButton>
</td>
</tr>
</table>
<asp:Label ID="label4" runat="server"></asp:Label>
</div>
</Content>
.aspx.cs page
protected void Timer1_Tick(object sender, EventArgs e)
{
DateTime dt = DateTime.Now;
TimeSpan differ;
System.DateTime date1 = new System.DateTime(2015, 4, 1, 20, 10, 0);
differ = date1.Subtract(dt);
double t = differ.TotalSeconds;
if (t > 0)
{
double dy, h, m, s;
dy = differ.Days;
h = differ.Hours;
m = differ.Minutes;
s = differ.Seconds;
Label13.Text = dy.ToString();// +" Days " + h + " Hours " + m + " Minutes " + s + " Seconds left for celebration";
Label14.Text = h.ToString();
Label15.Text = m.ToString();
Label16.Text = s.ToString();
}
else
{
Timer1.Enabled = false;
time_enable.Visible = false;
theDiv1.Visible = true;
}
}
After writing theDiv1.Visible = true; this statement theDiv1 is not visible and don't work.
How can I solve it?
You have set display=none in style property and making Visible=true on server side which doesn't make sense!! so you need to do it as below
theDiv1.Style.Remove("display");//To be on safer side do this first
theDiv1.Style.Add("display","block");
or
theDiv1.Style.Add(HtmlTextWriterStyle.Display, "block");
Alternative
If you make change to your div as below
<div id="theDiv1" Visible="false" runat="server" style="height: 182px;">
then whatever code you have written will work for sure.

Telerik RadGrid - Not giving new value in the UpdateCommand event handler

The problem i am facing is in this line.
decimal amount = Convert.ToDecimal(Amt.Text);
Amt.Text is not giving me the new entered value when i change it and try to save it. But it is giving me the old value. I don't know why ? Please suggest the fix.
I have a search button also in the webpage which is needed to rebind the Grid with the latest data. I think when i click the save link and gvLineItems_UpdateCommand is called , the rebinding is happening before that on the RADGRID (internally).
ASPX Code:-
<asp:content id="Content2" contentplaceholderid="MainContent" runat="server">
<script language="javascript">
function captureVal(sender, args){
alert('hi');
}
</script>
<table>
<tr>
<td>
<asp:Label ID="lblPartnerID" runat="server" Text="PartnerID" Font-Bold="true"></asp:Label>
</td>
<td>
<telerik:RadTextBox ID="tbPartnerID" runat="server" MaxLength="35" Width="243px" />
</td>
<td>
<asp:Button ID="btnSearch" runat="server" Width="80px" Visible="true" Text="Search" />
</td>
</tr>
<tr>
<td style="text-align:right">
<asp:Button ID="btnSave" runat="server" Visible="true" Text="Save" />
</td>
<td style="text-align:left">
<asp:Button ID="btnCancel" runat="server" Visible="true" Text="Cancel" />
</td>
</tr>
<tr>
<td>
Partner SSN/TIN:
</td>
<td>
<telerik:RadTextBox ID="tbPartnerEIN" runat="server" MaxLength="9" TabIndex="5">
</telerik:RadTextBox>
<label id="Label1" runat="Server" style="color: Navy">* No Dashes</label>
</td>
<td style="width:10px"></td>
<td style="text-align:left">
Address Line 1:
</td>
<td>
<telerik:RadTextBox ID="tbAddressLine1" runat="server" TabIndex="10" />
<label id="label2" runat="server" style="color: navy">
* No dashes</label>
</td>
</tr>
<tr>
<td>
Custodial EIN:
</td>
<td>
<telerik:RadTextBox ID="tbCustodialEIN" runat="server" MaxLength="9" TabIndex="10">
</telerik:RadTextBox>
<label id="Label3" runat="Server" style="color: Navy">* No Dashes</label>
</td>
<td style="width:10px"></td>
<td style="text-align:left">
Address Line 2:
</td>
<td>
<telerik:RadTextBox ID="tbAddressLine2" runat="server" TabIndex="10" />
<label id="Label4" runat="Server" style="color: Navy">
* No Dashes</label>
</td>
</tr>
<tr>
<td>
Format SSN/TIN:
</td>
<td>
<telerik:RadComboBox ID="cboFormatSSNTIN" Height="200px" runat="server" Width="246px"
TabIndex="41">
<Items>
<telerik:RadComboBoxItem Text="" Value="" />
<telerik:RadComboBoxItem Text="XXX-XX-XXXX" Value="0" />
<telerik:RadComboBoxItem Text="XX-XXXXXXX" Value="1" />
</Items>
</telerik:RadComboBox>
</td>
<td style="width:10px"></td>
<td style="text-align:left">
City:
</td>
<td>
<telerik:RadTextBox ID="tbCity" runat="server" MaxLength="22" Width="243px" TabIndex="45" />
</td>
</tr>
<tr>
<td>
Partner Name 1:
</td>
<td>
<telerik:RadTextBox ID="tbPartnerName1" runat="server" MaxLength="35" Width="243px"
TabIndex="15" />
</td>
<td style="width:10px"></td>
<td style="text-align:left">
State:
</td>
<td>
<telerik:RadComboBox ID="ddlState" runat="server" AllowCustomText="true" Filter="Contains"
Width="243px" TabIndex="35" Height="100" />
</td>
</tr>
<tr>
<td>
Partner Name 2:
</td>
<td>
<telerik:RadTextBox ID="tbPartnerName2" runat="server" MaxLength="35" Width="243px"
TabIndex="20" />
</td>
<td style="width:10px"></td>
<td style="text-align:left">
Zip:
</td>
<td>
<telerik:RadTextBox ID="tbZipcode" runat="server" MaxLength="12" Width="243px" TabIndex="55" />
</td>
</tr>
<tr>
<td>
Entity Type:
</td>
<td>
<telerik:RadComboBox ID="lbEntityType" Height="150px" runat="server" Width="246px"
TabIndex="40" />
<asp:RequiredFieldValidator ID="Requiredfieldvalidator1" runat="server" ErrorMessage="Select any one Entity type"
ControlToValidate="lbEntityType" InitialValue="0" Display="None">*</asp:RequiredFieldValidator>
</td>
<td style="width:10px"></td>
<td style="text-align:left">
Foreign Address:
</td>
<td>
<telerik:RadTextBox ID="tbForeignAddress" runat="server" Width="243px" TabIndex="35" />
</td>
</tr>
<tr>
<td colspan="2">
</td>
<td style="width:10px"></td>
<td style="text-align:left">
Domestic or Foreign:
</td>
<td>
<telerik:RadComboBox ID="lbCountry" runat="server" Width="246px" TabIndex="35" />
</td>
</tr>
<tr>
<td>
<asp:RadioButtonList ID="rbFinalAmend" runat="server" RepeatDirection="Horizontal">
<asp:ListItem>Final K-1</asp:ListItem>
<asp:ListItem>Amended K-1</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td colspan="2">
<asp:RadioButtonList ID="rbGenLtd" runat="server" RepeatDirection="Horizontal">
<asp:ListItem>General partner or LLC member-manager</asp:ListItem>
<asp:ListItem>Limited partner or other LLC member</asp:ListItem>
</asp:RadioButtonList>
</td>
<td style="width:10px"></td>
<td>
Nonrecourse
</td>
<td>
$<telerik:RadNumericTextBox ID="txtNonrecourse" DataType="System.Double" NumberFormat-DecimalDigits="2"
Width="200px" runat="server" />
</td>
</tr>
<tr>
<td colspan="2">
<br />
<asp:CheckBox ID="cbTax" Text="Tax basis" runat="server" />
<asp:CheckBox ID="cbGaap" Text="GAAP" runat="server" />
<asp:CheckBox ID="cbSection" Text="Section 704(b) book" runat="server" />
</td>
<td style="width:10px"></td>
<td>
Qualified nonrecourse financing
</td>
<td>
$<telerik:RadNumericTextBox ID="txtQualified" DataType="System.Double" NumberFormat-DecimalDigits="2"
Width="200px" runat="server" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:CheckBox ID="cbOther" Text="Other(explain)" runat="server" />
</td>
<td style="width:10px"></td>
<td>
Recourse
</td>
<td>
$<telerik:RadNumericTextBox ID="txtRecourse" DataType="System.Double" NumberFormat-DecimalDigits="2"
Width="200px" runat="server" />
</td>
</tr>
</table>
<table>
<tr>
<td colspan="3">
<br />
<span style="font-weight: bold; font-size: 10pt">(M) Did the partner contribute property
with a built-in gain or loss?</span>
<br />
<hr size="1" />
</td>
</tr>
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<asp:RadioButtonList ID="rbContributedProperty" runat="server" RepeatDirection="Horizontal">
<asp:ListItem>Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
</asp:RadioButtonList>
<br />
</td>
</tr>
</table>
</td>
</tr>
</table>
<table>
<tr>
<td>
<table>
<tr>
<td>
<table>
<thead colspan="2">
<span style="font-weight: bold; font-size: 10pt">(L) Partner's capital account analysis</span>
</thead>
<hr size="1" />
<br />
<br />
<tr>
<td>
Beginning capital account
</td>
<td>
$<telerik:RadNumericTextBox ID="txtCapBeginning" DataType="System.Double" NumberFormat-DecimalDigits="2"
Width="200px" runat="server">
</telerik:RadNumericTextBox>
</td>
</tr>
<tr>
<td>
Capital contributed during the year
</td>
<td>
$<telerik:RadNumericTextBox ID="txtCapContributed" DataType="System.Double" NumberFormat-DecimalDigits="2"
Width="200px" runat="server">
</telerik:RadNumericTextBox>
</td>
</tr>
<tr>
<td>
Current year increase(decrease)
</td>
<td>
$<telerik:RadNumericTextBox ID="txtIncrease" DataType="System.Double" NumberFormat-DecimalDigits="2"
Width="200px" runat="server">
</telerik:RadNumericTextBox>
</td>
</tr>
<tr>
<td>
Withdrawals & distributions <span style="color: Red">(-)</span>
</td>
<td>
$<telerik:RadNumericTextBox ID="txtWithdrawals" DataType="System.Double" NumberFormat-DecimalDigits="2"
Width="200px" ForeColor="Red" runat="server">
</telerik:RadNumericTextBox>
</td>
</tr>
<tr>
<td>
Ending capital account
</td>
<td>
$<telerik:RadNumericTextBox ID="txtCapEnding" DataType="System.Double" NumberFormat-DecimalDigits="2"
Width="200px" runat="server" ReadOnly="true" />
</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>
</td>
<td align="center">
<b> Beginning</b>
</td>
<td align="center">
<b>Ending</b>
</td>
</tr>
<tr>
<td>
Profit
</td>
<td>
<telerik:RadNumericTextBox ID="txtBeginningProfit" DataType="System.Double"
NumberFormat-DecimalDigits="6" Width="200px" runat="server" />%
</td>
<td>
<telerik:RadNumericTextBox ID="txtEndProfit" DataType="System.Double" NumberFormat-DecimalDigits="6"
Width="200px" runat="server" />%
</td>
</tr>
<tr>
<td>
Loss
</td>
<td>
<telerik:RadNumericTextBox ID="txtBeginningLoss" DataType="System.Double"
NumberFormat-DecimalDigits="6" Width="200px" runat="server" />%
</td>
<td>
<telerik:RadNumericTextBox ID="txtEndLoss" DataType="System.Double" NumberFormat-DecimalDigits="6"
Width="200px" runat="server" />%
</td>
</tr>
<tr>
<td>
Capital
</td>
<td>
<telerik:RadNumericTextBox ID="txtBeginningCap" DataType="System.Double"
NumberFormat-DecimalDigits="6" Width="200px" runat="server" />%
</td>
<td>
<telerik:RadNumericTextBox ID="txtEndCap" DataType="System.Double" NumberFormat-DecimalDigits="6"
Width="200px" runat="server" />%
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<telerik:RadGrid runat="server" ID="gvLineItems" AllowMultiRowSelection="true" AllowMultiRowEdit="False"
AllowAutomaticUpdates="false" AllowAutomaticInserts="false" Width="100%" AllowAutomaticDeletes="False" GridLines="None" Pagesize="10"
AllowPaging="True" AutoGenerateColumns="False" PagerStyle-Mode="NextPrevAndNumeric" OnNeedDataSource="gvLineItems_NeedDataSource">
<MasterTableView InsertItemDisplay="Bottom" AutoGenerateColumns="false" AllowAutomaticUpdates="false" EditMode="InPlace"
DataKeyNames="SchK1ID,LineNumber,LineCode,Amount"
AllowAutomaticDeletes="false" Width="100%" AllowAutomaticInserts="false" CommandItemDisplay="None">
<HeaderStyle HorizontalAlign="Left" Wrap="false" />
<ItemStyle HorizontalAlign="Left"/>
<Columns>
<telerik:GridBoundColumn HeaderText="Line Number" DataField="LineNumber" SortExpression="LineNumber" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Top" ReadOnly="true" />
<telerik:GridBoundColumn HeaderText="Line Code" DataField="LineCode" SortExpression="LineCode" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Top" ReadOnly="true" />
<telerik:GridBoundColumn HeaderText="Description" DataField="LineDescription" SortExpression="LineDescription" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Top" ReadOnly="true" />
<telerik:GridTemplateColumn DataType="System.Decimal" HeaderText="Amount" DataField="Amount" SortExpression="Amount" UniqueName="Amount" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Right" ItemStyle-VerticalAlign="Top">
<ItemTemplate><%#Eval("Amount", "{0:c}")%></ItemTemplate>
<EditItemTemplate>
<telerik:RadNumericTextBox runat="server" id="tbAmount" width="75px" EmptyMessage="0" DataType="System.Decimal" Text='<%#Eval("Amount")%>' NumberFormat-DecimalDigits="3">
</telerik:RadNumericTextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridEditCommandColumn UniqueName="Save" ButtonType="LinkButton" EditText="Edit" InsertText="Insert" UpdateText="Save"/>
</Columns>
</MasterTableView>
<ClientSettings>
<Selecting AllowRowSelect="True"/>
</ClientSettings>
</telerik:RadGrid>
</td>
</tr>
</table>
C# Code Behind:
public partial class EFileK1ImageEdit : System.Web.UI.Page
{
private string m_EFSTaxPayerID;
public int PartnerId {
get {
if (!string.Empty.Equals(tbPartnerID.Text.Trim())) {
return Convert.ToInt32(tbPartnerID.Text.Trim());
}
return 0;
}
}
protected void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack) {
this.LoadPartner();
this.PopulateCapitalAccount();
}
}
public void LoadPartner()
{
if (!(PartnerId == 0)) {
Partner p = Partner.GetEfilePartnerByID(PartnerId, ProfileExtensions.GetCurrentYear(), ProfileExtensions.GetCurrentClient(), ProfileExtensions.GetCurrentUsername());
if ((p != null)) {
PopulateInfo(p, ProfileExtensions.GetCurrentYear());
}
}
}
public void PopulateDropDowns()
{
this.lbEntityType.DataSource = IDMS.BusinessObjects.EntityCode.GetEntityType(ProfileExtensions.GetCurrentClient(), ProfileExtensions.GetCurrentUsername());
this.lbEntityType.DataTextField = "Explanation";
this.lbEntityType.DataValueField = "EntityCodeID";
this.lbEntityType.DataBind();
this.ddlState.DataSource = IDMS.BusinessObjects.SystemSettings.GetStateCodes(ProfileExtensions.GetCurrentClient(), ProfileExtensions.GetCurrentUsername());
this.ddlState.DataTextField = "StateCode";
this.ddlState.DataValueField = "StateCode";
this.ddlState.DataBind();
this.ddlState.Items.FindItemByText(". ").Text = "FR";
this.lbCountry.DataSource = IDMS.BusinessObjects.MailCode.GetAllMailCodes(ProfileExtensions.GetCurrentClient(), ProfileExtensions.GetCurrentUsername());
this.lbCountry.DataTextField = "Explanation";
this.lbCountry.DataValueField = "MailCodeID";
this.lbCountry.DataBind();
}
private void SetStateControl(string value)
{
RadComboBoxItem item = this.ddlState.FindItemByValue(value);
if (item == null) {
this.ddlState.Text = value;
} else {
item.Selected = true;
}
if (value.Trim() == ".") {
this.ddlState.Text = "";
}
}
protected void PopulateInfo(Partner p, int taxYear)
{
PopulateDropDowns();
this.tbPartnerID.Text = this.PartnerId.ToString();
}
private void PopulateCapitalAccount()
{
IDMS.BusinessObjects.CapitalAccount ca = IDMS.BusinessObjects.CapitalAccount.GetEFileCapitalAccount(this.PartnerId, ProfileExtensions.GetCurrentYear(), ProfileExtensions.GetCurrentClient(), ProfileExtensions.GetCurrentUsername());
// SetManualAdjustmentMessage(ca)
if (ca != null) {
var _with1 = ca;
this.rbFinalAmend.Items[0].Selected = _with1.FinalK1;
this.rbFinalAmend.Items[1].Selected = _with1.AmendedK1;
this.rbGenLtd.Items[0].Selected = _with1.GeneralPartner;
this.rbGenLtd.Items[1].Selected = _with1.LimitedPartner;
this.txtBeginningCap.Value = _with1.BeginningCapitalPercent * 100;
this.txtBeginningLoss.Value = _with1.BeginningLossPercent * 100;
this.txtBeginningProfit.Value = _with1.BeginningProfitPercent * 100;
this.txtEndCap.Value = _with1.EndingCapitalPercent * 100;
this.txtEndLoss.Value = _with1.EndingLossPercent * 100;
this.txtEndProfit.Value = _with1.EndingProfitPercent * 100;
this.txtNonrecourse.Value = _with1.LiabilityShareNonRecourse;
this.txtQualified.Value = _with1.LiabilitySharedQualifiedNonRecourse;
this.txtRecourse.Value = _with1.LiabilitySharedRecourse;
} else {
this.rbContributedProperty.Items[0].Selected = false;
this.rbContributedProperty.Items[1].Selected = false;
}
}
protected void gvLineItems_UpdateCommand(object sender, GridCommandEventArgs eventData)
{
//Validate Parameters
if (eventData.Item is GridEditableItem && eventData.Item.IsInEditMode) {
DataTable dt = IDMS.BusinessObjects.EfileMapping.GetEFileLineItemsByPartner(ProfileExtensions.GetCurrentClient(), ProfileExtensions.GetCurrentUsername(), ProfileExtensions.GetCurrentYear(), PartnerId);
//Declare Variables
GridEditableItem editableItem = eventData.Item as GridEditableItem;
int LineNumber = Convert.ToInt32(editableItem.GetDataKeyValue("LineNumber"));
string LineCode = Convert.ToString(editableItem.GetDataKeyValue("LineCode"));
decimal oldAmount = Convert.ToDecimal(dt.Select(string.Format("LineNumber={0} and LineCode='{1}'", LineNumber, LineCode))[0]["Amount"]);
RadNumericTextBox Amt = editableItem.FindControl("tbAmount") as RadNumericTextBox;
decimal amount = Convert.ToDecimal(Amt.Text);
decimal diff = amount - oldAmount;
txtIncrease.Text = (Convert.ToDecimal(txtIncrease.Text) + diff).ToString();
txtCapEnding.Text = (Convert.ToDecimal(txtCapEnding.Text) + diff).ToString();
saveCapitalAccount();
IDMS.BusinessObjects.EfileMapping.UpdateEFileLineItemsByPartner(ProfileExtensions.GetCurrentClient(), ProfileExtensions.GetCurrentUsername(), ProfileExtensions.GetCurrentYear(), PartnerId, amount, LineNumber, LineCode);
}
}
protected void gvLineItems_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
gvLineItems.DataSource = IDMS.BusinessObjects.EfileMapping.GetEFileLineItemsByPartner(ProfileExtensions.GetCurrentClient(), ProfileExtensions.GetCurrentUsername(), ProfileExtensions.GetCurrentYear(), PartnerId);
}
protected void btnSearch_Click(object sender, EventArgs e)
{
this.LoadPartner();
this.PopulateCapitalAccount();
gvLineItems.Rebind();
}
private void btnSave_Click(object sender, System.EventArgs e)
{
IDMS.BusinessObjects.Partner p = new IDMS.BusinessObjects.Partner();
var _with2 = p;
_with2.PartnerID = int.Parse(tbPartnerID.Text);
_with2.EFSNameLine1 = tbPartnerName1.Text;
UpdateEFileDetailPartnerGridByYear(ProfileExtensions.GetCurrentClient(), ProfileExtensions.GetCurrentYear(), this.PartnerId);
}
public void saveCapitalAccount()
{
IDMS.BusinessObjects.CapitalAccount ca = new IDMS.BusinessObjects.CapitalAccount();
var _with3 = ca;
_with3.PartnerID = this.PartnerId;
_with3.CalendarYear = ProfileExtensions.GetCurrentYear();
_with3.FinalK1 = this.rbFinalAmend.Items[0].Selected;
_with3.AmendedK1 = this.rbFinalAmend.Items[1].Selected;
_with3.GeneralPartner = this.rbGenLtd.Items[0].Selected;
_with3.LimitedPartner = this.rbGenLtd.Items[1].Selected;
_with3.BeginningCapitalPercent = this.txtBeginningCap.Value.GetValueOrDefault(0) / 100;
_with3.BeginningLossPercent = this.txtBeginningLoss.Value.GetValueOrDefault(0) / 100;
_with3.BeginningProfitPercent = this.txtBeginningProfit.Value.GetValueOrDefault(0) / 100;
_with3.EndingCapitalPercent = this.txtEndCap.Value.GetValueOrDefault(0) / 100;
_with3.EndingLossPercent = this.txtEndLoss.Value.GetValueOrDefault(0) / 100;
_with3.EndingProfitPercent = this.txtEndProfit.Value.GetValueOrDefault(0) / 100;
_with3.LiabilityShareNonRecourse = this.txtNonrecourse.Value.GetValueOrDefault(0);
_with3.LiabilitySharedQualifiedNonRecourse = this.txtQualified.Value.GetValueOrDefault(0);
_with3.LiabilitySharedRecourse = this.txtRecourse.Value.GetValueOrDefault(0);
_with3.AccountAnalysisBeginningCapital = this.txtCapBeginning.Value.GetValueOrDefault(0);
_with3.AccountAnalysisContributions = this.txtCapContributed.Value.GetValueOrDefault(0);
_with3.AccountAnalysisIncreaseDecrease = this.txtIncrease.Value.GetValueOrDefault(0);
_with3.AccountAnalysisWithdrawalsDistributions = this.txtWithdrawals.Value.GetValueOrDefault(0);
_with3.AccountAnalysisEndingCapital = _with3.AccountAnalysisBeginningCapital + _with3.AccountAnalysisContributions + _with3.AccountAnalysisIncreaseDecrease - _with3.AccountAnalysisWithdrawalsDistributions;
_with3.AccountAnalysisGAAP = this.cbGaap.Checked;
_with3.AccountAnalysisOther = this.cbOther.Checked;
_with3.AccountAnalysisSection704b = this.cbSection.Checked;
_with3.AccountAnalysisTaxBasis = this.cbTax.Checked;
_with3.ContributePropertyYes = this.rbContributedProperty.Items[0].Selected;
_with3.ContributePropertyNo = this.rbContributedProperty.Items[1].Selected;
_with3.SaveEfile(ProfileExtensions.GetCurrentClient(), ProfileExtensions.GetCurrentUsername());
}
public EFileK1ImageEdit()
{
Load += Page_Load;
Init +=EFileK1ImageEdit_Init;
}
private void EFileK1ImageEdit_Init(object sender, EventArgs e)
{
btnSave.Click+=btnSave_Click;
btnCancel.Click +=btnCancel_Click;
btnSearch.Click+=btnSearch_Click;
gvLineItems.NeedDataSource +=gvLineItems_NeedDataSource;
gvLineItems.UpdateCommand +=gvLineItems_UpdateCommand;
}
}

RadioButtonList alignment issue

I have a below code based on the value from backend i have to display the radiobuttonlist listitem value and controls in aspx page.
when the rbl1.SelectedValue = "0" the alignmnet of the controls are fine.
when the rbl1.SelectedValue = "1" the RadioButtonList is coming to center like below, and i want this rbl to align left side only.
can any body help me in this.
C#:
public string HiddenClassName { get; private set; }
if (!string.IsNullOrEmpty(value) && value.ToLower() == "y")
{
rbl1.SelectedValue = "0"; //Yes
lblName.Visible = true;
txtName.Visible = true;
HiddenClassName = "display:block";
}
else
{
rbl1.SelectedValue = "1"; //No
lblName.Visible = false;
txtName.Visible = false;
HiddenClassName = "display:none";
}
ASPX:
<h2>
Information</h2>
<table width="100%">
<tr>
<td>
<asp:Label ID="lbl1" runat="server" Width="180px" Text="Would like to use?"></asp:Label>
</td>
<td >
<asp:RadioButtonList ID="rbl1" runat="server" TextAlign="Right" RepeatDirection="Horizontal">
<asp:ListItem Value="Yes" Text="Yes" Selected="True" />
<asp:ListItem Value="No" Text="No" />
</asp:RadioButtonList>
</td>
<td style="padding-bottom: 17px">
<%=this.ShowHelp("rbl_Help")%>
</td>
<%-- <asp:Panel ID="pnlAgntName" runat="server"> --%>
<td align="right">
<asp:Label ID="lblName" Text="Name" runat="server"></asp:Label>
</td>
<td align="left">
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
</td>
<td style="<%= HiddenClassName %>;padding-bottom: 17px">
<%=this.ShowHelp("Name_Help")%>
</td>
<%--</asp:Panel>--%>
</tr>
</table>
<div class="hr">
</div>
</fieldset>
Add width in each td like style="width: 25px"

Listview Cannot select last row

i have an asp.net ListView and i want when i click the select linkbutton to select the row and pass the id of the data to a detailsview. It passes the id for all records except the last one. Any reasons why?
<asp:ListView ID="ListView1" runat="server" DataKeyNames="AnswerID" OnSelectedIndexChanging="ListView1_SelectedIndexChanging">
<EmptyDataTemplate>
<table runat="server" style="">
<tr>
<td>
No data was returned.
</td>
</tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<tr style="">
<td>
<asp:LinkButton ID="SelectButton" runat="server" CommandName="Select" Text="Select" />
</td>
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("AnswerID") %>'></asp:Label>
</td>
<td>
<asp:Label ID="Question" runat="server" Text='<%# Eval("QuestionText") %>' />
</td>
<td>
<asp:Label ID="UserAnswer" runat="server" Text='<%# Eval("UserAnswerTxt") %>' />
</td>
<td>
<asp:Label ID="CorrectAns" runat="server" Text='<%# Eval("CorrectAnswerTxt") %>' />
</td>
<td>
<asp:Image ID="Image1" ImageUrl='<%# Eval("ImagePath") %>' Width="48" Height="48"
runat="server" />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server">
</th>
<th runat="server">
AnswerID
</th>
<th runat="server">
QuestionText
</th>
<th runat="server">
UserAnswerTxt
</th>
<th runat="server">
CorrectAnswerTxt
</th>
<th runat="server">
</th>
<th runat="server">
</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="">
</td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="">
<td>
<asp:LinkButton ID="SelectButton" runat="server" CommandName="Select" Text="Select" />
</td>
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("AnswerID") %>'></asp:Label>
</td>
<td>
<asp:Label ID="Question" runat="server" Text='<%# Eval("QuestionText") %>' />
</td>
<td>
<asp:Label ID="UserAnswer" runat="server" Text='<%# Eval("UserAnswerTxt") %>' />
</td>
<td>
<asp:Label ID="CorrectAns" runat="server" Text='<%# Eval("CorrectAnswerTxt") %>' />
</td>
<td>
<asp:Image ID="Image1" ImageUrl='<%# Eval("ImagePath") %>' Width="48" Height="48"
runat="server" />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" AutoGenerateRows="False"
DataSourceID="SqlDataSource1">
<Fields>
<asp:BoundField DataField="AnswerID" HeaderText="AnswerID" SortExpression="AnswerID" />
<asp:BoundField DataField="AnswerExplanation" HeaderText="AnswerExplanation" SortExpression="AnswerExplanation" />
<asp:BoundField DataField="SuggestionText" HeaderText="SuggestionText" SortExpression="SuggestionText" />
<asp:BoundField DataField="LessonID" HeaderText="LessonID" SortExpression="LessonID" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [ErDiagID], [AnswerID], [LessonID], [AnswerExplanation], [SuggestionText] FROM [ErrorDiagnosis] WHERE ([AnswerID] = #AnswerID)">
<SelectParameters>
<asp:ControlParameter ControlID="ListView1" Name="AnswerID" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
protected void Page_Load(object sender, EventArgs e)
{
Panel p = (Panel)Master.FindControl("Panel1");
if (p != null)
{
p.Visible = false;
}
ArrayList al = (ArrayList)Session["AnswerList"];
if (!Page.IsPostBack)
{
ListView1.DataBind();
}
if (al == null)
{
Response.Redirect("~/Default.aspx");
}
SqlConnection connection = null;
try
{
ListView1.DataSource = al;
//ListView1.SelectedIndex = ListView1.Items.Count - 1;
ListView1.DataBind();
//ListView1.SelectedIndex = ListView1.Items.Count - 1;
ListView1.SelectedIndex = -1;
if (IsPostBack == false)
{
double questions = al.Count;
double correct = 0.0;
for (int i = 0; i < al.Count; i++)
{
Answer a = (Answer)al[i];
if (a.Result == Answer.ResultValue.Correct)
{
correct++;
}
}
//foreach (ListViewItem item in resultGrid.Items)
//{
// Label cor = (Label)item.FindControl("CorrectAns");
// Label useran = (Label)item.FindControl("UserAnswer");
// if (cor.Text != useran.Text)
// {
// useran.Font.Bold = true;
// }
//}
double score = (correct / questions) * 100;
Scorelbl.Text = string.Format("{0:0.##}", score) + "%";
if (score >= 80 && score < 100)
{
resultext.Text = "Μπράβο " + Profile.UserName + "!!!";
}
connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
connection.Open();
SqlDataSource userQuizDataSource = new SqlDataSource();
userQuizDataSource.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
userQuizDataSource.InsertCommand = "INSERT INTO [UserQuiz] ([QuizID], [DateTimeComplete], [Score], [UserName]) VALUES (#QuizID, GETDATE(), #Score, #UserName)";
userQuizDataSource.InsertParameters.Add("QuizID", Session["QuizID"].ToString());
userQuizDataSource.InsertParameters.Add("Score", score.ToString());
userQuizDataSource.InsertParameters.Add("UserName", User.Identity.Name);
int rowsAffected = userQuizDataSource.Insert();
connection.Close();
if (rowsAffected == 0)
{
errorLabel.Text = "";
}
}
}
catch (Exception exp)
{
//throw new Exception(exp.ToString(), exp);
Response.Redirect("~/Default.aspx");
}
}
protected void ListView1_SelectedIndexChanging(object sender, ListViewSelectEventArgs e)
{
ListView1.SelectedIndex = e.NewSelectedIndex;
string id = ListView1.SelectedDataKey.Value.ToString();
SqlDataSource1.SelectParameters["AnswerID"].DefaultValue = id;
ListView1.DataBind();
}
Try this to get the selected Rows value
ListView1.SelectedIndex = e.NewSelectedIndex;
string id=ListView1.SelectedDataKey.Value.ToString();
//Then pass the id's value
ListView1.DataBind();
Hope it helps.

Categories