I use PNM Sequence. And I need to make one grid column as the mandatory field.
I know how to make it with any separate control. E.g. I can type:
<sq8:GridBoundColumn DataField="txtField" HeaderText="txtField"
SortExpression="txtField" UniqueName="txtField" FilterControlAltText="">
<ColumnValidationSettings>
<RequiredFieldValidator ForeColor=""></RequiredFieldValidator>
</ColumnValidationSettings>
</sq8:GridBoundColumn>
And I can use this Validator for the TextBox:
<sq8:Label runat="server" Text="Field:" ID="Label1" Width="100%"></sq8:Label>
<nobr>
<sq8:TextBox runat="server" ID="txtField" Width="100%"></sq8:TextBox>
<sq8:RequiredFieldValidator runat="server"
ErrorMessage="RequiredFieldValidator"
ID="RequiredFieldValidator4"
ControlToValidate="txtField"
SetFocusOnError="True">*</sq8:RequiredFieldValidator>
</nobr>
<sq:BindableControl runat="server" TargetControlID="txtField"
DataField="txtField"></sq:BindableControl>
And it works. User can't send the form because he gets an error - the field is empty.
But I need to do the same with grid.
When I open "Edit columns" in Grid Wizard I can't see any property as "mandatory" or something like this.
And the code with RequiredFieldValidator doesn't work with a grid column. If I try to use it:
<Columns>
<sq8:GridBoundColumn DataField="txtFieldGrid" HeaderText="txtFieldGrid"
SortExpression="txtFieldGrid" UniqueName="txtFieldGrid"
FilterControlAltText="">
<sq8:RequiredFieldValidator runat="server"
ErrorMessage="RequiredFieldValidator"
ID="RequiredFieldValidator4"
ControlToValidate="txtFieldGrid"
SetFocusOnError="True">*</sq8:RequiredFieldValidator>
<sq:BindableControl runat="server" TargetControlID="txtFieldGrid"
DataField="txtFieldGrid"></sq:BindableControl>
</sq8:GridBoundColumn>
</Columns>
In this case, I have an error:
Is there some method for grid column validation? Or it's impossible with a grid?
Maybe I can use some javascript?
Related
So I have gridview pulling fields from a table and my hyperlinkfield is used to go to a specific page for that row to get more detailed data. Everything seems to work great except when the field used in the hyperlinkfield has an ampersand. I assume it is reading the ampersand as something else and so it doesn't bring up the proper info because the ampersand is in the name in the database.
Hyperlinkfieldcode:
<asp:HyperLinkField HeaderText="Name" Text="{0}" DataNavigateUrlFields="Name" DataNavigateUrlFormatString="item.aspx?name={0}" DataTextField="Name" />
Example:
A clicking on the name "test item" would take you to mysite.com/item.aspx?name=test%20item and this works.
However, clicking on "test & test item" it takes you to mysite.com/item.aspx?name=test%20item%20&%20item which does not work. It just pulls up a page with blank info.
What can I do to fix this?
Update:
I converted the hyperlinkfield to a hyperlink inside a template field, but the url is now coming out weird.the url now comes out like mysite.com/item.aspx?name=System.Int32%5b%5d
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:HyperLink runat="server" Text='<%#Eval("Name") %>' DataNavigateUrlFields="Name" NavigateUrl='<%# "name.aspx?name=" + HttpUtility.UrlEncode({0}.ToString())%>' DataTextField="Name" />
</ItemTemplate>
</asp:TemplateField>
My original answer was incomplete (due to not being able to see the entire code). This answer will contain the missing elements.
The main object is to UrlEncode the data field Name, so that it can be used as (part of) a url link .
1 - First we must ensure that the field "Name", is listed as DataKeyNames for the GridView as follows:
<asp:GridView ID="GridView1" runat="server" DataKeyNames="Name" ...
2 - Secondly (if using a navigateURL) create a TemplateField i.e. (asp:TemplateField ) and use Eval() method to access the DataField in conjunction with UrlEncode() .
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:HyperLink ID="NameLink" runat="server" Text='<%# Eval("Name") %>' NavigateUrl='<%# "name.aspx?name=" + HttpUtility.UrlEncode(Eval("Name").ToString())%>' ></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
Option 2 Alternatively you can use a HyperLinkField and DataNavigateURL but you should still designate Name as a DataKeyNames .
Hope this works with no problems. Let me know if any clarification is needed.
Happy coding and Cheers,
i want to know status is active or not in check box. how to bind check box with database data. while editing im lossing previous data. data is not showing in check box
code behind updating event
cmd.Parameters.AddWithValue("#LeadsAccess", ChkLeads.Checked);
<asp:TemplateField HeaderText="Leads">
<ItemTemplate>
<asp:CheckBox ID="ChkLeads" runat="server" />
</ItemTemplate>
</asp:TemplateField>
db column- [Leads]
You can try like this
<asp:CheckBox ID="ChkLeads" runat="server"
Checked='<%#bool.Parse(Eval("columnName").ToString())%>' />
try this..
you can bind the db value like this..
<asp:CheckBox ID="ChkLeads" runat="server" AutoPostBack="true" Checked='<%#Convert.ToBoolean(Eval("LeadsAccess"))%>'/>
I have a GridView which has a TextField column in it .. I've setup validation for this TextField column so that it requires an input (i.e. its not optional), and that the input can be a positive integer only ..
The errors do show up when a text field is either empty or has doesn't have a positive integer value, but there's a server-side button which still executes even when there are errors in the GridView ..
I want the button to NOT do its processing if there are inputs errors .. Currently this doesn't happen, as the button's click event is still called even when there are errors ..
GridView Markup Code:
<asp:GridView ID="EPSAndTSRValuesInputGridView" runat="server" ShowFooter="true"
AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="EPS Value">
<ItemTemplate>
<asp:TextBox ID="EPSValue" Text='<%# Eval("EPSValue") %>' runat="server" CausesValidation="True" ValidationGroup="Display"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Enter a valid value for EPS!"
ValidationExpression="^\d*$" ControlToValidate="EPSValue" ValidationGroup="Display"/>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
ControlToValidate="EPSValue" ValidationGroup="Display"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Button which performs the next action:
<asp:Button ID="btnDisplayReport2"
runat="server" CssClass="ButtonStyle"
Text="Display Report" ValidationGroup="Display" OnClick="btnDisplayReport2_Click" CausesValidation="true"/>
This is happening because your Button have validation group Display so on click of it will validate only control with same group i.e. Display.As I can see there no validation group of your Textbox so it will not validate it in button click..,to cause validation on Click of Button Add same validation group in your Textbox,RegularExpressionValidator, and RequiredFieldValidator too.
I think it's because they don't have the same ValidationGroup.
Try adding ValidationGroup="Display" to your validators.
You are saying to execute the validation group Display on your button click.It will validate only control have the validation group (dispaly) as you mentioned.You are not defined any validation group for Textbox validators Try by Add same validation group(displa) in your Textbox,RegularExpressionValidator, and RequiredFieldValidator.
I have an asp.net web page where i have a checkbox control inside gridview control as under
<asp:GridView ID="grdMergeCoverage" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<input type="checkbox" id="chkSelectStream" onclick="OnSelectionChanged(this);"
testrunid='<%#DataBinder.Eval(Container.DataItem,"TestRunId") %>'
checked='<%#DataBinder.Eval(Container.DataItem,"CodeCoverageRequired") %>'
servername='<%#DataBinder.Eval(Container.DataItem,"ServerName") %>'
runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
And the OnSelectionChanged function is as under
function OnSelectionChanged(id)
{
alert(id.testrunid);
alert(id.servername);
alert(id.checked);
}
In IE8 , I am able to get the value for testrunid,servername while in IE 9, it is coming as NULL.
What is the problem and how can i get the value in all the cases?
To get custom attributes you should use the getAttribute method.
Like so: id.getAttribute("servername").
The way you used to get the value before is non-standard and not always supported.
you can add the asp checkbox and add the attribute to it on the gridview rowitembound event. it will fire....
I'm trying to bind a GridView HyperLinkField such that the bound column is used as a parameter value in the URL. Pretty standard stuff - nothing fancy, but the binding fails when the bound column contains a colon, i.e. :. I'm my particular case, this value is a string representing a duration of time, e.g. "14:35", or "1:07:19".
Here's my GridView, with the time value bound to the HyperLinkField url.
<asp:GridView ID="ResultsGridView" runat="server" AutoGenerateColumns="False"
DataSourceID="ResultsDataSource" EnableModelValidation="True"
AllowPaging="True">
<Columns>
<asp:BoundField DataField="Year" HeaderText="Year" SortExpression="Year" />
<asp:HyperLinkField DataNavigateUrlFields="RunTime"
DataTextField="RunTime" HeaderText="Hyperlink"
DataNavigateUrlFormatString="LinkedPage.aspx?param={0}" />
<asp:BoundField DataField="RunTime" HeaderText="Time"
SortExpression="RunTime" />
<asp:BoundField DataField="FullName" HeaderText="Name"
SortExpression="FullName" ReadOnly="True" />
</Columns>
</asp:GridView>
It produces HTML like this. Note that the <a> tags have no href attribute.
<tr>
<td>2010</td><td><a>34:58</a></td><td>34:58</td><td>Joe Schmoe</td>
</tr><tr>
<td>2010</td><td><a>35:30</a></td><td>35:30</td><td>Rod Krueger</td>
</tr><tr>
<td>2010</td><td><a>35:38</a></td><td>35:38</td><td>Mike Johnson</td>
</tr>
But if I switch the bound field from RunTime to Year, i.e. to a column that doesn't contain a colon in the values, it works as expected. Take the GridView above, and change the DataNavigateUrlFields attribute of the HyperLinkField, like so:
<asp:HyperLinkField DataNavigateUrlFields="Year"
DataTextField="RunTime" HeaderText="Hyperlink"
DataNavigateUrlFormatString="LinkedPage.aspx?param={0}" />
And now the HTML output is correct, like this:
<tr>
<td>2010</td><td>34:58</td><td>34:58</td><td>Joe Schmoe</td>
</tr><tr>
<td>2010</td><td>35:30</td><td>35:30</td><td>Rod Krueger</td>
</tr><tr>
<td>2010</td><td>35:38</td><td>35:38</td><td>Mike Johnson</td>
</tr><tr>
So the nut of my question is this: how do I bind a data column with values that contain a colon to the URL of a HyperLinkField? Or, failing that, create the same bound hyperlink by another method?
Changing the format of the data to not include a colon would be a last resort, because LinkedPage.aspx expects the parameter value in that format, and it's already written, tested and in use.
<asp:TemplateField HeaderText="Hyperlink">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl='<%# Eval("RunTime", #"LinkedPage.aspx?param={0:hh\:mm}") %>'
Text='<%# Eval("RunTime", #"{0:hh\:mm}") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
Wow, very strange, worse comes to worse, as a very last step, you can always tap into RowDataBound, and set the cell text to hyperlink HTML yourself, but in the meantime, try tapping into RowDataBound and examining the results there. Maybe you can encode the value at binding time, so that if there is an issue with :, encoding probably will resolve it?
You may also want to submit that as a bug to connect.microsoft.com...
HTH.