How to display the image with pop up in asp.net? - c#

I want to display the pop up when click the link button from the grid view in asp.net. In the database I store the image with the byte type. I write the code in HTML for
<asp:GridView ID="dgvImage" DataKeyNames="File_ID" runat="server"
AutoGenerateColumns="False" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None"
BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="File_ID" HeaderText="ID"/>
<asp:BoundField DataField="File_Name" HeaderText="Name" />
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:LinkButton ID="lnkView" runat="Server" Text="View" CommandName="View"
OnClick="View_Click"></asp:LinkButton>
</span>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<span onclick="return confirm('Are you sure to Delete the record?')">
<asp:LinkButton ID="lnkdelete" runat="server"
OnClick="lnkdelete_Click">Delete</asp:LinkButton>
</span>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCC99" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#F7F7DE" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FBFBF2" />
<SortedAscendingHeaderStyle BackColor="#848384" />
<SortedDescendingCellStyle BackColor="#EAEAD3" />
<SortedDescendingHeaderStyle BackColor="#575357" />
</asp:GridView>
When I click the view buttton the page is load but the image is not displayed and then none of the error is occur.

To display image in popup : on the pop up, pass the record id from the parent page as query string and get this id on popup page, convert the Byte to Image and display it in Image tag

Related

pass querystring value of linkbnbutton placed in gridview to iframe source

I need to pass the querystring value, of linkbutton to iframe source here is the Code
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333"
Width="100%" AutoGenerateColumns="False" ShowHeaderWhenEmpty="True" DataKeyNames="ItemCode">
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
<Columns>
<asp:BoundField DataField="State" HeaderText="State"/>
<asp:BoundField DataField="City" HeaderText="City"/>
<asp:BoundField DataField="LandlineNo1" HeaderText="Contact"/>
<asp:BoundField DataField="Item_name" HeaderText="Name"/>
<asp:BoundField DataField="Qty" HeaderText="qty"/>
<asp:BoundField DataField="rate" HeaderText="Amount"/>
<asp:BoundField DataField="DeliveryDate" HeaderText="Deliverydate"/>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkDetails" runat="server" Text="Release" PostBackUrl='<%# "~/popup.aspx?RowIndex=" + Container.DataItemIndex %>'></asp:LinkButton>
<cc1:modalpopupextender ID="mp1" runat="server" PopupControlID="Panl1" TargetControlID="lnkDetails"
CancelControlID="Button2" BackgroundCssClass="Background">
</cc1:modalpopupextender>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Panel ID="Panl1" runat="server" CssClass="Popup" align="center" style = "display:none">
<iframe style=" width: 600px; height: 400px;" id="irm1" src="popup.aspx?id=<% =request.Querystring(" id=")%>" runat="server"></iframe>
<br/>
<asp:Button ID="Button2" runat="server" Text="Close" />
</asp:Panel>
how to pass the value of querystring to popup.aspx page for now its
going null

datagrid it is not showing in TabContainer

I have a ajaxtoolkit:TabContainer in my code. I put gridview inside it. but it is not showing the grid view when I run the project. gridview is fine and is showing data when it is not inside the TabContainer.
This is my aspx code:
<ajaxToolkit:TabPanel ID="tbAgency" runat="server" HeaderText="Agency" >
<ContentTemplate>
<asp:GridView ID="grAgency" runat="server" CellPadding="4"
ForeColor="#333333" GridLines="None" AutoGenerateColumns="False"
Width="901px" style="cursor: pointer;" AllowPaging="True"
AllowSorting="True" PageSize="20">
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="green" Font-Bold="True" ForeColor="White"
Font-Size="Small" HorizontalAlign="Left" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#c9d9c9" Font-Size="Small" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
<Columns>
<asp:BoundField HeaderText="Agency Name" DataField="Name"
ItemStyle-Wrap="true" ItemStyle-HorizontalAlign="Center">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" Wrap="True"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="Description" DataField="Description"
ItemStyle-Wrap="true" ItemStyle-HorizontalAlign="Center">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" Wrap="True"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="Contact Name" DataField="ContactName"
ItemStyle-Wrap="true" ItemStyle-HorizontalAlign="Center">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" Wrap="True"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="Contact Phone" DataField="Phone"
ItemStyle-Wrap="true" ItemStyle-HorizontalAlign="Center">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" Wrap="True"></ItemStyle>
</asp:BoundField>
</Columns>
</asp:GridView>
<asp:Button ID="btnAddAgency" Text="Add Agency" runat="server" />
<asp:TextBox ID="txtAgencySearch" runat="server" />
<asp:Button ID="btnSearchAgency" runat="server" Text="Search" />
</ContentTemplate>
</ajaxToolkit:TabPanel>
and this is my C# code that when the dropdown changes, it shows data in grid.(but grid is only visible when it is outside of the Tab, when I put in inside the Tab in disappears.
protected void ddlPartnerList_SelectedIndexChanged(object sender, EventArgs e)
{
Aid = Convert.ToInt32(ddlPartnerList.SelectedItem.Value);
if (Aid != 0)
{
Session["Aid"] = Aid;
TabContainer1.ActiveTabIndex = 0;
var AgencyList = adminmv.getAgency(Aid);
grAgency.DataSource = AgencyList;
grAgency.DataBind();
}
}
Put the GridView inside a ContentTemplate inside an UpdatePanel inside the ContentTemplate of the TabPanel and make sure you have a ToolkitScriptManager control on the page.
<tabPanel>
<contentTemplate>
<updatePanel>
<contentTemplate>
<gridview>

Identify the Access Key of a particular record in Gridview ,(For a button / TemplateField)

I am trying to have a gridview with dynamic data imported using a SqlDataSource , plus 2 TemplateFields containing 2 buttons as Accept and Decline.What I need to do is , update a specific column of the table where the records are coming from.(Change the value from Null to 1 or 0, in the column called "accepted")
Q.)I need a way to identify the row which the button will be clicked ?
(need to identify the value of access key for the particular row)
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="request_no" DataSourceID="SqlDataSource1" Font-Names="Tahoma" Font-Size="Small" ForeColor="#333333" GridLines="None" OnSelectedIndexChanged="GridView1_SelectedIndexChanged1" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="request_no" HeaderText="request_no" ReadOnly="True" SortExpression="request_no" />
<asp:BoundField DataField="employee_name" HeaderText="employee_name" SortExpression="employee_name" />
<asp:BoundField DataField="requested_date" HeaderText="requested_date" SortExpression="requested_date" />
<asp:BoundField DataField="requested_time" HeaderText="requested_time" SortExpression="requested_time" />
<asp:BoundField DataField="requested_from" HeaderText="requested_from" SortExpression="requested_from" />
<asp:BoundField DataField="requested_to" HeaderText="requested_to" SortExpression="requested_to" />
<asp:BoundField DataField="service_type" HeaderText="service_type" SortExpression="service_type" />
<asp:BoundField DataField="reason_data" HeaderText="reason_data" SortExpression="reason_data" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="AcceptRequest" runat="server" OnClick="AcceptRequest_Click" Text="Accept" CommandName="AcceptRequestcmd" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="DeclineRequest" runat="server" OnClick="DeclineRequest_Click" Text="Decline" CommandName="DeclineRequestcmd" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
You are very close, just lack CommandArgument:
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="AcceptRequest" runat="server"
OnClick="AcceptRequest_Click" Text="Accept"
CommandName="AcceptRequestcmd"
CommandArgument="<%# Eval("request_no") %> />
</ItemTemplate>
</asp:TemplateField>
(assuming that request_no is the row identifier)
Then just
protected void GridView1_RowCommand(...)
{
switch ( e.CommandName )
{
case "AcceptRequestcmd" :
string rowid = e.CommandArgument;
}
}

ASP.NET Grid View row with style never defined

I have a strange problem.
I created a GridView that is bounded to an ObjectDataSource.
The strange thing I have now, that all Grid Rows have the style "background-color: White".
But I never declared this and I can't find any place in my project where it is designed. Neither inline the .aspx nor any css or in any code behind. Simply this style definition doesn't exist in my project.
The information I add to the GridView directly are overwritten by the style definition. Here's what Firebug gets:
<div>
<table id="MainContent_UserGrid" cellspacing="0" cellpadding="4" style="width:100%;border-collapse:collapse;">
<tbody>
<tr style="color:White;background-color:#5D7B9D;font-weight:bold;">
<tr style="color:#333333;background-color:White;">
<td>
<td>name.ofme#mydomain.com</td>
<td>Name of me</td>
<td>Y</td>
<td>
</tr>
<tr style="color:#284775;background-color:White;">
<tr style="color:#333333;background-color:White;">
<tr style="color:#284775;background-color:White;">
<tr style="color:#333333;background-color:White;">
</tbody>
</table>
</div>
Here's my ASPX code of the Grid:
<asp:GridView ID="UserGrid"
runat="server"
AutoGenerateColumns="False"
DataKeyNames="AD_ID"
DataSourceID="UserByAdminAdapter" CellPadding="4"
GridLines="None" Width="100%" AllowPaging="True">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
ShowSelectButton="True" />
<asp:BoundField DataField="AD_ID" HeaderText="AD_ID" ReadOnly="True"
SortExpression="AD_ID"></asp:BoundField>
<asp:BoundField DataField="NAME" HeaderText="NAME" SortExpression="NAME"
ReadOnly="True">
</asp:BoundField>
<asp:BoundField DataField="ACCOUNT_TYPE" HeaderText="ACCOUNT_TYPE"
SortExpression="ACCOUNT_TYPE" Visible="False" ReadOnly="True"></asp:BoundField>
<asp:BoundField DataField="ADMIN_ID" HeaderText="ADMIN_ID"
SortExpression="ADMIN_ID" Visible="False" ReadOnly="True"></asp:BoundField>
<asp:BoundField DataField="BOOKINGS_CONSISTENT" HeaderText="BOOKINGS_CONSISTENT"
SortExpression="BOOKINGS_CONSISTENT" ReadOnly="True"></asp:BoundField>
<asp:BoundField DataField="COMPANY" HeaderText="COMPANY"
SortExpression="COMPANY" Visible="False" />
<asp:TemplateField HeaderText="COMPANY_NAME" SortExpression="COMPANY_NAME">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="Companies"
DataTextField="NAME" DataValueField="ROW_ID"
SelectedValue='<%# Bind("COMPANY") %>'>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("COMPANY_NAME") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#000000" ForeColor="#333333" />
<AlternatingRowStyle BackColor="#99FFCC" ForeColor="#284775" />
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<sortedascendingcellstyle backcolor="#E9E7E2" />
<sortedascendingheaderstyle backcolor="#506C8C" />
<sorteddescendingcellstyle backcolor="#FFFDF8" />
<sorteddescendingheaderstyle backcolor="#6F8DAE" />
</asp:GridView>
By the way, changing the background color of a row in the c# code doesn't change anything, also.
I have a workaround through css but that's not "nice".
Thank you right now!
Do you have a theme somewhere in your project that could be overwriting your grid styles?
Could you be modifying the style somewhere in your code behind (I doubt it).
Instead of putting specific styles in your gridview footerStyle, why not make a class in your css and link to that so
<RowStyle BackColor="#000000" ForeColor="#333333" />
becomes
<RowStyle CssClass="ItemStyle" />
It might make it easier to trouble shoot in Firebug and reduce the amount of inline styles (and be more maintainable at the same time).
It's auto styling. You can creat CSS Classes for your GridView and apply them to the following attributes:
<HeaderStyle CssClass="tableHead" />
<RowStyle CssClass="tableRow" />
<PagerStyle CssClass="pager" />
//Example
<asp:GridView runat="server" ID="grdAssetSearchResults" AutoGenerateColumns="false" GridLines="Both" AllowSorting="true" UseAccessibleHeader="true" >
<HeaderStyle CssClass="tableHead" />
<RowStyle CssClass="tableRow" />
<PagerStyle CssClass="pager" />
<Columns>
//Columns
</Columns>
</asp:GridView>

How I can display Image on mouseover event on asp:linkButton

I am using asp.net framework 3.5 and c# 2.0. I am able to bind data in to gridview.
Actually I want to display Image on mouseover event on asp:linkButton, which is used in grid view
<asp:GridView ID="gvTemplate" runat="server" AllowPaging="True" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="None" ShowFooter="True" Width="100%"
OnRowCommand="gvTemplate_RowCommand" OnRowDataBound="RowDataBound" OnPageIndexChanging="gvTemplate_PageIndexChanging">
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:TemplateField HeaderStyle-HorizontalAlign="Left" HeaderText="Sr. No">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Template Name" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:LinkButton ID="lBtTempID" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"tempName") %>'
CommandName='<%# DataBinder.Eval(Container.DataItem,"tempID") %>' CommandArgument="tempID" onmouseover="javascript:showImage(this.id)"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-HorizontalAlign="Left" HeaderText="Template Type">
<ItemTemplate>
<asp:Label ID="lbltempType" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"tempType") %>' />
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
If you can use jquery it would be like this
$('.lBtTempClass').mouseover(function() {
/// Do your code
});
you should add a css class to link button
<asp:LinkButton ID="lBtTempID" CssClass="lBtTempClass" runat="server" >

Categories

Resources