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")) %>'
Related
I have two dropdown lists in a detailsview one called College and the other is Department. If the user select a college, the department dropdown list should generate all the departments for the selected college.
Here is the detailsview and the dropdown lists:
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="600px" AutoGenerateRows="False" CssClass="table table-bordered mtop" DataKeyNames="ID" DataSourceID="SqlDataSource1" OnDataBound="DetailsView1_DataBound">
<FieldHeaderStyle CssClass="DetailsViewHeader" Width="200px" />
<Fields>
<asp:TemplateField HeaderText="College" SortExpression="Colleges">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource3" DataTextField="ArName" DataValueField="Code"></asp:DropDownList>
<asp:HiddenField ID="HiddenColl" runat="server" value='<%# Eval("Colleges") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label15" runat="server" Text='<%# Bind("Colleges") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Department" SortExpression="ArName">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2" DataTextField="ArName" DataValueField="Code"></asp:DropDownList>
<asp:HiddenField ID="HiddenDep" runat="server" value='<%# Eval("ArName") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label11" runat="server" Text='<%# Bind("ArName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:Button ID="Button1" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
<asp:Button ID="Button2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" />
<asp:Button ID="btnDelete" runat="server" CausesValidation="False" Text="Delete" OnClientClick="return confirm('Do you want to delete ?');" OnClick="btnDelete_Click" />
</ItemTemplate>
<ControlStyle CssClass="btn-login" />
<ItemStyle CssClass="text-center" />
</asp:TemplateField>
</Fields>
</asp:DetailsView>
Here is the SqlDataSources:
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:UEDConnectionStringMarwaMarwa %>" SelectCommand="SELECT [ArName], [Code] FROM [College]"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:UEDConnectionStringMarwaMarwa %>" SelectCommand="SELECT [Code], [ArName] FROM [Department] WHERE ([CollegeCode] = #CollegeCode)">
<SelectParameters>
<asp:ControlParameter ControlID="DetailsView1$DropDownList2" Name="CollegeCode" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
This is the error message:
Could not find control 'DetailsView1$DropDownList2' in
ControlParameter 'CollegeCode'
I did this DetailsView1$DropDownList2 so it can access the dropdown list that is inside the detailsview
What is the problem ?
I am unfamiliar with the DetailsView and not experienced with the SqlDataSource, but I will try to help.
In my experience, I have learned that you shouldn't try to assume a control's ClientID. So, first I would recommend getting the ClientID from the server control.
Using an inline expression, I would try something like this:
<asp:ControlParameter ControlID='<%= DetailsView1.Rows(0).FindControl("DropDownList2").ClientID %>' Name="CollegeCode" PropertyName="SelectedValue" Type="Int32" />
For more about asp.net inline expressions see Introduction to ASP.NET inline expressions in the .NET Framework.
Because I am unfamiliar with the DetailsView control, I don't know if there will be a row at index 0 in the DetailsView when it executes this inline expression (which would throw an exception).
If that code doesn't work, I would suggest dynamically setting the ControlID on the back end that executes after the DetailsView1 rows are bound (such as inside the DetailsView1's DataBound event method).
VB:
If DetailsView1.Rows.Count > 0 Then
Dim objDropDownList2 as Control = DetailsView1.Rows(0).FindControl("DropDownList2")
If objDropDownList2 IsNot Nothing Then
SqlDataSource1.SelectParameters("CollegeCode").ControlID = objDropDownList2.ClientID
End If
End If
C#:
if (DetailsView1.Rows.Count > 0) {
Control objDropDownList2 = DetailsView1.Rows(0).FindControl("DropDownList2");
if (objDropDownList2 != null) {
SqlDataSource1.SelectParameters("CollegeCode").ControlID = objDropDownList2.ClientID;
}
}
I hope this helps!
I am trying to build a simple GridView.
I have a Products table and it contains ProductID and ModelName.
I am using LINQ to SQL
My GridView code is
<asp:GridView ID="GridView1" runat="server" DataSourceID="objData" AutoGenerateColumns="false" AutoGenerateEditButton="true" DataKeyNames="ProductID,ModelName">
<Columns>
<asp:TemplateField HeaderText="Product ID">
<ItemTemplate>
<asp:Label runat="server" Text='<%#Eval("ProductID") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Model Name">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("ModelName") %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" Text='<%#Eval("ModelName") %>'/>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
and my datasource code is
<asp:ObjectDataSource ID="objData" runat="server" SelectMethod="GetAll" UpdateMethod="UpdateProduct"
DataObjectTypeName="TestLINQProto.tblProduct" TypeName="TestLINQProto.ProductsList"></asp:ObjectDataSource>
I have my update method written like this
[DataObjectMethod(DataObjectMethodType.Update,true)]
public void UpdateProduct(tblProduct product)
{
EshopDataAccess.UpdateProduct(product);//This will call a LINQ function to update the product
}
The issue is that the tblProduct that the UpdateProduct contain original values. It is not getting the updated values.
I think the issue is that you are using Eval method which only supports reading/fetching of data. Use Bind Method in your grid aspx code. Like this
<asp:GridView ID="GridView1" runat="server" DataSourceID="objData" AutoGenerateColumns="false" AutoGenerateEditButton="true" DataKeyNames="ProductID,ModelName">
<Columns>
<asp:TemplateField HeaderText="Product ID">
<ItemTemplate>
<asp:Label runat="server" Text='<%#Eval("ProductID") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Model Name">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("ModelName") %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" Text='<%#Bind("ModelName") %>'/>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Data gridview bind the recored with data set.Gird view consist the column "Compnayname"
whenever user click on the column of gridview "Company name" then menu or dropdown control will be display.
so how to add dropdown or menu control in gridview.
I want to data display in grid view control and user click on company name then Menu will be display which contain the information like Send msg, save company detail.
You have to make Template Column
<asp:TemplateField HeaderText="Compnayname">
<ItemTemplate>
<asp:DropDownList ID="ddlCompany" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
here isthe complete GRIDView
<asp:GridView ID="grdList" runat="server" AutoGenerateColumns="False" OnRowCancelingEdit="grdList_RowCancelingEdit" OnRowEditing="grdList_RowEditing" OnRowUpdating="grdList_RowUpdating" OnPageIndexChanging="grdList_PageIndexChanging" AllowPaging="true">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:Label SkinID="OneColLabel" ID="lblName" runat="server" HeaderText="Edit" />
</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="lnbEdit" runat="server" CommandName="Edit" Text="Edit" />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="lnbUpdate" runat="server" CommandName="Update" Text="Update" />
<asp:LinkButton ID="lnbCancel" runat="server" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="drpEditName" runat="server" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
You have to bind Dropdownlist on code behind
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.
I have a gridview like this :
<asp:MultiView ID="MvCustomer" runat="server" ActiveViewIndex="0" >
<%--View 1 to List the customers--%>
<asp:View ID="VwCustomersList" runat="server" >
<asp:GridView ID="GvListCustomer" runat="server" AutoGenerateColumns="False"
HorizontalAlign="Center" DataSourceID="OdsGvCustomers" DataKeyNames="CUSNUM"
EnableModelValidation="True" onrowcommand="GvListCustomer_RowCommand" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="LblCUSNUM" runat="server" Text='<%#Eval("CUSNUM") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="LblCO_NAM" runat="server" Text='<%#Eval("CO_NAM") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="LblCUSCTY" runat="server" Text='<%#Eval("CUSCTY") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<%--<asp:CommandField ButtonType="Button" SelectText="Edit" ShowSelectButton="true" />--%>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="BtnSelect" runat="server" Text="Edit" CommandArgument='<%#Eval("CUSNUM")%>' CommandName="Select" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="BtnDelete" runat="server" Text="Delete" CommandArgument='<%#Eval("CUSNUM")%>' CommandName="Delete" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="OdsGvCustomers" runat="server"
SelectMethod="GetAllCustomers" TypeName="MultiView_EF.BLL.Customers_BLL">
</asp:ObjectDataSource>
</asp:View>
<%--View 2 to show customer details--%>
<asp:View ID="VwCustomerDetail" runat="server" >
<asp:FormView ID="FvCustomerDetails" runat="server" HorizontalAlign="Center"
DataSourceID="OdsFvCustomerDetails" EnableModelValidation="True" DefaultMode="Edit" >
<EditItemTemplate>
CUSNUM:
<asp:TextBox ID="CUSNUMTextBox" runat="server" Text='<%# Bind("CUSNUM") %>' />
<br />
CO_NAM:
<asp:TextBox ID="CO_NAMTextBox" runat="server" Text='<%# Bind("CO_NAM") %>' />
<br />
CUSCTY:
<asp:TextBox ID="CUSCTYTextBox" runat="server" Text='<%# Bind("CUSCTY") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
CUSNUM:
<asp:TextBox ID="CUSNUMTextBox" runat="server" Text='<%# Bind("CUSNUM") %>' />
<br />
CO_NAM:
<asp:TextBox ID="CO_NAMTextBox" runat="server" Text='<%# Bind("CO_NAM") %>' />
<br />
CUSCTY:
<asp:TextBox ID="CUSCTYTextBox" runat="server" Text='<%# Bind("CUSCTY") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<%--<ItemTemplate>
CUSNUM:
<asp:Label ID="CUSNUMLabel" runat="server" Text='<%# Bind("CUSNUM") %>' />
<br />
CO_NAM:
<asp:Label ID="CO_NAMLabel" runat="server" Text='<%# Bind("CO_NAM") %>' />
<br />
CUSCTY:
<asp:Label ID="CUSCTYLabel" runat="server" Text='<%# Bind("CUSCTY") %>' />
<br />
</ItemTemplate>--%>
</asp:FormView>
<asp:ObjectDataSource ID="OdsFvCustomerDetails" runat="server"
SelectMethod="GetCustomerByCusnum" TypeName="MultiView_EF.BLL.Customers_BLL">
<SelectParameters>
<asp:ControlParameter ControlID="GvListCustomer" Name="cusnum"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
</asp:View>
</asp:MultiView>
My idea is that when the user clicks "BtnSelect" I will change the View to the view containing the FormView which has a select method configured to take the SelectedValue of the GridView as an input parameter - it will show the details of the selected customer.
I have done this before "n" number of times but I am not able to get it working this time. The trouble is that when the call for the Select Method of the formview goes to the relevant function - "GetCustomerByCusnum" I have a null value in its parameter "cusnum".
I know that I can write a selecting event and using CommandArgument, parse the value of the selected row and pass it into the Select method as a value but I dont want that solution. I know it works without the "Selecting" method but I cant recall how.
Please help.
By looking at your code, all seems ok, just a single hint, if you are not setting the active view, do it by SetActiveView method of multiview, please do that in button click.
Another thing you can do is: add OdsFvCustomerDetails_Selecting and OdsFvCustomerDetails_Selected events. in Selecting you can see the params and values passed and in Selected you can see e.Exception if there is any error in the query. so it will give you more idea about what exactly is going wrong.
Additional note
Another thing that should be noted is, multivew control works in a way that it binds all the views regardless of whichever is active so it degrades the performance. You may probably find better idea
Yikes. A relic of a question - IIRC I did away with the MV approach for this as we moved list and details section to different aspx pages and used query string parameters. Never got to fix what must have been, in hindsight, some missing parameter assignment.