hello i am creating a shopping application , I have a shopping cart in that i have some columns which are add from the code behind and some columns are of template fields which are not present in the database but want use in future.
this is my shopping cart
code :
<asp:GridView ID="GridViewProduct" runat="server" CellPadding="5" CssClass="grid"
ForeColor="#333333" OnRowCreated="GridViewProduct_RowCreated" OnRowDataBound="GridViewProduct_RowDataBound"
ShowFooter="True" CellSpacing="1"
onrowupdating="GridViewProduct_RowUpdating">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:ButtonField Text="Remove From Cart" CommandName="RemoveFromCart" />
<asp:TemplateField HeaderText="Quantity">
<ItemTemplate>
<asp:TextBox ID="TextBoxQuantity" runat="server" Width="50px">1</asp:TextBox><br />
<asp:LinkButton ID="LinkButtonEditQuantity" runat="server" CommandName="EditTextBox">edit</asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="LinkButtonUpdate" runat="server">Update</asp:LinkButton>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Price">
<ItemTemplate>
<asp:Label ID="LabelTotalPrice" runat="server" Text="0"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" ForeColor="White" Font-Bold="True" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
i have a edit link button in the template field and the update link button in the editItem template and textbox above it so as to edit the textbox when a person clicks the edit link button.
My Question is that : How can i edit the textbox in the same column instead of whole row.
and which method should i use of the to achieve to editing the same cell rowupdating,rowcommand and save the values in session and multiply the edited value as quantity and unit price to show in the total price rows of the gridview .
please help me to implement right way to implement this as i am stuck with this for many days.. please
on your gridview templates, look at the EditRowTemplate, you will see that it contains all the editable controls (most likely textboxes) delete the textboxes and add Labels instead and bind them to your datasource. That way the data is still displayed but wont be editable (except for the control that you want to be edited)
Try it and let me know if you need more help.
Related
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
I have taken 3 text-boxes in grid view. I want to access all the 3 text-boxes value in single label on button click event.
ASP code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
CssClass="style1" ForeColor="#333333" GridLines="None" Height="342px" Width="548px">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField ApplyFormatInEditMode="True" DataField="IName" HeaderText="Item Name" />
<asp:BoundField DataField="Description" HeaderText="Description" />
<asp:BoundField DataField="price" HeaderText="Price" />
<asp:TemplateField>
<HeaderTemplate>
<asp:Label ID="txtqty" runat="server" AutoPostBack="false" Text="Enter Quantity" />
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtqtys" runat="server" AutoPostBack="false" OnTextChanged="TextBox_Changed"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
<asp:Label ID="chkAll" runat="server" onclick="checkAll(this);" AutoPostBack="true"
OnCheckedChanged="CheckBox_CheckChanged" Text="Select" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chk" runat="server" onclick="Check_Click(this)" AutoPostBack="True"
OnCheckedChanged="CheckBox_CheckChanged" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<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" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
<asp:Label ID="lbltxtqty" runat="server" Text="txtqty" Visible="true"></asp:Label>
<asp:Button ID="btnsubmit" runat="server" Text="Submit" onclick="btnsubmit_Click" />
C# code:
protected void btnsubmit_Click(object sender, EventArgs e)
{
if (!IsPostBack)
{
lbltxtqty.Visible = true;
lbltxtqty.Text = ((TextBox)GridView1.Rows[0].FindControl("txtqtys")).Text;
}
}
so please tell me the write code for it.
You are "Contradicting" your own aspx and code behind code. Why I am saying this is because, check you Label Mark-up & button click event handler:-
<asp:Label ID="lbltxtqty" runat="server" Text="txtqty" Visible="true"></asp:Label>
Here you are setting labels Visible property to true which is of no use because its by default true. Now, see your button click event you are trying to make it visible by using lbltxtqty.Visible = true;, So obviously your mark-up should first look like this:-
<asp:Label ID="lbltxtqty" runat="server" Text="txtqty" Visible="false"></asp:Label>
Because, you must be needing that when Page loads.
Now, comes your button click event. Do you know the Page Life Cycle of ASP.NET? When button click event is fired that's an obvious PostBack request so what is the Point of checking IsPostBack property there? Remove this code and it should work. Change your button click handler as follows:-
protected void btnsubmit_Click(object sender, EventArgs e)
{
lbltxtqty.Visible = true;
lbltxtqty.Text = ((TextBox)GridView1.Rows[0].FindControl("txtqtys")).Text;
}
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.
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")%
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>