I'm facing problem regarding the grid-view template. It shows sum of individual as well as shows grand total. How can it be tackle ?
I'm trying to design my grid same as shown in picture using C#.net.
Format for my grid-view:
You can do this easily with Asp.net Repeater control.Footer template will help you to hold summation
<FooterTemplate>
<tr style="border-top: 1px solid Grey;">
<td colspan="2">
<strong>Total</strong>
</td>
<td>
<strong></strong><asp:Label ID="CartTotal" runat="server" Text='0' /></strong>
</td>
</tr>
</table>
</FooterTemplate>
in c# you will bind data like below
CartListRepeater.DataSource = Yourdatasource;
CartListRepeater.DataBind();
Then add data to Footer after binding data.
Control FooterTemplate =CartListRepeater.Controls[CartListRepeater.Controls.Count - 1].Controls[0];
Label lblFooter = FooterTemplate.FindControl("CartTotal") as Label;
lblFooter.Text = "0"//This is your total value;
Hope this will help you out.
Related
Below is my aspx code for text box and calendar control and text box which displays an error message if the selected from date and to date is not in the range,the problem is i am getting error message but on again changing the date by using date picker i am unable to clear the label message not a valid document
<tr>
<td style="width:100px; text-align:left; padding-left:10px;">From Date:</td>
<td style="width:200px; text-align:left;"><asp:TextBox ID="txtfromdate" runat="server" Width="120px" CssClass="Calender"></asp:TextBox></td>
<td style="width:100px; text-align:left; padding-left:10px;">To Date:</td>
<td style="width:200px; text-align:left;"><asp:TextBox ID="txtToDate" runat="server" Width="120px" CssClass="Calender"></asp:TextBox> </td>
<td style="width:250px;"></td>
</tr>
All right according to comments what you need is to reload the page when the calendar values change. For this you do this:
<asp:TextBox ID="txtfromdate" runat="server" Width="120px" CssClass="Calender" ontextchanged="ClndrFrom_TextChanged">
And in your code behind:
private void ClndrFrom_TextChanged(object sender, EventArgs e)
{
//Here you clear your label. Or if you already stored the file in server
//you can validate your file and change the label
}
You also need to do the same thing for the other calendar text box.
For the record I recommend using client side code in Javascript for such operations but, hope it helps :)
I'm creating an MCQ Question and answer Interface where I need to place my each radio option in separete row next to the answer, so that user can select the answer, I know to use radiobutton list in a single row in normal way,
<asp:RadioButtonList ID="opt_questiontype" runat="server" RepeatLayout="Flow" OnClick="call()">
<asp:ListItem Value="MCQ" Selected="True">MCQ</asp:ListItem>
<asp:ListItem Value="Single">Single Answer</asp:ListItem>
</asp:RadioButtonList>
but here i need to place them in row by row in an html table as follows,
<table id="mcqtable">
<tr style="border-bottom-style:solid; border-bottom-width:1px; border-bottom-color:#CCCCCC;">
<th class="captions2">Option</th><th class="captions2">Answer Text</th><th class="captions2">Is Correct</th>
</tr>
<tr>
<td class="captions1">Answer Option 1</td><td><asp:TextBox ID="txt_answeropt1" runat="server" TextMode="SingleLine" Width="600px"></asp:TextBox></td><td><asp:RadioButton ID="opt_answer1" runat="server" GroupName="grp_answers" Checked="true" /></td>
</tr>
<tr>
<td class="captions1">Answer Option 2</td><td><asp:TextBox ID="txt_answeropt2" runat="server" TextMode="SingleLine" Width="600px"></asp:TextBox></td><td><asp:RadioButton ID="opt_answer2" runat="server" GroupName="grp_answers" /></td>
</tr>
<tr>
<td class="captions1">Answer Option 3</td><td><asp:TextBox ID="txt_answeropt3" runat="server" TextMode="SingleLine" Width="600px"></asp:TextBox></td><td><asp:RadioButton ID="opt_answer3" runat="server" GroupName="grp_answers" /></td>
</tr>
<tr>
<td class="captions1">Answer Option 4</td><td><asp:TextBox ID="txt_answeropt4" runat="server" TextMode="SingleLine" Width="600px"></asp:TextBox></td><td><asp:RadioButton ID="opt_answer4" runat="server" GroupName="grp_answers" /></td>
</tr>
</table>
Here I have used normal radiobuttons, but there is a conflict when getting the selected value, So please any one could suggest a way to use asp:RadioButtonList to do this task?
here I have used normal radiobuttons, but there is a conflict when
getting the selected value
What is conflict? why you want to use RAdioButtonList here? Your existing code does not show me any conflict.
Either use repeater or you can use css to create single row for each radio button.
In repeater you can control the HTML as per your requirement
You should set RepeatDirection="Vertical" in order to show the options row-wise.
Please refer my answer #CodeProject - Change ASP radiobuttonlist repeatdirection property with Javascript or JQuery for a more detailed information on how we can toggle between Vertical and Horizontal alignments.
Demo - [Demo] Change Repeat Direction of asp RadioButtonList
EDIT
Do like below...
<asp:RadioButtonList ID="opt_questiontype" runat="server" RepeatLayout="Flow" RepeatDirection="Vertical" OnClick="call()">
I have a repeater with a table in it with lots of properties of the td's bound by the repeater.
I have had to add a runat server to each td so I can add a visible attribute, because depending on the data some tds aren't visible.
Now I have added the runat server I am having a problem setting the background colour of my tds. It is done with a bound value.
When I add my <%%> tags to my style they are output as plain text, It even says in my html that "This is not a scriptlet. Will output as plain text" where as the rest of my <%%> tags bind correctly.
Why won't my style bind anymore?
Other tags I add will, but just not style?
Here's a cut down version of my repeater.
<table id="Table1" border="1" cellpadding="0" cellspacing="0" class="groups">
<tr id="Tr1" class="thead">
<td colspan='<%#AllowedItems.Count() %>' align="center">
items
</td>
</tr>
<tr class="theadL">
<td id="Td1" runat="server" visible='<%#ItemAllowed("Item1")%>'>
item1
</td>
<td id="Td2" runat="server" visible='<%#ItemAllowed("Item2")%>'>
item2
</td>
<td id="Td3" runat="server" visible='<%#ItemAllowed("Item3")%>'>
item 3
</td>
</tr>
<asp:Repeater ID="Repeater1" runat="server" DataSource='<%# GetData((int)Eval("Id"))%>'>
<ItemTemplate>
<tr>
<td id="Td9" title='<%#Eval("Item1Status")%>' runat="server" visible='<%#ItemAllowed("Item1")%>'
style='background-color: <%#Eval("Item1StatusColour")%>;'>
</td>
<td id="Td10" title='<%#Eval("Item2Status")%>' runat="server" visible='<%#ItemAllowed("Item3")%>'
style='background-color: <%#Eval("Item3StatusColour")%>;'>
</td>
<td id="Td11" title='<%#Eval("Item3Status")%>' runat="server" visible='<%#ItemAllowed("Item4")%>'
style='background-color: <%#Eval("Item4StatusColour")%>;'>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
Update
The style renders like this :
style="background-color:<%# ""+ Eval("Item1StatusColour")%>;"
All the rest of the attribute render how they should.
Update
This is the ItemAllowed method as requested
public bool ItemAllowed(string item)
{
//allowed items is a list<string>
return AllowedItems.Contains(item);
}
The first thing I would recommend is using css classes instead of what you are doing.
When you use html elements with runat=server, you are converting it into an html control and .net is rendering the final output. Your particular issue arises from .net wrapping the value with htmlencode or something to that effect.
I would suggest perhaps using a gridview with a onrowdatabound event. Then you can do anything programmitically in the code-behind.
I don't think it likes a combination of code and inline strings, so you could try doing it all in code:
<td ... style='<%# "background-color:" + Eval("Item2StatusColour")%>'>
Unfortunately don't have VS in front of me so can't verify it, let me know if it works.
If your controls are runat server I would personally recommend hooking into the OnItemDataBound event within the repeater, and then in your code behind handle all of your calculations there. Here's a quick example
ASPX
...
<asp:Repeater ID="rptItems" runat="server" OnItemDataBound="rptItems_OnItemDataBound" DataSource='<%# GetData((int)Eval("Id"))%>'>
<ItemTemplate>
<tr>
<td id="Td9" runat="server"></td>
<td id="Td10" runat="server"></td>
<td id="Td11" runat="server"></td>
</tr>
</ItemTemplate>
</asp:Repeater>
...
Code behind
protected void rptItems_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType != ListItemType.AlternatingItem && e.Item.ItemType != ListItemType.Item)
{
return;
}
var currentItem = e.Item as YourDataItemTypeHere;
var td9 = e.Item.FindControl("Td9") as HtmlTableCell;
td9.Attributes["title"] = currentItem.Item1Status;
td9.Style["background-color"] = currentItem.Item2StatusColour;
...
}
On a side note
From a more readable perspective I would also recommend renaming controls to something more readable, i.e. what is td9, td10 and td11? Instead it would be easier to understand if it were say tdFirstStatus, tdSecondStatus and tdThirdStatus, but that's just a preference thing.
Just noticed that my answer is exactly the same as Sir Crispalot's! I have however tested this and I've replicated the bug and the fix in Visual Studio 2008...
Like this...
<td id="Td9" title='<%#Eval("Item1Status")%>'
runat="server"
visible='<%#ItemAllowed("Item2")%>'
style='<%# "background-color:" + Eval("Item2StatusColour")%>' >
I believe that Eval is expecting a dataitem name, not an expression. However <%# %> expects an expression which can contain operations. The Eval can then be used within here and concatenated to the string "background-color".
I don't fully grok all the asp inline-tags - they're always a headache!
PS - I notice there is a mismatch between the Item numbers within your <td>s - is this intentional? eg Item1 and Item2 are referenced within the same <td>...
I have a simple repeater that looks like:
<asp:Repeater runat="server" ID="rptOptions" OnItemDataBound="rptOptions_ItemDataBound">
<HeaderTemplate>
<thead>
<tr>
<td class="GridHeader">Account</td>
<td class="GridHeader">Margin</td>
<td class="GridHeader">Symbol</td>
<td class="GridHeader">Usymbol</td>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tbody>
<tr runat="server" ID="trOption">
<td class="GridRow"><asp:Label runat="server" ID="lblOptionAccount"></asp:Label></td>
<td class="GridRow"><asp:Label runat="server" ID="lblOptionMargin"></asp:Label></td>
<td class="GridRow"><asp:Label runat="server" ID="lblOptionSymbol"></asp:Label></td>
<td class="GridRow"><asp:Label runat="server" ID="lblOptionUsymbol"></asp:Label></td>
</tr>
</tbody>
</ItemTemplate>
</asp:Repeater>
Now, in my code-behind I have an event which is fired that is supposed to add/insert a row into the database. After this happens, I re-grab the new list of options from the database and re-bind them to the repeater. This takes place inside an update panel so the list refreshes right away for the user.
protected void lbtnAddOptionSave_Click(object sender, EventArgs e)
{
SelectedOption = new Option()
{
Account = txtAddOptionAccountNumber.Text,
Margin = chkAddOptionMargin.Checked,
Symbol = txtAddOptionSymbol.Text,
Usymbol = txtAddOptionUsymbol.Text,
};
Presenter.OnAddOption(); // Insert new option into database
RefreshOptions(); // Re-get list of options, bind them to repeater
}
Now, what I would ~love~ to do, is use the jQuery ScrollTo plugin to scroll straight to the newly added row.
What would be the best way to call the ScrollTo() method in the jQuery plugin so I scroll to that particular row that was just added? Is there anyway I can mark my rows in my ItemTemplate so I can easily select an element to scroll to via jQuery?
Ideally, right after RefreshOptions() I would like to execute the ScrollTo function to scroll down to the new row.
If you know the client side Id of the row (which you can get), its relatively painless to simply call
$(document).scrollTo("#<row-id-here>", 800);
When you add the object to the database (or just after that), grab the id of the newly inserted object. Modify the repeater to include a Label with Visible="false" so that it doesn't get rendered to the client. Hook into the ItemDataBound event and check each label against the id you've grabbed. When you find the matching row, you can get the id of the row and then you'll be able to use for the scrolling parameter.
Note: Other data-bound controls have a DataKey property which could be used for the id of the object and make this a bit simpler. Not sure if you're tied to the Repeater at this point, but a GridView or ListView could be worth looking into.
I have a login page that has several textboxes on the page, one of them has the mode set to "password". This page worked previously but we've recently noticed (since an IE7 update) that the textbox that is specified as a password textbox is not as wide as the other textboxes on the page. If I remove the TextMode="Password", the textbox resizes to match the others.
I've checked for oddities on the page when the page displays using the IE developer toolbar, but it all looks ok.
The textbox code is fairly basic:
<tr>
<td>
Username
</td>
<td>
<asp:TextBox ID="txtUsername" runat="server" TabIndex="2"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Password
</td>
<td>
<asp:TextBox ID="txtPassword" TextMode="Password" runat="server" TabIndex="3"></asp:TextBox>
</td>
</tr>
I've found one other person asking about this on the web and they fixed it by applying a css to all the input controls on the page, but I haven't managed to get that to work either.
The best way to ensure that all of your controls will be of the same size is via style (either inline or in css).
I've found that if you use the following CSS:
input, select { font-family: sans-serif; }
this will make the text and password boxes be the same width. The font-family does not have to be sans-serif, but it must be defined.
This may be a better solution as it seems to fix the issue rather than band-aid over it by using an explicit width in your CSS. You can now just use the default font settings of the browser by using the generic font families or be explcit if you have a particular font you are using for the page.
It may help if you provide a Width="" property to your textboxes. That should force them to match up in terms of width even those they have different text modes.
If you specify a value (like 20) for the TextBox.Columns property (which maps to the <input size="" /> attribute) they'll match up. If you want to use CSS, you should try to avoid an inline style (which the TextBox.Width property creates).
You may try setting Width property of all the text boxes to be same. 150 would be a good value.
I think it is normal to have different widths for password-type and non-password-type textboxes when you specify the size as "columns", as the width of a textbox is calculated by multiplying the width of the largest character in the font (say, "m") by the requested number of columns.
When passworded, the largest character is always the bullet (all chars are bullets), so the width is different (when using a proportional font obviously). To solve this problem, specify a width in pixel and not columns, i.e.: style="width:250px;" (or use a non-proportional font).
I recently ran into this problem with internet explorer 11. I tried everything here and nothing worked, but then stumbled onto this post. What solved it for me was doing this:
<tr>
<td style="width: 1000px; text-align: right;">User Name:</td>
<td style="width: 200px; text-align: right;">
<asp:TextBox ID="UNTextBox" runat="server" style="width: 200px;"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 1000px; text-align: right">Password:</td>
<td style="width: 200px; text-align: right;">
<asp:TextBox ID="PassTextBox" runat="server" TextMode="Password" style="width: 200px;"></asp:TextBox>
</td>
</tr>
I HAD to put in style="width: 200px;" straight into the asp:TextBox tag or the sizes just would not match up in IE11.
Hope that helps someone