Q:
I have a gridview contains a textbox as a template field :
the aspx:
<asp:GridView Width="100%" ID="gv_Evaluation" CssClass="datatable" AllowSorting="True"
runat="server" AutoGenerateColumns="False" AllowPaging="True" GridLines="None"
OnRowDataBound="gv_Evaluation_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="serial">
<ItemTemplate>
<asp:Label ID="lblSerial" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="activity type" DataField="activityType" />
<asp:BoundField HeaderText="weight" DataField="activityWeight" />
<asp:TemplateField HeaderText="evaluation">
<ItemTemplate>
<telerik:RadTextBox ID="txt_evaluateWeights" runat="server" AutoPostBack="True"
OnTextChanged="txt_evaluateWeights_TextChanged"></telerik:RadTextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txt_evaluateWeights" Display="Dynamic" ErrorMessage="*" SetFocusOnError="True"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle VerticalAlign="Top" CssClass="row" />
</asp:GridView>
the weight column contains the following numbers[50,10,10,10,5,5,10]
What I wanna to do is:
Validate the data entry when the user enters the data in the txt_evaluateWeights Where it must be less than or equal the meeting one in the weight column. I do that in server side. But I wanna to do that client side. I tried to use the compare validator but it doesn't suit my case because each time i compare with a different value, according to the weight column.
You can use the CustomValidator class and set the ClientValidationFunction property to use clientside validation
see MSDN documentation
Related
I have a gridview with bounded fields. In the first column "Priority" I'd like to bind the priority number but also add multiple glyphicon's based on flags from other columns in the datatable. There are columns "HOT_FLAG", "WATCH_FLAG" and "INFO_FLAG" and if those are true, I need to display the corresponding glyphicon.
<asp:GridView
ID="dgv_Test"
GridLines="None"
AutoGenerateColumns="False"
OnRowCreated="dgv_RowCreated"
EnableHeadervisualstyles ="true"
runat="server">
<Columns>
<asp:BoundField DataField="PRIORITY" HeaderText="#"/>
<asp:BoundField DataField="COL2" HeaderText="COL2" />
<asp:BoundField DataField="COL3" HeaderText="COL3" />
</Columns>
</asp:GridView>
I'm assuming I need to convert these bound fields to template fields (or something else) and set the Glyphicon's in the code behind but I'm not sure where to go from here.
Try this.
<asp:TemplateField HeaderText="#">
<ItemTemplate>
<asp:Image ID="HotFlag" runat="server" ImageUrl="path/to/image" Visible='<%# Eval("HOT_FLAG") %>'/>
<asp:Image ID="WatchFlag" runat="server" ImageUrl="path/to/image" Visible='<%# Eval("WATCH_FLAG") %>'/>
<asp:Image ID="InfoFlag" runat="server" ImageUrl="path/to/image" Visible='<%# Eval("INFO_FLAG") %>' />
</ItemTemplate>
</asp:TemplateField>
I have multiple asp.net data grids that a user can select a checkbox to the corresponding value that they want, put in the amount they want in a textbox and submit the request. How do I show what values they requested with the amount on the next page? I can do this with a session I believe but I'm having a hard time finding good examples for something like this. Since they can select multiple values I can't use a query string right? I'm using VB.net but if you answer in c# that's fine. Thanks!
<asp:GridView ID="flexGridView" DataKeyNames="ID" runat="server" AutoGenerateColumns="False" DataSourceID="FormSqlDataSource" CssClass="gridView" ClientIDMode="Static">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="flexCheckBoxList" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Form" ShowHeader="False" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" Visible="False" />
<asp:BoundField DataField="Category" HeaderText="Category" SortExpression="Category" ShowHeader="False" Visible="False" />
<asp:TemplateField Visible="false">
<ItemTemplate>
<asp:Label ID="lblEmail" runat="server" Text='<%# Eval("Email")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Qty" >
<ItemTemplate>
<asp:TextBox ID="flexTextBox" runat="server" Width="40" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
You can use Session or query string, but I would recommend Session, as there are limitations on the length of a query string, especially if you are not sure how many check boxes might be checked.
Use the OnCheckChanged event of the check box control and set AutoPostBack to true in your template field, like this:
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="flexCheckBoxList" runat="server"
AutoPostBack="True" OnCheckedChanged="Check_Clicked" />
</ItemTemplate>
</asp:TemplateField>
protected void Check_Clicked(Object sender, EventArgs e)
{
// Store the check box name, ID or whatever unique value you want in Session here
CheckBox theCheckBox = sender as CheckBox;
// Was the check box found?
if(theCheckBox != null)
{
// Store in Session
Session["CheckBoxValue"] = theCheckBox.SomePropertyValue;
}
}
Then in the Page_Load of your redirect page, you will need to read out the Session value for the checked check boxes.
I created with ASP.NET Dynamic Data Entities Web App and ADO.NET Entity Data Model an dynamic application to modify an sql table.
But how can i modify in gridView column width?? The columns are big but the data will be cut.
Table column width screenshot
In *.edmx file the MaxLength is set to 300.
<Property Name="foreign_data" Type="nvarchar" Nullable="false" MaxLength="300" />
The grid view in Lists.aspx looks like:
<asp:GridView ID="GridView1" runat="server" DataSourceID="GridDataSource" EnablePersistedSelection="true"
AllowPaging="True" AllowSorting="True" CssClass="DDGridView"
RowStyle-CssClass="td" HeaderStyle-CssClass="th" CellPadding="6"
PageSize="15">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:DynamicHyperLink runat="server" Action="Edit" Text="Bearbeiten"
/> <asp:LinkButton runat="server" CommandName="Delete" Text="Löschen"
OnClientClick='return confirm("Sind Sie sicher das Sie diesen Datensatz löschen möchten?");'
/> <asp:DynamicHyperLink runat="server" Text="Details" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle CssClass="DDFooter"/>
<PagerTemplate>
<asp:GridViewPager runat="server" />
</PagerTemplate>
<EmptyDataTemplate>
There are currently no items in this table.
</EmptyDataTemplate>
</asp:GridView>
So how can i control the lenght. By the way, every field is cut after 22 chars! I search the whole solution but no more MaxLength values found. If I set MaxLength Value in gridView it doesen't work.
Ok I solved it. I've modified the field template (text.ascx.cs) from
private const int MAX_DISPLAYLENGTH_IN_LIST = 25;
to an higher value....
Maybe you entered some "maxlength" Attribute cause both of your values are 22 characters Long.
something like this maybe?
<asp:TextBox ID="txtmyValue" MaxLength="10" runat="server" ..../>
Did you got "BoundField"'s so maybe you should replace them with "TemplateField"'s instead so you can control whats going on:
<asp:TemplateField HeaderText="my text value">
<ItemTemplate>
<asp:TextBox ID="txtmyValue" MaxLength="40" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "YOUR_BOUND_ITEM_NAME") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
I need to develop such a program in which the GridView's rows should be decided at run time.
i.e. I have a table in database called dealer capacity.
Dealer_ID Capacity
D0001 5
Now when the Dealer D00001 is selected from combo box the number of rows in grid view should be 5. I want to use the template field also.
My code for GridView is:
<asp:GridView ID="grdlicence" runat="server" DataKeyNames="Version_id" GridLines="None" BorderStyle="Solid" AutoGenerateColumns="false" AllowSorting="true"
CssClass="mGrid table"
PagerStyle-CssClass="pgr"
AlternatingRowStyle-CssClass="alt" >
<Columns>
<asp:BoundField DataField="Version_name" ItemStyle-CssClass="uppercase" ItemStyle-Width="150px" HeaderText="Version" HeaderStyle-HorizontalAlign="Left" />
<asp:BoundField DataField="Version_id" Visible="false" HeaderText="Version" HeaderStyle-HorizontalAlign="Left" />
<asp:TemplateField HeaderText="Price">
<ItemTemplate>
<center><asp:TextBox ID="txtprice" CssClass="alignments TextStyle" MaxLength="5" runat="server" ></asp:TextBox></center>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Licence Id">
<ItemTemplate>
<center><asp:TextBox ID="txtlicenceid" CssClass="alignments uppercase" runat="server" ></asp:TextBox></center>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Purchase Date">
<ItemTemplate>
<center><asp:TextBox ID="txtpurchasedate" onfocus="showCalendarControl(this);" CssClass="alignments TextStyle" runat="server"></asp:TextBox></center>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Expiry Date">
<ItemTemplate>
<center><asp:TextBox ID="txtexpirydate" onfocus="showCalendarControl(this);" CssClass="alignments TextStyle" runat="server"></asp:TextBox></center>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Upload File">
<ItemTemplate>
<center><asp:FileUpload ID="fileUpload" runat="server" /></center>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
You need to define PageSize for your GridView and remember to set AllowPaging to true for the GridView
GridView.PageSize Property
Gets or sets the number of records to display on a page in a GridView
control.
The default is 10.
You may see this article: GridView Paging Sample in ASP.NET
You can use the linq Take() and pass the number as parameter.
Updated according to the comment, use following code.
grdlicence.DataSourse= ds.Take(5);
grdlicence.DataBind();
I have a gridview with a hyperlink:
<asp:GridView ID="gvEmployees" runat="server" AutoGenerateColumns="False"
CssClass="table table-hover table-striped" GridLines="None" >
<Columns>
<asp:TemplateField HeaderText="Name" SortExpression="EmployeName">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server"
Text='<%# Bind("EmployeName") %>' ></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ID" SortExpression="EmployeID" Visible="False">
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text='<%# Bind("EmployeID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
However, it should only appear as a hyperlink if the employeeID is that of the logged in employee.
I can do all that, but what I do not know is how to make the hyperlink look like a Label. It's easy to have it not link anywhere, but I do not know how to make it look like a label.
Thanks
I believe if you set Enabled="false" it does. If it does not, then the only way to do that is put both a HyperLink and Label in the cell, and show the link when appropriate, and the label when appropriate, hiding the other one (which can be easily done in RowDataBound event).