There is a RadGrid which contains RadcomboBox along with button next to it.
When user key-in something and click on button, data bind in RadComboBox related to key-in text and display in DropdownList.
but this DropdownList appear far below from RadcomboBox, which disturbs the look & feel of the page. Please refer the attached issue snapshot.
I tried to set ExpandDirection="Down" property but did not worked.
Also I tried to set EnableScreenBoundaryDetection="false", this sticks the
Dropdownlist at the bottom of page, so when I scroll the page , DropDown always stick at bottom & it also scrolls with the page.
Also, I set the HighlightTemplatedItems="true" but it is not working at all.
EDIT:
HTML code:
<telerik:RadMultiPage ID="RadMultiPage6" runat="server" SelectedIndex="0" Width="100%">
<telerik:RadPageView ID="RadPageView5" runat="server" Width="100%">
<%--<telerik:RadAjaxPanel ID="RadAjaxPanel5" runat="server">--%>
<telerik:RadGrid ID="RGGSTAcCode" runat="server" AutoGenerateColumns="false"
ShowFooter="True" GroupingEnabled="False" ShowStatusBar="true"
AllowAutomaticInserts="False" AllowAutomaticUpdates="False" AllowAutomaticDeletes="true"
OnNeedDataSource= "rggstAcCode_NeedDataSource" OnItemDataBound="rggstAcCode_ItemDataBound"
OnInsertCommand="rggstAcCode_InsertCommand" OnDeleteCommand="rggstAcCode_DeleteCommand"
OnUpdateCommand="rggstAcCode_UpdateCommand" EnableEmbeddedSkins="true" Skin="Outlook">
<mastertableview commanditemdisplay="Top" autogeneratecolumns="false" datakeynames="AccountCodeID"
insertitempageindexaction="ShowItemOnCurrentPage" ShowFooter="True" ShowHeadersWhenNoRecords="true">
<CommandItemSettings AddNewRecordText="New" />
<Columns>
<telerik:GridEditCommandColumn UniqueName="imagebutton1" ButtonType="ImageButton"></telerik:GridEditCommandColumn>
<telerik:GridTemplateColumn UniqueName="AccountCode" HeaderText="Account Code">
<ItemTemplate>
<asp:Label ID="lblAcCode" Text='<%# Eval("AccountCode") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblAcCode2" runat="server" Text='<%# Eval("AccountCode") + " - " + Eval("AccountDescription")%>' Visible="false"></asp:Label>
<telerik:RadComboBox ID="ddlAccountCode" runat="server" Height="200" Width="260" DropDownWidth="310"
EnableLoadOnDemand="True" OnItemsRequested="ddlAccountCode_ItemsRequested" EnableItemCaching="true"
ShowMoreResultsBox="True" EnableVirtualScrolling="true" AllowCustomText="true" MarkFirstMatch="true"
Filter="Contains" HighlightTemplatedItems="true" CausesValidation="true" AppendDataBoundItems="true"
DataTextField="AccountDescription" DataValueField="AccountCodeID"
ShowDropDownOnTextboxClick="false"
OnClientDropDownOpening="OnClientDropDownOpening" OnClientItemsRequested="OnClientItemsRequested">
</telerik:RadComboBox>
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click" OnClientClick="ButtonClicked()" UseSubmitBehavior="true" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
//Other columns
</Columns>
<EditFormSettings>
<EditColumn ButtonType="ImageButton" />
</EditFormSettings>
<PagerStyle AlwaysVisible="True" PageSizeControlType="RadComboBox" />
</mastertableview>
</telerik:RadGrid>
<%--</telerik:RadAjaxPanel>--%>
</telerik:RadPageView>
</telerik:RadMultiPage>
C# code:
protected void ddlAccountCode_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
Session["Text"] = e.Text;
Session["NumberOfItems"] = e.NumberOfItems;
RadComboBox combo = (RadComboBox)sender;
combo.ShowDropDownOnTextboxClick = false;
combo.Items.Clear();
combo.HighlightTemplatedItems = true;
}
protected void btnSearch_Click(object sender, EventArgs e)
{
try
{
GridEditableItem editedItem = (sender as Button).NamingContainer as GridEditableItem;
RadComboBox combo = (RadComboBox)editedItem.FindControl("ddlAccountCode");
//clear the previous items on every new search
combo.Items.Clear();
combo.OpenDropDownOnLoad = true; // opens dropdown of RadComboBox on button click
combo.HighlightTemplatedItems = true; // to highlight the searched text
//Code related to search in RadComboBox
combo.DataBind();
}
catch (Exception ex)
{
}
}
Please let me know how to resolve the 2 issues. Please reply.
Thanks in advance.
Sorry i can't replicate your problem in my environment....
Here is my code using
.aspx
<telerik:RadGrid ID="RGGSTAcCode" runat="server" AutoGenerateColumns="false"
ShowFooter="True" GroupingEnabled="False" ShowStatusBar="true"
AllowAutomaticInserts="False" AllowAutomaticUpdates="False" AllowAutomaticDeletes="true"
OnNeedDataSource="rggstAcCode_NeedDataSource">
<MasterTableView CommandItemDisplay="Top" AutoGenerateColumns="false"
InsertItemPageIndexAction="ShowItemOnCurrentPage" ShowFooter="True" ShowHeadersWhenNoRecords="true">
<CommandItemSettings AddNewRecordText="New" />
<Columns>
<telerik:GridEditCommandColumn UniqueName="imagebutton1" ButtonType="ImageButton"></telerik:GridEditCommandColumn>
<telerik:GridTemplateColumn UniqueName="AccountCode" HeaderText="Account Code">
<ItemTemplate>
<asp:Label ID="lblAcCode" runat="server" Text='<%# Eval("AccountCode") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblAcCode2" runat="server" Text='<%# Eval("AccountCode") + " - " + Eval("AccountDescription")%>' Visible="false"></asp:Label>
<telerik:RadComboBox ID="ddlAccountCode" runat="server" Height="200" Width="260" DropDownWidth="310"
EnableItemCaching="true" ShowMoreResultsBox="True" EnableVirtualScrolling="true" AllowCustomText="true"
MarkFirstMatch="true" Filter="Contains" HighlightTemplatedItems="true" CausesValidation="true"
AppendDataBoundItems="true" ShowDropDownOnTextboxClick="false" OnItemsRequested="ddlAccountCode_ItemsRequested">
</telerik:RadComboBox>
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<EditFormSettings>
<EditColumn ButtonType="ImageButton" />
</EditFormSettings>
<PagerStyle AlwaysVisible="True" PageSizeControlType="RadComboBox" />
</MasterTableView>
</telerik:RadGrid>
.cs
protected void Page_Load(object sender, EventArgs e)
{
// Check
if (!IsPostBack)
{
// Variable
DataTable dt = new DataTable();
dt.Columns.Add("AccountCode");
dt.Columns.Add("AccountDescription");
for (int i = 0; i < 10; i++) dt.Rows.Add("AccountCode" + i, "AccountDescription" + i);
ViewState["data"] = dt;
// Bind
RGGSTAcCode.DataSource = dt;
RGGSTAcCode.DataBind();
// Dispose
dt.Dispose();
}
}
protected void rggstAcCode_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
RGGSTAcCode.DataSource = ViewState["data"] as DataTable;
}
protected void ddlAccountCode_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
Session["Text"] = e.Text;
Session["NumberOfItems"] = e.NumberOfItems;
RadComboBox combo = (RadComboBox)sender;
combo.ShowDropDownOnTextboxClick = false;
combo.Items.Clear();
combo.HighlightTemplatedItems = true;
}
protected void btnSearch_Click(object sender, EventArgs e)
{
try
{
GridEditableItem editedItem = (sender as Button).NamingContainer as GridEditableItem;
RadComboBox combo = (RadComboBox)editedItem.FindControl("ddlAccountCode");
//clear the previous items on every new search
combo.Items.Clear();
combo.OpenDropDownOnLoad = true; // opens dropdown of RadComboBox on button click
combo.HighlightTemplatedItems = true; // to highlight the searched text
//Code related to search in RadComboBox
combo.DataSource = ViewState["data"] as DataTable;
combo.DataTextField = "AccountCode";
combo.DataValueField = "AccountCode";
combo.DataBind();
}
catch (Exception ex)
{
}
}
Result as below
I removed the RadAjaxPanel and used the asp.net UpdatePanel and the issue resolved as of now as the page will not post back on button click and above behavior will never happen. But I dont know why it is creating issue when I do not put RadGrid in RadAjaxPanel or UpdatePanel.
Related
I am displaying a grid of data which includes a users name and profile pic etc.
If they haven’t uploaded a profile picture I have set the code below to set imgPic.ImageUrl = "~/files/images/blankProfilePic.png"
However, this works only for the 1st page of 6 pages of data displayed.. As soon as you switch to the 2nd page I get the missing picture icon as the code below is only working for the initial page displayed.
I need to change this code to work on every page as it is only called when the page loads.
VB CODE
Protected Sub Page_LoadComplete(sender As Object, e As System.EventArgs) Handles Me.LoadComplete
Dim acc As New accounts(Membership.GetUser.ProviderUserKey)
If acc.region = "North East" Then
For Each r As GridViewRow in gdvNorthEast.Rows
If r.RowType = DataControlRowType.DataRow Then
Dim imgPic As Image
imgPic = r.Cells(4).FindControl("imgProfilePic")
If imgPic.ImageUrl = "~/catalog/images/"
imgPic.ImageUrl = "~/files/images/blankProfilePic.png"
End If
End If
Next r
End If
ASP.NET
<asp:SqlDataSource
ID="DSLeaderboardNorthEast"
runat="server"
ConnectionString="<%$ ConnectionStrings:DBConnectionString %>"
SelectCommand="SELECT tblAccounts.contactName, tblAccounts.profilePic, tblAccounts.minAge, tblAccounts.maxAge, tblAccounts.AccountID, tblAccounts.region
FROM tblAccounts
WHERE tblAccounts.region='North East'
ORDER BY tblAccounts.contactName ">
</asp:SqlDataSource>
<asp:GridView ID="gdvNorthEast" width="100%" runat="server" AllowPaging="True" AutoGenerateColumns="False" CssClass="mGrid" DataKeyNames="accountID" DataSourceID="DSLeaderboardNorthEast" PageSize="20" AllowSorting="True">
<AlternatingRowStyle CssClass="alt" />
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Image ID="imgProfilePic" AlternateText="Players profile picture" runat="server" width="100px" height="100px" ImageUrl='<%# "~/catalog/images/" & Eval("ProfilePic").ToString %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="contactName" HeaderText="Player Name" />
<asp:BoundField DataField="minAge" HeaderText="Won" />
<asp:BoundField DataField="maxAge" HeaderText="Lost" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:HyperLink ID="hypMessage" runat="server" CssClass="nyroModalMsg" NavigateUrl='<%# "~/sendLeaderboardMessage.aspx?" & "&aID=" & Eval("accountID").ToString %>'>Msg</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Your foreach loop for assigning default image should be reusable method.
Use PageIndexChanged event handler to call the same reusable method.
Update:
Since the above option is not helping, follow this post
//RowDataBound Event
protected void gdvNorthEast_RowDataBound(object sender, GridViewRowEventArgs e)
{
//Checking the RowType of the Row
if(e.Row.RowType==DataControlRowType.DataRow)
{
//your logic goes here without foreach loop
}
}
Use the Gridview_RowDataBound event to make the function of substitution instead use a for instruction
I formed the table shown below picture 1 with GridView but there is a something which I want and I explain that picture 2 (İ didn't use GridView there).
When the data come from database to column of Durum, if it is Aktif, it shows Aktif Button or if it is Pasif, it shows Pasif Button.
How can do this?
You can do pretty much whatever you want assuming you don't use default column binding but rather you define your own.
<asp:GridView ... AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
this is where your template can do
pretty much anything including conditionals
<asp:Button runat="server"
ForeColor="<%# Bind("column")=="value" ? "Red" ? "Blue" %> />
Note that dynamic binding can be applied to any property. You could have two different buttons then and dynamically bind their Visible property so that they are visible or hidden depending on a value of one of dataset columns.
More on dynamic templates in multiple tutorials, e.g.
https://msdn.microsoft.com/en-us/library/bb288032.aspx
Add this TemplateField Code in your GridView:
<asp:TemplateField HeaderText="Durum">
<ItemTemplate>
// Bind your durum column from database in Eval
<asp:Label ID="lblDurum" Visible="false" runat="server" Text='<% #Eval("durum") %>'></asp:Label>
<asp:Button ID="btnAktif" Visible="false" runat="server" Text="Aktif" />
<asp:Button ID="btnPasif" Visible="false" runat="server" Text="Pasif" />
</ItemTemplate>
</asp:TemplateField>
Code Behind
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button Aktif = e.Row.FindControl("btnAktif") as Button;
Button Pasif = e.Row.FindControl("btnPasif") as Button;
string Durum = ((Label)e.Row.FindControl("lblDurum")).Text;
if (Durum=="Aktif")
Aktif.Visible = true;
else
Pasif.Visible = true;
}
}
Note: Don't forget to add OnRowDataBound in GrindView <asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound" >
I have two dropdowns Complaint_Type and Complaint_SubType. Using SqlDataSource I have populated both. SubType dropdown gets correctly populated when I choose the Type dropdown. When I select the values and press submit and check in the database both the type and subtype values are same.
.aspx code
<asp:ScriptManager ID="smDDL" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="upDDL" runat="server">
<ContentTemplate>
<div class="form-group" style="margin-bottom: 25px;">
<asp:Label ID="lblCType" runat="server" Text="Complaint Type" data-toggle="tooltip" title="Select Complaint Type" />
<asp:RequiredFieldValidator ID="RfvDDLCompType" runat="server" ErrorMessage="Please Select Complaint Type" ControlToValidate="ddlCType" ForeColor="Red" InitialValue="0" Display="Dynamic"> *</asp:RequiredFieldValidator>
<asp:DropDownList ID="ddlCType" runat="server" CssClass="form-control" DataSourceID="SqlDataSource1" DataTextField="Comp_Type" DataValueField="Type_ID" AutoPostBack="True" OnDataBound="DDLCTypeDataBound" Style="width: 400px">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ComplaintWebsiteConnectionString %>" SelectCommand="SELECT * FROM [Complaint_Type]"></asp:SqlDataSource>
</div>
<div class="form-group" style="margin-bottom: 25px;">
<asp:Label ID="lblSubType" runat="server" Text="Complaint Sub Type" data-toggle="tooltip" title="Select Complaint Sub Type" />
<asp:RequiredFieldValidator ID="rfvDDlSubType" runat="server" ErrorMessage="Please Select Complaint Sub Type" ControlToValidate="ddlSubType" ForeColor="Red" InitialValue="0" Display="Dynamic"> *</asp:RequiredFieldValidator>
<asp:DropDownList ID="ddlSubType" runat="server" CssClass="form-control" DataSourceID="SqlDataSource2" DataTextField="Comp_SubType" DataValueField="Type_ID" OnDataBound="DDLSubTypeDataBound" Style="width: inherit">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ComplaintWebsiteConnectionString %>" SelectCommand="SELECT * FROM [Complaint_SubType] WHERE ([Type_ID] = #Type_ID2)">
<SelectParameters>
<asp:ControlParameter ControlID="ddlCType" Name="Type_ID2" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</div>
</ContentTemplate>
</asp:UpdatePanel>
.cs code
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DDLCTypeDataBound(object sender, EventArgs e)
{
ddlCType.Items.Insert(0, new ListItem("Select", "0"));
}
protected void DDLSubTypeDataBound(object sender, EventArgs e)
{
ddlSubType.Items.Insert(0, new ListItem("Select", "0"));
}
protected void btn_Reset(object Sender, EventArgs e)
{
}
protected void btnReport_Click(object Sender, EventArgs e)
{
SqlConnection con = new SqlConnection(Utils.Connection);
String query = "insert into CITIZEN_COMPLAINTS(TYPE, SUBTYPE, LOCATION, DESCRIPTION, IMAGE) values (#TYPE, #SUBTYPE, #LOCATION, #DESCRIPTION, #IMAGE)";
SqlCommand cmd = new SqlCommand(query, con);
cmd.Parameters.Add("#TYPE", SqlDbType.Int).Value = ddlCType.SelectedValue;
cmd.Parameters.Add("#SUBTYPE", SqlDbType.Int).Value = ddlSubType.SelectedValue;
cmd.Parameters.Add("#LOCATION", SqlDbType.VarChar).Value = txtLoc.Text;
cmd.Parameters.Add("#DESCRIPTION", SqlDbType.VarChar).Value = txtDesc.Text;
cmd.Parameters.Add("#IMAGE", SqlDbType.VarChar).Value = Utils.file_upload(fuImage);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
//...
}
finally
{
con.Close();
}
}
The reason is because the DataValueField="Type_ID" is same for both drop downs in your markup for these drop downs.
For the second drop down for sub types, you should have something like DataValueField="SubType_ID".
Assuming the primary key column in Complaint_SubType table is SubType_ID, the markup below will solve your problem. Note the DataValueField in these two markups, which should be different.
Type drop down
<asp:DropDownList ID="ddlCType" runat="server" CssClass="form-control"
DataSourceID="SqlDataSource1" DataTextField="Comp_Type" DataValueField="Type_ID"
AutoPostBack="True" OnDataBound="DDLCTypeDataBound" Style="width: 400px">
</asp:DropDownList>
Sub Type drop down
<asp:DropDownList ID="ddlSubType" runat="server" CssClass="form-control"
DataSourceID="SqlDataSource2" DataTextField="Comp_SubType" DataValueField="SubType_ID"
OnDataBound="DDLSubTypeDataBound" Style="width: inherit">
</asp:DropDownList>
I have a RadGrid which has a FilterTemplate using a RadComboBox. When I load the data in RadGrid, I want to show the user filtered data. Here is my column:
<telerik:GridTemplateColumn FilterControlAltText="Filter tclmArrangement column"
HeaderText="Arrangement" UniqueName="tclmArrangement" DefaultInsertValue="-"
DataField="IsDemoAssigned">
<HeaderStyle Width="2%" />
<ItemTemplate>
<asp:Repeater ID="rptchkarrangement" runat="server"
DataSource='<%# IIf(DataBinder.Eval(Container, "DataItem.IsDEmoAssigned") = 0,
DataBinder.Eval(Container, "DataItem.Employees"), Nothing)%> '>
<ItemTemplate>
<table>
<tr class="clsParent">
<input type="checkbox" class="clsEmployee" id="cbSelect"
checked='<%# DataBinder.Eval(Container, "DataItem.IsAssigned")%>'
runat="server" />
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
<FilterTemplate>
<telerik:RadComboBox ID="RadComboBoxAssignmentStatus" Height="80px" Width="80px"
AppendDataBoundItems="true" runat="server"
OnClientSelectedIndexChanged="AssignmentStatusIndexChanged">
</telerik:RadComboBox>
<telerik:RadScriptBlock ID="rsbAssignmentStatus" runat="server">
<script type="text/javascript">
function AssignmentStatusIndexChanged(sender, args) {
var tableView = $find("<%# TryCast(Container,GridItem)
.OwnerTableView.ClientID %>");
var selectedValue = sender.get_value();
if (selectedValue) {
if (parseInt(selectedValue) < 0) {
tableView.filter("tclmArrangement", selectedValue, "NoFilter");
}
else {
tableView.filter("tclmArrangement", selectedValue, "EqualTo");
}
}
}
</script>
</telerik:RadScriptBlock>
</FilterTemplate>
</telerik:GridTemplateColumn>
The filter works fine when the complete data is displayed initially using All option. Filter has values (All, Assigned and UnAssigned). How do I show data in the RadGrid which falls under UnAssigned category?
Not sure is this what you want but I filter through the GridTemplateColumn DataFields. I have removed the repeater.
I hope this help you
.aspx
<telerik:RadGrid ID="rg" runat="server" AutoGenerateColumns="false"
OnNeedDataSource="rg_NeedDataSource" AllowFilteringByColumn="true">
<MasterTableView>
<Columns>
<telerik:GridTemplateColumn DataField="IsAssigned" DefaultInsertValue="-"
UniqueName="tclmArrangement">
<HeaderStyle Width="2%" />
<ItemTemplate>
<asp:CheckBox ID="chk" runat="server"
Checked='<%# Eval("IsAssigned") %>' />
<asp:Label ID="lbl" runat="server" Text='<%# Eval("EmployeeName") %>'>
</asp:Label>
</ItemTemplate>
<FilterTemplate>
<telerik:RadComboBox ID="rcbAssignmentStatus" Height="80px" Width="80px"
runat="server"
OnClientSelectedIndexChanged="AssignmentStatusIndexChanged"
SelectedValue='<%# ((GridItem)Container)
.OwnerTableView
.GetColumn("tclmArrangement").CurrentFilterValue %>'>
<Items>
<telerik:RadComboBoxItem Text="All" Value="" />
<telerik:RadComboBoxItem Text="All Assigned" Value="true" />
<telerik:RadComboBoxItem Text="Unassigned" Value="false" />
</Items>
</telerik:RadComboBox>
<telerik:RadCodeBlock ID="rcb" runat="server">
<script type="text/javascript">
function AssignmentStatusIndexChanged(sender, args) {
var tableView = $find('<%# ((GridItem)Container)
.OwnerTableView.ClientID %>');
var value = sender.get_selectedItem().get_value();
if (value != "")
tableView.filter('tclmArrangement', args.get_item()
.get_value(), 'EqualTo');
else
tableView.filter('tclmArrangement', args.get_item()
.get_value(), 'NoFilter')
}
</script>
</telerik:RadCodeBlock>
</FilterTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
.cs
protected void Page_Load(object sender, EventArgs e)
{
// Check
if (!IsPostBack)
{
// Variable
DataTable dt = new DataTable();
dt.Columns.Add("IsAssigned", typeof(bool));
dt.Columns.Add("EmployeeName", typeof(string));
string[] employeeName = { "Patrick", "Bucky", "Henry", "Jesus", "Linda" };
int[] isAssigned = { 1, 1, 0, 0, 0 };
// Loop
for (int i = 0; i < employeeName.Length; i++)
dt.Rows.Add(isAssigned[i], employeeName[i]);
ViewState["Data"] = dt;
rg.DataSource = dt;
rg.DataBind();
dt.Dispose();
}
}
protected void rg_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
rg.DataSource = ViewState["Data"] as DataTable;
}
This link helped me.
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/functionality/filtering/how-to/apply-default-filter-on-initial-load
One thing which is not specified in the link is to set "EnableLinqExpression=false"
I chose to take "Setting the initial filter in the code-behind" approach. Filter expressions can be formed as follows.
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/functionality/filtering/how-to/operate-with-the-filterexpression-manually
I have a gridview in which I have 100 rows of Textboxes. All textboxes have same id 'TxtEmpcode'. User enters data in some rows of gridview. How do I validate textboxes such that one Employee code is entered only once in textboxes. This is to avoid duplicate entry of data. Suppose a user enters Employee code '1234', this should not allowed in other rows of textboxes. If they enter, a message should appear as 'Employee Code has already been entered'.
Can anyone tell how to achieve this?
<asp:GridView ID="GridView2" runat="server" style="margin-left: 23px; margin-top: 11px;" Width="420px" CellPadding="4" AutoGenerateColumns="False" ForeColor="#333333" GridLines="None" Height="213px" >
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Employee Code">
<ItemTemplate>
<asp:TextBox ID="TxtEmpcode" runat="server" OnTextChanged="TxtId_TextChanged" AutoPostBack ="true" ></asp:TextBox>
</ItemTemplate>
You can use logic of it as per your requirement.
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</head>
<script>
function IsValidTest(Control) {
name = Control.name;
var list = document.getElementById("TxtEmpcode");
var contents = $("[id=TxtEmpcode]");
var TextboxId = name;
var Txtbox = document.getElementsByName(name);
var TextboxValue = Txtbox[0].value;
for (i = 0; i < contents.length; i++)
{
var currenttextboxName=contents[i].name;
var currenttextboxValue=contents[i].value;
//Compare currently changed value with existing values in other textboxes
if (name != currenttextboxName && currenttextboxValue == TextboxValue)
{
alert('Employee Code has already been entered');
Txtbox[0].value = '';
return false;
}
}
return true;
}
</script>
<div>
<asp:GridView ID="GridView2" runat="server" Style="margin-left: 23px; margin-top: 11px;"
Width="420px" CellPadding="4" AutoGenerateColumns="False" ForeColor="#333333"
GridLines="None" Height="213px">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Employee Code">
<ItemTemplate>
<asp:TextBox ID="TxtEmpcode" runat="server" AutoPostBack="true" ClientIDMode="Static" onchange="javascript: return IsValidTest(this);"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</asp:Content>