Click here to Skip to main content
15,886,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi , i have an gridview which has filled from my sql server data base .
note : i bind my database in asp.net side and not in C# ( code behind )

i have 2 tables i.e
1: company table
2: image table

at image table each img has an unique id and at companytable each field has one img_ref field which reffer to its specific image at image Table .

i filled my gridview using a left join from my both tables .

my method for opening images is to call an .aspx file ant my image open like below :

www.MyWeb.com/readAttachment.aspx?Code=aaaaa&ID=1

The readAttachment.aspx file is in my root and my gridview is in my /company/add directory .

now i want to open my images using my Code and ID from my Company Table .

my asp.net code is :

ASP.NET
<pre lang="xml"><asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ChiCarDariConnectionString1 %>" ProviderName="<%$ ConnectionStrings:ChiCarDariConnectionString1.ProviderName %>" SelectCommand="select Company.Fld_id as Fld_id,Company.Fld_Uploader as Fld_Uploader,Company.Fld_Name as Fld_Name,Company.Fld_Date as Fld_Date,Img.Fld_RandCode as Fld_RandCode from tbl_Company as Company left join tbl_Img as Img on Company.Fld_ImgRef = img.Fld_id"></asp:SqlDataSource>
<asp:GridView CssClass="GridComapny" ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource2" EmptyDataText="There are no data records to display." BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical">
<AlternatingRowStyle BackColor="#CCCCCC" />
<RowStyle Height="100px" />

<Columns>
    <asp:TemplateField>
        <ItemTemplate>
            <asp:Image ID="Image1" ImageUrl="../../ReadAttachment.aspx?code={???}&id={???}" runat="server" />
        </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="#" ItemStyle-CssClass="Company_Grid_Checkbox">
    <ItemTemplate>
        <asp:CheckBox ID="chkRow" runat="server" />
    </ItemTemplate>
    <HeaderStyle Width="10%" />
    </asp:TemplateField>
    <asp:BoundField DataField="Fld_id" HeaderText="شماره" ReadOnly="True" SortExpression="Fld_id" />
    <asp:HyperLinkField HeaderText="آپلود کننده" DataNavigateUrlFields="Fld_RandCode,Fld_id" DataTextField="Fld_Uploader" DataNavigateUrlFormatString="Company_Add.aspx?Code={0}&id={1}" />
    <asp:HyperLinkField HeaderText="تاریخ آپلود" DataNavigateUrlFields="Fld_RandCode,Fld_id" DataTextField="Fld_Date" DataNavigateUrlFormatString="Company_Add.aspx?Code={0}&id={1}" />
    <asp:
ImageField DataImageUrlField="" HeaderText="تصویر" SortExpression="Fld_path" />
<asp:HyperLinkField HeaderText="نام" DataNavigateUrlFields="Fld_RandCode,Fld_id" DataTextField="Fld_Name" DataNavigateUrlFormatString="Company_Add.aspx?Code={0}&id={1}" />

</Columns>



I know its a bit complicated but i have been working on it about 1 week and still didnt get my appropriate result :(


Thank you all .
Posted
Updated 13-Oct-14 9:38am
v3
Comments
ZurdoDev 13-Oct-14 14:47pm    
So, where exactly are you stuck?
Member 11125813 14-Oct-14 3:05am    
I edited my post and the bold part is what i dont know what to do ...
Not clear. Please explain the requirement and problem clearly.
Member 11125813 14-Oct-14 3:05am    
I edited my post and the bold part is what i dont know what to do ...
Member 11125813 13-Oct-14 15:38pm    
I edited my post and the bold part is what i dont know what to do ...

1 solution

Try something like this:
ASP.NET
<ItemTemplate>
    <asp:Image ID="Image1" runat="server" 
        ImageUrl='<%# string.Format("~/ReadAttachment.aspx?code={0}&id={1}", Eval("Code"), Eval("ID")) %>'
    />
</ItemTemplate>

You'll need to replace the fields names "Code" and "ID" in the two Eval(...) calls with the real names of the fields in your data source.
 
Share this answer
 
Comments
Member 11125813 13-Oct-14 17:03pm    
I got this error :
Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

note : my field in database is not code , its Fld_Code but my querystring name is code .
Richard Deeming 14-Oct-14 7:14am    
What code did you put inside the <%# ... %> tags? That error suggests you didn't copy the code I posted.

As I mentioned in the solution, you need to replace the "Code" and "ID" field names in the two Eval(...) calls with the real field names.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900