Tie a custom savebutton to itemtemplate textbox - c#

using Visual.Web.Developer.2010.Express;
using SQL.Server.Management.Studio.2008.R2;
using Northwind;
N00b here,
Trying to customize a asp.net gridview, and I'm stuck at this part...
In the ItemTemplate, I've got a text-box that has a class applied to it where on .keypress(Clientside JS), a asp:LinkButton appears next to it that's formatted like a Jquery UI icon. I'm stuck at this part. I know that I can "enable editing" for the gridview, but I want to make an edit button only appear on .keypress, which I’ve already achieved. The park I’m stuck at is trying to get the click of that asp:LinkButton to send an update command to the SQLserver to update that db entry accordingly . So far, I’ve got the textbox to be created dynamically for each db item in that column.
Is there a more practical way of doing this while achieving the same results? To be more specific, I'm not really looking for code, cause I'm trying to learn, but more for methods I should take a look at, or other tutorials that I missed on the web.
I would also appreciate some advice, thanks in advance: )

You can try using GridView_RowCommand event to fetch the Command event bubbled by Linkbutton.

You can use CommandName Property of the LinkButton and set it to Update.
<Columns>
<asp:TemplateField>
<EditItemTemplate>
<asp:linkbutton ID="Button1" text="TextBox1" runat="server" CommandName="Update" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>

Related

How to set visibility of ASP.net hyperlinkfield dynamically

I have a DataGridView with ASP.net hyperlink fields inside of it. What I'm trying to do is not display a certain hyperlink based on a condition. I have SQL that determines if the hyperlink should be hidden or not, but I'm having trouble getting this to work in the hyperlinks.
I tried <asp:HyperLinkField....Visible="<%= Eval(Condition) %>" /> where Condition is True or False from my SQL query.
Which of course throws the error Cannot create an object of type 'System.Boolean' from its string representation '<%= Eval(Condition)%>' for the 'Visible' property.
So I understand this from Why will <%= %> expressions as property values on a server-controls lead to a compile errors? and other similar questions.
My question now is: what is the workaround? How can I get the hyperlink to display or not based on my condition?
You cannot change HyperLinkField's Visible on runtime, because it does not have a DataBinding event.
Instead, you should not be changing HyperLinkField's Visible value. The problem is the rest of the column will not be aligned properly if you hide a single cell.
Instead, you want to use TemplateField and HyperLink, and hide a link only (leave the table cell by itself). For example,
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="ConditionHyperLink" runat="server"
Visible='<%# Convert.ToBoolean(Eval("Condition")) %>'
Text="Link" />
</ItemTemplate>
</asp:TemplateField>
FYI: Your syntax is not correct; it should be ='<%# Eval("") %>'
My recommendation would be to handle it in the codebehind, most likely handling the RowCreated event, and setting the Visible property of the control there. There might be more context to your application that I'm missing, but that seems like the simplest way.
This is the event: https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcreated(v=vs.110).aspx
Other events on the gridview in case that one doesn't meet your needs: https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview_events%28v=vs.110%29.aspx

Changing BizForm properties Kentico

I am currently trying to have a bizform as part of my transformation as:
<cms:BizForm runat="server" ID="BizForm" FormName="YourBizFormCodeName" EnableViewState="false" FormDisplayText="Form submitted"/>
In the DocumentType/PageType I have a field that allows the user to enter whatever they want to display once the form has been submitted, so in theory I need to go about and change FormDisplayText to what has been provided.
I have tried using Eval("SubmitText") inside FormDisplayText, but it doesn't work.
Does anyone have a solution for this?
Thank you
Following code works fine for me (Kentico v8.1):
<cms:BizForm runat="server" ID="BizForm" FormName="test" EnableViewState="false"
FormDisplayText='<%# CMS.MacroEngine.MacroContext.CurrentResolver.ResolveMacros("{%CurrentDocument.SubmitText#%}") %>' />

What data viewing control will I need to use?

I am new to asp.net and even though I have been successfully developing some decent pages
that access backend SQL server using C# code behind, I have run into a problem that I need
some nudge in the right direction on.
I need to be able to display records from a SQL datasource (could be displayed using SQLDataSource method
OR using a dataReader OR using a gridview data fill) onto a page but I need other information displayed above
and below the returned record. Its best if I show an example:
<horizontal seperator line>
Customer ID
Customer Name
Customer Address
City, ST
COLUMNS FOR THE RETURNED RECORD DATA
THE ACTUAL RECORD DATA
OTHER DYNAMICALLY CALCULATED DATA BELOW THE RECORDS
<horizontal seperator line>
And this repeats for every record that is returned
For the life of me, I can't find determine what view, template, or even best data binder or
data source control it is that I need to use to make this happen.
Thanks for anyone's assistance in advance.
dell
If a datatable or gridview won't do, you can always use a Repeater or a Listview.
In the template, you can have all the controls you want in there.
You probably need a repeater similar to this:
<asp:Repeater runat="server" ID="repeater1">
<ItemTemplate>
<hr/>
<asp:Label runat="server" ID="labelCustomerId" />
<div style="padding-left:150px">
<asp:Label runat="server" ID="labelCustomerName" />
<asp:Label runat="server" ID="labelCustomerAddress" />
<asp:Label runat="server" ID="labelCityState" />
</div>
<asp:GridView runat="server" ID="gridViewRecordData">
<!--define columns & footer calculations here -->
</asp:GridView>
<hr/>
</ItemTemplate>
</asp:Repeater>
You can use the same ItemTemplate if you chose a ListView
Repeated is the best control. but in repeater you need to write code for Paging, Sorting...etc functiontly.
If you don't want to code for paging, sorting then go for GridView.
Try a ListView control. It lets you use templates to define how records, groups of records, etc. show up. For example you could define a template for your customer contact info, then a template for your records and other data.
You can accomplish this easily with a ListView. This article has a display of product information that's a lot like your layout -- horizontal lines between repeated sections.
I also like Scott Gu's tutorial, though the data layout (catalog images) is a little different from yours. Still, there's some good screenshots, and it also demos a Linq to SQL data source, which is a popular choice.

Looking for suitable DataBound control to implement questions page

I looking forward to find a suitable asp.net DataBound control (C#) to implement in my application.
I wanted to create a exam page where each page show 10 questions, each question got a Label control and a radiobutton control to display the choices, the data to be bind into the DataBound control might be having multiple rows where each rows represent each question.
I found that DetailView control was quite suit with my requirement but I not able to set the page size.
Please help to give some suggestion and advises, thank you in advanced.
I would use a DataList or a ListView, because it will allow you to enter a template for each item. The reason I would choose these over a repeater is because you can use data keys, which will probably come in handy.
Here's a simple example of how you could implement a list of questions:
<asp:DataList ID="DataList1" runat="server" DataKeyField="QuestionID" ...>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("Question")%>' />
<asp:RadioButton ID="RadioButton1" runat="server" Text="Yes" GroupName="QuestionAnswer" ... />
<asp:RadioButton ID="RadioButton2" runat="server" Text="No" GroupName="QuestionAnswer" ... />
</ItemTemplate>
</asp:DataList>
I would recommend to you to use the Repeater control since you can customize it's design very easily to suit your needs.
Here are two tutorials on how to use it:
http://www.w3schools.com/aspnet/aspnet_repeater.asp
http://www.learn-asp.net/asptutorials/Repeater.aspx
Update:
Repeater doesn't have pagination included so you would have to add it:
http://blog.divergencehosting.com/2009/03/25/adding-paging-repeater/
Other option would be to just use a GridView which has pagination included.

TextChanged event not firing

I have a GridView and a TextBox in one of its fields:
<asp:GridView ID="NTSBulkEditGridView" runat="server" AutoGenerateColumns="false" AllowSorting="true" Height="500px"
DataKeyNames="BookStem" OnRowDataBound="NTSBulkEditGridView_RowDataBound" DataSourceID="NTSSqlDataSource">
<Columns>
<asp:TemplateField HeaderText="Priority" SortExpression="Priority">
<ItemTemplate>
<asp:TextBox ID="txtPriority" runat="server" Text='<%# Eval("Priority") %>' BorderStyle="None" Width="80%" OnTextChanged="TextBox_Changed" AutoPostBack="true"></asp:TextBox>
<asp:CompareValidator ID="PriorityCompareValidator" runat="server" ControlToValidate="txtPriority" Display="Dynamic" ErrorMessage="Priority must be an integer!" Text="*" Operator="DataTypeCheck" Type="Integer" ValidationGroup="InsertUpdateNewTitlesStatusValidation" ></asp:CompareValidator>
</ItemTemplate>
</asp:TemplateField>
...
Could you please tell me why TextBox_Changed() is never called when I change text and press Enter? I tried to put same kind of a TextBox outside of the GridView, and there it works.
Thanks.
TextChanged of an ASP.NET TextBox translates into blur JavaScript event. And blur occurs when the text of the input element is changed and the input element loses focus. Try to change the text, but don't hit Enter. Simply hit TAB key to go to next field. Does it fire post back?
Update:
Well, I saw that link. Two things. First, if you notice, it goes back to 2005 and ASP.NET 2.0 and we all know that 6 years in the world of computer means 60 years. So that article is obsolete by now. Second, sometimes a pattern only exists in articles, and you rarely see it in real productive systems. How many bulk actions have you seen on the web? And what type do they have? Consider Gmail, or Yahoo mail for example. You can mark 20 or 30 or X number of emails as read in one shot. But, can you respond to 20 mails in one step? Nope, just because it doesn't make sense. I've never seen a bulk action on a text box in web world. I think you'd better stick to use AJAX, with better performance, and more user acceptance. :)

Categories