Freeze Title Header in gridview asp.net c# - c#

I have a Title in my webpage, some texts,a textbox and a button. I have a large gridview that needs to be scrolled vertically and horizontally. What i want is, Even if I scroll the gridview, the Title in my webpage, some texts,a textbox and a button will still be in the same position or freeze.
here is my html code
<div>
Data Warehouse Calendar Maintenance
<br />
<br />
</div>
<p>
<asp:Label ID="Label1" runat="server" Text="Enter Date:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button ID="btn_View" runat="server" onclick="btn_View_Click" Text="View" />
</p>
<p>
<asp:GridView ID="GridView1" runat="server" BackColor="LightGoldenrodYellow"
BorderColor="Tan" BorderWidth="1px" CellPadding="5" Font-Names="Calibri"
Font-Size="Medium" Font-Underline="False" ForeColor="Black"
onrowdatabound="GridView1_RowDataBound"
onselectedindexchanged="GridView1_SelectedIndexChanged" Width="271px">
<RowStyle Wrap="False" />
<EmptyDataRowStyle Wrap="False" />
<FooterStyle BackColor="Tan" BorderColor="Black" BorderStyle="Solid"
Wrap="False" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"
HorizontalAlign="Center" Wrap="False" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite"
Wrap="False"/>
<HeaderStyle BackColor="Tan" BorderStyle="Solid" Font-Bold="True"
Wrap="False" />
<EditRowStyle Wrap="False" />
<AlternatingRowStyle BackColor="PaleGoldenrod" Wrap="False" />
</asp:GridView>
</p>

Yes, You can do it very easily by using css. css has the property for postion. So set your postion fixed like this.
.Title
{
Position:Fixed;
Top:120px; // Set as per your requirement
Left:120px; // Set as per your requirement
}
apply title class to that Title div.
Same can be written for texts, Textbox and for button.

Refer this sample http://www.aspsnippets.com/Articles/Scrollable-GridView-with-Fixed-Headers-in-ASP.Net.aspx
It will be useful to your problem.

Related

avoid reload gridview c# after clicking on a button

I created a web page Default6.aspx containing a gridview.
This gridview contains w column "radio button" (just one radio button can be selected)
I have a button that when I click,the Id of the row checked will be shown.
The problem that after click on the button,the checked radio button becomes unchecked and the gridview loads new data.
I couldn't really understand why.
Note: I have the same code in another Default5.aspx and it works.
this is the code of gridview:
<div style ="height:250px; width:1092px; overflow:auto;" spellcheck="True">
<asp:GridView ID="GridView2" runat="server"
BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" CellSpacing="4" GridLines="Vertical" Height="160px"
OnSelectedIndexChanged="GridView2_SelectedIndexChanged" Width="271px" ForeColor="Black"
ShowHeaderWhenEmpty="True" AutoPostBack="false">
<AlternatingRowStyle BackColor="White" />
<Columns >
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:CheckBox ID="chkDelete" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Main" >
<ItemTemplate>
<asp:RadioButton ID ="radioButton1" HeaderText="Main" runat="server"
onclick = "RadioCheck(this);" AutoPostBack ="False" Checked="False" CausesValidation="True" />
<asp:HiddenField ID="HiddenField1" runat="server" Value = '<%#Eval("id")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ID" Visible="false">
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text='<%# Eval("id") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCC99" />
<HeaderStyle BackColor="#80FF00" Font-Bold="True" ForeColor="Black" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#CCCCCC" BorderStyle="Solid" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FBFBF2" />
<SortedAscendingHeaderStyle BackColor="#848384" />
<SortedDescendingCellStyle BackColor="#EAEAD3" />
<SortedDescendingHeaderStyle BackColor="#575357" />
</asp:GridView>
</div>
and this is the code of the button:
<asp:Button ID="Button1" runat="server" BackColor="#80FF00" Font-Size="Large" OnClick="Button1_Click" Text="Delete unselected rows" Width="200px" />
for the test I created another button that just shows me a message "hello" when I click on it..and when I did (even I don't check a radio button),the gridview became refreshed..
what can be that?
thank you
Consider wrapping your button and the label in an updatepanel control, which uses AJAX to refresh their contents. The rest of the page will not be reloaded and the action will not affect the browser navigation.
the answer is:
if (!IsPostBack)
{ //my code}
else
{ //nothing to do}

Link Button to Gridview

I have a following GridView and my source code look like this:
<%# Control Language="C#" AutoEventWireup="true" CodeFile="ShopData.ascx.cs" Inherits="usercontrols.UsercontrolsShopData" %>
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Export to csv</asp:LinkButton>
<br /> <br />
<asp:GridView ID="gridviewShopData" runat="server" DataSourceID="SqlDataSource1" CellPadding="4" BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px">
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="#330099" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<SortedAscendingCellStyle BackColor="#FEFCEB" />
<SortedAscendingHeaderStyle BackColor="#AF0101" />
<SortedDescendingCellStyle BackColor="#F6F0C0" />
<SortedDescendingHeaderStyle BackColor="#7E0000" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="SELECT firstName as 'First Name',lastName as 'Last Name',employeeNumber as 'Employee Number',productID as 'Product Number' FROM ShopOrder where shopID=#pageid">
<SelectParameters><asp:QueryStringParameter Name="pageid" QueryStringField="id"/></SelectParameters>
</asp:SqlDataSource>
I want to make the first column values to link button that link to a url..how can i make this?
In your gridview, set AutoGenerateColumn="False". NExt, open the properties of the Gridview and convert the column to a template field. Within item template, add the hyperlink control. From here you can change the hyperlink control as you like. To access the data from the column you can use eval (eg Text='<%# Eval("ColumnName", "Run") %>'
This can be done using a TemplateField. Please example code below.
<asp:TemplateField HeaderText="Your Header Here">
<ItemTemplate>
<asp:HyperLink runat="server" Text="<%# Bind(Text) %>" NavigateUrl='<%# "Your Link Here" %>' Target="_blank"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
Take template field for first column in your Grid view,and in that template field place Link button..
click on Link button->Link button Tasks->edit Data Bindings->Text=<%Eval("Your ColumnName")%

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 to Bind Data in HTML Drop Down List

Can any one please tell me How to Bind Data from Sql DataBase to
DropDown List(Select Drop Down) using C#.net in Asp.net
OK! first youll have to write the javascript code using HTML in the client side using the selectedIndex function! you could read more about javascript in google , second you you bind your data in server side like this
dropdown1.DataSource = datatable;
dropdown1.DataBind();
OR read these links
http://shawpnendu.blogspot.com/2009/08/javascript-how-to-get-selectedtext-from.html
http://shawpnendu.blogspot.com/2009/05/how-to-bind-or-populate-data-into.html
i hope it helps you or at least show you the right directions or hints of what you want :)
Try this one ...you can achieve it
<script type="text/javascript">
function func() {
var grd = document.getElementById("Panel1");
grd.setAttribute("style", "display:inline;");
}
</script>
<asp:TextBox ID="txtDDL" CssClass="txtClass" runat="server" ReadOnly="true" onclick="javascript:func();" />
<asp:Panel ID="Panel1" runat="server" Style="display: none;">
<asp:GridView ID="GridView1" runat="server" BackColor="LightGoldenrodYellow" BorderColor="Tan"
BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None">
<AlternatingRowStyle BackColor="PaleGoldenrod" />
<FooterStyle BackColor="Tan" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<SortedAscendingCellStyle BackColor="#FAFAE7" />
<SortedAscendingHeaderStyle BackColor="#DAC09E" />
<SortedDescendingCellStyle BackColor="#E1DB9C" />
<SortedDescendingHeaderStyle BackColor="#C2A47B" />
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:LinkButton ID="lbtnSelect" Text="Check All" runat="server" OnClick="Select" />
<asp:Button ID="btnSubmit" CssClass="btn" Text="Submit" runat="server" OnClick="Result" />
<asp:LinkButton ID="lbtnClear" Text="Clear All" runat="server" OnClick="Clear"></asp:LinkButton>
</asp:Panel>

Get value from DetailsView to FormView Textbox in insert mode

I'm trying to get the value from detailsview to formview. I want to set the Book ID/ISBN in formview insert textbox to Book ID/ISBN value from detailsview.
Here's a sample of my code:
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
CellPadding="4" DataKeyNames="bookid" DataSourceID="detailsDataSource"
ForeColor="#333333" GridLines="None" Height="50px" Width="">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
<RowStyle BackColor="#EFF3FB" />
<FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<FooterTemplate>
<asp:GridView ID="GridView2" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="reservationid" DataSourceID="reserveDataSource"
ForeColor="#333333" GridLines="None">
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:BoundField DataField="EmployeeID" HeaderText="Reserved by"
SortExpression="EmployeeID" />
<asp:BoundField DataField="reservedate" HeaderText="Reserved date"
SortExpression="reservedate" />
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="reservationid"
DataSourceID="reserveDataSource">
<EditItemTemplate>
reservationid:
<asp:Label ID="reservationidLabel1" runat="server"
Text='<%# Eval("reservationid") %>' />
<br />
bookid:
<asp:TextBox ID="bookidTextBox" runat="server" Text='<%# Bind("bookid") %>' />
<br />
EmployeeID:
<asp:TextBox ID="EmployeeIDTextBox" runat="server"
Text='<%# Bind("EmployeeID") %>' />
<br />
reservedate:
<asp:TextBox ID="reservedateTextBox" runat="server"
Text='<%# Bind("reservedate") %>' />
<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>
Book ID/ISBN:
<asp:TextBox ID="bookidTextBox" runat="server"
Text='<%# Bind("bookid") %>'/>
<br />
Employee ID:
<asp:TextBox ID="EmployeeIDTextBox0" runat="server"
Text='<%# Bind("EmployeeID") %>' />
<br />
Reserve date:
<asp:TextBox ID="reservedateTextBox0" runat="server"
Text='<%# Bind("reservedate") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Reserve" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
So what I'm trying to do is when a user click the Insert/Reserve book linkbutton the Book ID/ISBN is already set to the Book ID/ISBN in formview insert mode as default.
Any help would be much appreciated ;)
Thanks in advance.
Can you try and check the DetailsView1.SelectedValue
<asp:TextBox ID="bookidTextBox" runat="server"
Text='<%# DetailsView1.SelectedValue %>'/>
Edit:
Now if you want to bind that value to your Insert function of your DetailsView, it will not behave like the other control, since you are using the Bind method for the other control and it provides two way binding.
Now you need to pass that value to inserting evet of DetailsView like as we are assigning values using DetailsView1.SelectedValue but not binding the value.
I hope you understand this theory.
protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
e.Values["bookid"] = ((TextBox)DetailsView1.FindControl("bookidTextBox")).Text;
}

Categories

Resources