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.
Related
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")) %>'
<asp:Repeater ID="RptrSearchedPhotographer" runat="server"
onitemcommand="RptrSearchedPhotographer_ItemCommand"
onitemdatabound="RptrSearchedPhotographer_ItemDataBound">
<ItemTemplate>
<tr>
<td>
<asp:Label ID="LblContactInfo" runat="server" Text='<%# Eval("ContactInfo")%>'/>
<asp:TextBox ID="TxtContactInfo" runat="server" Text='<%#Eval("ContactInfo") %>' Visible="false" ></asp:TextBox>
</td>
<td>
<asp:LinkButton ID="LnkDelete" runat="server" CommandArgument='<%#Eval("Id") %>' CommandName="delete">Delete</asp:LinkButton>
<asp:LinkButton ID="lnkEdit" runat="server" CommandArgument='<%#Eval("Id") %>' CommandName="edit" EnableViewState ="true">Edit</asp:LinkButton>
<asp:LinkButton ID="lnkUpdate" runat="server" CommandArgument='<%#Eval("Id") %>' CommandName="update" Visible="false" EnableViewState="true">Update</asp:LinkButton>
<asp:LinkButton ID="LinkCancel" runat="server" CommandName="cancel" Visible="false">cancel</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
my .cs code is...
if (e.CommandName.Equals("update"))
{
TextBox DetailNote = (TextBox)e.Item.FindControl("txtDetailNote");
string s = DetailNote.Text;
}
But here... It gives the me old value of s from textbox. I want new value which is inserted during run time... I googled a lot... but it doesn't work...
I had this issue, I solved it by adding an "if(!Page.IsPostBack)" before databinding my repeater in the page_load function.
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).
I need my own posts and comment on the page in my project, something similar to Facebook. I succesfully created posts by using sql table, sqldatasource and repeater. But I have a problem with comments.
I created sql table Comments, there is a column with Post ID. This is my code:
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:MotWebConnectionString %>"
SelectCommand="SELECT * FROM [Posts]
JOIN [Users] ON [Users].[UserName] = [Posts].[UserName]
JOIN [Comments] ON [Comments].[PostId] = [Posts].[PostId]
WHERE ([GroupId] = #GroupId) ">
<SelectParameters>
<asp:QueryStringParameter Name="GroupId" QueryStringField="id" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource3" >
<ItemTemplate>
<table style="width: 100%;">
<tr>
<td width="10%">
<asp:Image ID="Image2" runat="server" Width="64px" Height="64px" ImageUrl='<%# Eval("ProfilePicture")%>' />
</td>
<td align="left" width="90%" >
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("UserName", "~/_/Profile.aspx?Username={0}")%>'><p><asp:Literal ID="Literal2" runat="server" Text='<%# Eval("Username")%>'></asp:Literal></p></asp:HyperLink>
</td>
</tr>
</table>
<asp:Literal ID="Literal3" runat="server" Text='<%# Eval("Text")%>'></asp:Literal>
<br />
<asp:Literal ID="Literal4" runat="server" Text='<%# Eval("CommentText")%>'></asp:Literal>
<asp:FormView ID="FormView2" runat="server" DataSourceID="SqlDataSource4" DefaultMode="Insert" >
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" CommandName="Insert" />
</InsertItemTemplate>
</asp:FormView>
</ItemTemplate>
<SeparatorTemplate>
<br />
<br />
<br />
</SeparatorTemplate>
</asp:Repeater>
But it shows only posts, where is at least 1 comment and if there are more comments than 1, the posts is twice or more times on the page.
And another problem is, that I don't know how to insert right Post ID into the Comments table. It is probably by using Parameter...
My database schema (I did't know how to create it in SQL Management Studio, so it is in VS):
http://img685.imageshack.us/img685/1416/vstiekd.jpg
Please could anyone help me with this:
How to view right comments under the post and view also posts without any comment
How to insert the comment with right Post ID
I will be very thankfull for any kind of help
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.