ASP.NET Grid View row with style never defined - c#

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>

Related

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

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

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

How to add a default text to appear in all the rows of one specific Gridview column

I have added a Gridview, and I have connected it to a Database. I save an integer as the primary key. When retrieving the primary key I want to add a default text to the front of it. I was hoping if there is any way in which I can set the particular set of cells in the Gridview to have the text I want as default.
This is how it appears :
I want it to appear as follows :
Here's my code :
<table style="width:100%">
<tr>
<td>
</td>
</tr>
<tr>
<td align="center">
<div style="overflow:auto; height: 175px; width: 900px;">
<asp:GridView ID="grdNDA" runat="server" ShowHeaderWhenEmpty="true" EmptyDataText="No Records Found" AutoGenerateColumns="False" AutoGenerateSelectButton="True" CellPadding="4" ForeColor="#333333" GridLines="None" Font-Size="Small" Width="95%">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField HeaderText="NDA ID" DataField="NDA_ID" />
<asp:BoundField HeaderText="Company Name" DataField="COMPANY_NAME" />
<asp:BoundField HeaderText="Country Incorperated" DataField="COUNTRY" />
<asp:BoundField HeaderText="Date Created" DataField="DATE_CREATED" />
</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>
</div>
</td>
</tr>
</table>
Please help. Thanks in advance.
Use DataFormatString property like:
<asp:BoundField HeaderText="NDA ID" DataField="NDA_ID" DataFormatString="SL/NDA/{0}" />
For more complex scenarios consider using TemplateField instead of DataBound
<asp:TemplateField HeaderText="NDA ID" SortExpression="NDA_ID">
<ItemTemplate>
SL/NDA/<asp:Literal runat="server" Mode="Encode" Text='<%# Eval("NDA_ID") %>' />
</ItemTemplate>
</asp:TemplateField>

How to make any column hyperlinked in dynamic gridview , where that hyperlink column is linked to another gridview

How to make any column hyperlinked (except first one) in dynamic gridview , where that hyperlink column is linked to another gridview.
This dynamic table shows two type of output as mentioned below:
View 1:
Start Bus_no Change_at Change_Bus_no Destination Means
Desu Office 715 Hanuman Mandir 781 Subroto Park DTC
Desu Office 715 Palam Airport 764 Subroto Park DTC
Desu Office 715 Palam Airport 781 Subroto Park DTC
View 2:
Start bus_no Destination Means
Subroto Park 764 Nehru Place Terminal DTC
In first view I want to make column 2nd (Bus_no) and 4th(Changed_Bus_no) and in second view I want to make column 2nd as hyperlink column which will be linked to another grid view table.
Gridview Code is given below:
<asp:GridView ID="GridView1" runat="server" BackColor="White"
BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4"
GridLines="Vertical" ForeColor="Black">
<AlternatingRowStyle BackColor="White" />
<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>
please help. Thanx in advance.
You can use Template Field for your requirement.
Try like this,
<asp:GridView ID="GridView1" runat="server" BackColor="White"
BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4"
GridLines="Vertical" ForeColor="Black">
<AlternatingRowStyle BackColor="White" />
<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" />
<Columns>
<asp:TemplateField HeaderText="First Column">
<ItemTemplate>
<asp:Label ID="lblthird0" runat="server" Text="items" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Second Column">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="#Gridview2"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
You can do like this for all your columns.

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;
}
}

Categories

Resources