RadComboBox not displaying bound data - asp.net

I have a RadComboBox like so:
<telerik:RadComboBox ID ="productsDropDown" DataValueField="DisplayName" DataTextField="DisplayName" HighlightTemplatedItems="true"
runat="server" AllowCustomText="true" Height="150px" Width="200px" OnClientDropDownClosed="onDropDownProductClose" AutoPostBack="true">
<ItemTemplate>
<div onclick="StopPropagation(event)">
<asp:CheckBox runat="server" ID="chk2" Checked="false" onclick="onCheckBoxProductClick(this)"/>
<asp:Label runat="server" ID="Label2" AssociatedControlID="chk2">
<%# Eval("DisplayName")%>
</asp:Label>
</div>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnSubmitProduct" runat="server" Text="OK" OnClick="OnSubmitProduct" />
</FooterTemplate>
</telerik:RadComboBox>
but for some reason it won't display any of the data I bind to it like so:
productsDropDown.DataSource = FTSAppLogic.getProducts();
productsDropDown.DataBind();
I have a nearly identical drop down like this:
<telerik:RadComboBox ID ="regionsDropDown" DataValueField="Region" DataTextField="Region" HighlightTemplatedItems="true"
runat="server" AllowCustomText="true" Height="150px" Width="200px" OnClientDropDownClosed="onDropDownRegionClosing" AutoPostBack="true">
<ItemTemplate>
<div onclick="StopPropagation(event)">
<asp:CheckBox runat="server" ID="chk1" Checked="false" onclick="onCheckBoxRegionClick(this)"/>
<asp:Label runat="server" ID="Label1" AssociatedControlID="chk1">
<%# Eval("Region")%>
</asp:Label>
</div>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnSubmitRegion" runat="server" Text="OK" OnClick="OnSubmitRegion" />
</FooterTemplate>
</telerik:RadComboBox>
regionsDropDown.DataSource = FTSAppLogic.getRegions();
regionsDropDown.DataBind();
and it displays everything perfectly (and both of their get functions are nearly identical, returning same layout and same data type)
Also to make matters weirder, I've thrown a debug break in and found that after the data is bound to the productDropDown, the data is in fact bound, it just will not display any of it..
anyone have any ideas why?! I'm at a complete loss!!

I think u have used the label in wrong way in item template:
<asp:Label runat="server" ID="Label1" AssociatedControlID="chk1">
<%# Eval("Region")%>//this is wrong
</asp:Label>
It should be:
<asp:Label runat="server" ID="Label1" AssociatedControlID="chk1"
Text='<%# Eval("Region")%>'</asp:Label>
U need to assign the data column to the text field of label it is asp control(not like HTML label).

Related

Confusion about Retrieve image from database

I am trying to retrieve images to gridview. But My images not displaying .I can get all the data except images. I keep the their paths in the database and I have a folder named Resimler stores images .I have been trying to figure out three hours and i dont understand what is missing or wrong This is my code
<div>
<asp:GridView ID="GvSehirBilgileri" runat="server" AutoGenerateColumns="False"
DataSourceID="sql"
onrowdatabound="GvSehirBilgileri_RowDataBound"
Height="327px" Width="376px">
<Columns>
<asp:TemplateField>
<ItemTemplate>
CityName :<asp:Label ID="lblSehirAdi" runat="server"
Text='<%# Bind("CityName") %>'></asp:Label>
<br />
TaksiPrice :<asp:Label ID="Label2" runat="server"
Text='<%# Bind("TaxiPrice") %>'></asp:Label>
<br />
Resim :
<asp:Image ID="imgpath" runat="server"
ImageUrl='<%#Bind("Path") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="sql" runat="server"
ConnectionString="<%$ ConnectionStrings:SQL %>"
SelectCommand="SELECT * FROM [locCities]"></asp:SqlDataSource>
<asp:Button ID="Button1" runat="server"
onclick="Button1_Click" Text="Button" />
<asp:TextBox ID="txtID" runat="server"></asp:TextBox>
</div>
Set ImageUrl like this:
ImageUrl='<%# string.Format("~/{0}", Eval("Path")) %>'

Changing AccessDataSource to SqlDataSource

I'm trying to change my database from Access to MS SQL and I've got the database ready and everything. I've gone around my website and changed the IDs for each data source to SqlDataSource(number here) and then changed each control that uses the property "DataSourceID" to reflect the name change. However, when I try to open my website, it says it is still looking for AccessDataSource1. Here is some of my code:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:TravelJoansDBSQLConnectionString %>"
SelectCommand="SELECT TOP 8 * FROM [Table2]"></asp:SqlDataSource>
<asp:DataList ID="DataList1" DataSourceID="SqlDataSource1"
runat="server" ItemStyle-CssClass="picTableStyle"
DataKeyField="ID">
<ItemStyle></ItemStyle>
<ItemTemplate>
<br /><br />
<table>
<tr>
<td>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#"~/Places.aspx?ID="+Eval("ID")%>'>
<asp:Image ID="Image1" runat="server" BorderColor="#CCCCCC" BorderWidth="1px" Width="220px" Height="180px" ImageUrl='<%# "PlaceImages/" + Eval("Image") %>' /><br /></asp:HyperLink>
<asp:Label ID="Label1" CssClass="picCaptionStyle" runat="server" Text='<%# Eval("Caption") %>' /></td>
<td>
<asp:HyperLink runat="server" NavigateUrl='<%#"~/Places.aspx?ID="+Eval("ID")%>'>
<asp:Label ID="Label2" class="picTitleStyle" runat="server" Text='<%# Eval("BlogTitle") %>' /><br /></asp:HyperLink>
<asp:Label ID="Label3" class="picBodyText" runat="server" Text='<%# Eval("TravelDate", "{0:MMMMMMMMM dd, yyyy}") %>' /><br /><br />
<asp:Label ID="Label4" class="picBodyText" runat="server" Text='<%# Limit(Eval("PicText"), 400)+"..." %>' />
<asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl='<%#"~/Places.aspx?ID="+Eval("ID")%>' Text="[Read More]" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
Again, when I try to run my website based on this code, I get the error "The DataSourceID of 'DataList1' must be the ID of a control of type IDataSource. A control with ID 'AccessDataSource1' could not be found." Any help would be much appreciated.
Try a clean then rebuild. You can also try a Ctrl+F in all files to see if "AccessDataSource1" is lingering somewhere.

How to insert comma in the value which is present in Hyperlink column in gridview

Here is my markup:
<asp:TemplateField HeaderText="Loss" SortExpression="Loss"
HeaderStyle-CssClass="StrongText" HeaderStyle-Font-Bold="true"
HeaderStyle-Font-Size="Medium" HeaderStyle-ForeColor="Blue"
HeaderStyle-Font-Underline="true" HeaderStyle-VerticalAlign="Bottom"
ItemStyle-Width="3%" ItemStyle-HorizontalAlign="Left"
ItemStyle-VerticalAlign="Bottom" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:HyperLink runat="server" ID="HyperLink8"
NavigateUrl='<%#"db_LossofPay.aspx?UserID="+ Eval("User ID")%>'
Text='<%# Eval("Loss","{0}")%>'
ForeColor="BLUE" Target="_blank"></asp:HyperLink>
<asp:Label ID="lblLoss" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Could you please help me with this? In BoundField I wrote DataFormatString="{0:N2}" which works fine, but I got stuck when using in hyperlink (template field)
Try with this:
<asp:HyperLink runat="server" ID="HyperLink8"
NavigateUrl='<%#"db_LossofPay.aspx?UserID="+ Eval("User ID")%>'
Text='<%# Eval("Loss","{0:#,##0.00}") %>' ForeColor="BLUE" Target="_blank" />
Try
Text='<%# String.Format("{0:N2}", DataBinder.Eval(Container.DataItem, "Loss"))%>'

asp.net binding problem

I have in my code behind the following property
public string Firstname {get;set;}
when I want to bind it to some textbox I do the following:
<asp:TextBox runat="server" ID="txtFirstname" Text='<%# Bind("Firstname") %>'/>
then I want value put in this textbox to be set in my Firstname property (because I want to process it e.g. save this value) in my presenter.
Why it doesn't work?
EDIT
Here is the aspx
<formview runat="server" ID="myFormView">
<p>Firstname <asp:TextBox ID="txtFirstName" runat="server" Text='<%# Eval("Firstname") %>' /></p>
<p>Lastname <asp:TextBox ID="txtLastName" runat="server" /></p>
<input type="button" title="send" runat="server" id="btnSend" />
</formview>
It will bind in the page load but you have to tell it what to bind to in mark up or in code. You didn't say where or how you're storing your data and it sounds like you are trying to insert new data so...
Here is a tutorial on the sqldatasource.
SQL Datasource Tutorial
Here is a turorial on the formview:
Formview Tutorial
Here is a simple one I whipped up...(NOTE: I did not test the below code, so if I forgot somehting my apologies, but it should give you a good start).
<asp:SqlDataSource ID="SqlDataSource1"
runat="server"
ConnectionString="Connection string for your database here."
SelectCommand="SELECT FirstName, LastName FROM YourTable"
>
</asp:SqlDataSource>
<asp:FormView ID="frmYourForm" DefaultMode="Insert" runat="server" DataSourceID="SqlDataSource1">
<EditItemTemplate>
<asp:TextBox ID="txtFirstName" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox>
<br />
<asp:TextBox ID="txtLastName" runat="server" Text='<%# Bind("LastName") %>'></asp:TextBox>
<asp:LinkButton ID="LinkButton1" CommandName="Update" runat="server">Update</asp:LinkButton>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="txtFirstName" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox>
<br />
<asp:TextBox ID="txtLastName" runat="server" Text='<%# Bind("LastName") %>'></asp:TextBox>
<asp:LinkButton ID="LinkButton1" CommandName="Insert" runat="server">Insert</asp:LinkButton>
</InsertItemTemplate>
</asp:FormView>
EDIT: Fixed the links to the tutorials...I didn't realize the orginal link didn't show info on the formview.

Merge datagrid cells

i have to merge the cells from the cell that does not contain the radio button, to the cell that contains the radio button.
here the link for the interface
http://i839.photobucket.com/albums/zz316/girish_kolte/untitled.jpg
You need to use the TemplateField and here is a tutorial that explains some of the other fields that GridView offers as well.
<asp:GridView ID="gvwAirportSchedule" runat="server">
<Columns>
....
<asp:TemplateField>
<ItemTemplate HeaderText="Airport">
<asp:RadioButton ID="rbAirport" runat="server" Visible='<%# (bool)Eval("IsDestination") %>' />
<asp:Label runat="server" ID="Label1" Text='<%# Eval("Airport") %>' />
</ItemTemplate>
</asp:TemplateField>
....
</Columns>
</asp:GridView>
good answer from David.
One could reduce, by omitting Lable like below
<asp:RadioButton ID="RadioButton1" runat="server" Text='<%# Eval("Airport") %>' />

Resources