Using <ItemTemplate> with Checkbox and Label - c#

I want to be able to show the Label next to the manually inserted item "All Profiles", right now it only shows the checkbox at the top but I am not sure how to pass the text to the label.
Thanks

Can you try something like that?
<telerik:radcombobox id="myCombo" emptymessage="All Types" runat="server" width="200px" AppendDataBoundItems="True">
<ItemTemplate>
<div onclick="StopPropagation(event)">
<asp:CheckBox runat="server" ID="chk1" onclick="onCheckBoxClick(this)"/>
<asp:Label runat="server" ID="lblProfile" AssociatedControlID="chk1"><%# Eval("Name") %></asp:Label>
</div>
</ItemTemplate>
<Items>
<telerik:RadComboBoxItem runat="server" Name="Hello"></telerik:RadComboBoxItem>
</Items>
</telerik:radcombobox>

Try databinding again after inserting "All profiles"-item.
If that doesnt work, try something like this:
var values = myDbConnection.GetValues();
var listOfValues = values.Select(x => new ListItem(x.Name, x.Value)).ToList(); // something like that
listOfValues.Add(new ListItem("All Profiles"));
myCombo.DataSource = listOfValues;
myCombo.DataBind();

Telerik recommends to rebind added items in the DataBound event handler like the following
ddlCombobox.Items[0].DataBind()
Check the following links for similar issue on Telerik site
http://www.telerik.com/account/support-tickets/view-ticket.aspx?threadid=327434
http://www.telerik.com/help/aspnet-ajax/combobox-insert-default-item-when-databinding.html

Related

Multiple Parents for ajaxtoolkit:cascadingdropdownlist

I'm trying to set a filter using ajaxtoolkit CascadingDropDown.
The problem is that I need to set a CascadingDropDown using as parent 2 others CascadingDropDown.
My code looks like this:
<asp:DropDownList ID="Parent1" runat="server"/>
<ajaxToolkit:CascadingDropDown ID="CCDParent1" runat="server" TargetControlID="Parent1" ..../>
<asp:DropDownList ID="Parent2" runat="server"/>
<ajaxToolkit:CascadingDropDown ID="CCDParent2" runat="server" ParentControlID="Parent1" TargetControlID="Parent2" ..../>
and this is what I need.
<asp:DropDownList ID="Child" runat="server"/>
<ajaxToolkit:CascadingDropDown ID="CCDChild" runat="server" ParentControlID="Parent1 and Parent2" TargetControlID="Child" ..../>
Is it possible? How?
Thanks

Unable to edit Asp.net DropDownList from code behind

I'm working on an ASP.net Web Forms application (not MVC) and I have a DropDownList wrapped by a TemplateField in a DetailsView like this:
<asp:TemplateField>
<ItemTemplate> </ItemTemplate>
<EditItemTemplate> </EditItemTemplate>
<InsertItemTemplate>
<div class="form-group">
<asp:DropDownList ID="myStatus" runat="server" DataSourceID="DBStatus"
DataTextField="DESC" DataValueField="CODE"
Enabled="false" SelectedValue='<%# Bind("Status") %>'>
</asp:DropDownList>
</div>
</InsertItemTemplate>
</asp:TemplateField>
as you can see at insertion its not enabled (Enabled="false")
for simplicity I wanted to use the insertion items/fields to achieve a search
so I want to enable my DropDownList for that search
I tried using these from code-behind on DetailsView_PreRender and Page_Load but nothing worked:
DropDownList Status = DetailsView1.FindControl("myStatus") as DropDownList;
Status.Enabled = true;
and i also tried
Status.Attributes.Add("enabled", "enabled");
i also debugged it, and these commands are executed but the DropDownList doesn't want to be enabled.
any thoughts ?
thanks.

Access TextBox Control In ListView Control

How to access "TextBox" control inside "ListView" Control ?
For example I want to use this.AddCommentTextbox.Text property in code-behind.
aspx code:
<asp:ListView ID="PostsListView" runat="server" DataSourceID="EntityDataSourcePosts">
<ItemTemplate>
<asp:TextBox Text="active" ID="AddCommentTextbox" runat="server" TextMode="MultiLine" Height="100" Width="370"></asp:TextBox>
</ItemTemplate>
</asp:ListView>
You could try something like this:
TextBox tmpControl = (TextBox)PostsListView.FindControl("AddCommentTextbox");
then you can do something with the tmpControl.text
Hope that helps.

Eval() in a DropDownList within a GridView

How can I do Eval() in a DropDownList that are inside a GridView?
I tried the follow code, but still wrong:
<asp:TemplateField HeaderText="Prioridade">
<ItemTemplate>
<asp:DropDownList ID="ddlPrioridade" runat="server"
SelectedValue='<%# Eval("Prioridade") %>'>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
Try this way
<asp:DropDownList ID="ddlPrioridade" runat="server" AppendDataBoundItems="true" DataSourceID="datasource" DataTextField="key" DataValueField="data" AutoPostBack="True" SelectedValue='<%# Eval("Prioridade") %>'>
also have a look at this DropDownList inside a GridView (or DataGrid). It might help you
You are receiving this error because the drop down list is not loaded with items and asp.net is trying to set the selected value of an empty drop down list and that's why it gives you error. So fill the drop down list first before setting it's selected value.

GridView edit command button with jquery

I want to use the gridview command button (edit) with the jquery not postback. Please help me.
Place an asp button in another item template and set its CommandName property to edit. This will work simillar to default edit button in grid view. Then you can call javascript function and perform your logic.
See the code below:
Remove the following line to avoid default edit button:
<asp:CommandField ShowEditButton="true" ShowCancelButton="true"/>
Add the following instead:
<asp:TemplateField HeaderText="headerName" >
<ItemTemplate>
<asp:Button ID="Button1" CommandName="edit" runat="server" Text="Button" />
</ItemTemplate>
</asp:TemplateField>
Hope this helps you..
I think you can do it in a gridview.What you need is to columns with textbox and display the data in the textbox and needs a button at the end .
<asp:TemplateField >
<HeaderTemplate>
Values
</HeaderTemplate>
<ItemTemplate>
<asp:textbox ID"txt" runat="server" cssclass="abc" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Spares">
<HeaderTemplate>
Edit column
</HeaderTemplate>
<ItemTemplate>
<asp:button id="abc" runat="server" text="save" cssclass="pqr" />
<input type="hidden" runat="server" value="" />
</ItemTemplate>
</asp:TemplateField>
Store the Id in a hidden field and it is possible to get the value of text box and hidden feild via jquery.
gridview will be rendered as html table and using parent() we can able to find the clicked row and after finding the row u can use find() to find the values in the txtbox and hidden feild. Use $ajax() or $post() to send data to server.

Categories

Resources