i want to compare this two value on grid view but when i using .text it will occur error?
the client side code look like this
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblremainqty" runat="server" Text='<%# Eval("qtycart") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Error" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblError" runat="server" Text=''></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Try use this
int.Parse(Qty.Text) > int.Parse(RemainQty.Text)
or if it is not int value use float or decimal Parse etc. I hope it will help.
PS
Qty.ToString() will return you name of type Label.
Operator >(Greater than) is only used to compare Integer Value Not
String Value. If still you need to use that operation Then you can
convert into Int and Use that operation
You can use :
Convert.ToInt32(Qty.Text) > Convert.ToInt32(RemainQty.Text)
the client side code look like this
<asp:TemplateField HeaderText="Quantity" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblQty" runat="server" Text='<%# Eval("Quantity") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:Label ID="lblremainqty" runat="server" Text='<%# Eval("qtycart") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Error" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblError" runat="server" Text=''></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Related
Here is the gridview part. Somebody please help me to find the answer. I want to multiply Count and Price and display the sum in Amount.
<asp:TemplateField HeaderText="Price">
<ItemTemplate>
<asp:Label ID="lblCardPrice" runat="server" Text='<%# Bind("Price")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Count" >
<ItemTemplate>
<asp:Label ID="lblCount" runat="server" Text='<%# Bind("Count")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount">
<ItemTemplate>
<asp:Label ID="lblAmount" runat="server" Text='<%# Eval("(Amount)")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
try this:
<asp:TemplateField HeaderText="Amount" >
<ItemTemplate >
<asp:Label ID="lblAmount" runat="server" Text='<%# Convert.ToInt32(Eval("Count"))*Convert.ToInt32(Eval("Price"))%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
I would like to format a label using a format string returned when the grid view is bound to a stored procedure. I want to do something like this, but not this as it doesn't work:
<asp:Label ID="lbl" runat="server" Text='<%# Eval("ValueColumn"), Eval("NumberFormatColumn") %>'></asp:Label>
Thanks. Dan.
You can use string.Format with Eval.
<asp:TemplateField HeaderText="Test">
<ItemTemplate>
<asp:Label ID="lbl" runat="server"
Text='<%# string.Format("{0}, {1}", Eval("ValueColumn"),
Eval("NumberFormatColumn")) %>'/>
</ItemTemplate>
</asp:TemplateField>
Or
<asp:TemplateField HeaderText="Test">
<ItemTemplate>
<asp:Label ID="lbl" runat="server"
Text='<%# Eval("ValueColumn") + ", " + Eval("NumberFormatColumn") %>'/>
</ItemTemplate>
</asp:TemplateField>
Updated:
To format a string based on given format string
<asp:TemplateField HeaderText="Test">
<ItemTemplate>
<asp:Label ID="lbl" runat="server"
Text='<%# string.Format(Eval("NumberFormatColumn").ToString(),
Eval("ValueColumn")) %>'/>
</ItemTemplate>
</asp:TemplateField>
How can I get a Product_ID from a gridviewrow without creating a column because every time I have to make the column visible and invisible to perform gridview data operation.
Thanks in advance.
Make it part of one of your columns using a label similar to this:
<asp:TemplateField HeaderText="Name" SortExpression="name">
<ItemTemplate>
<asp:Label ID="productdIdLabel" runat="server" Text='<%# bind("Product_ID") %>' Visible="false"></asp:Label>
<asp:Label Visible="true" runat="server" ID="productNameLabel" Text='<%# bind("Product_Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Hope this helps! Cheers
<asp:HiddenField ID="HiddenField1" runat="server" Value"<%# Eval("id")%>" />
<asp:TemplateField HeaderText="Name" SortExpression="name" visible="False">
<ItemTemplate>
<asp:label id="prodId" runat=server" Text="<%# Eval("id")%>" ></asp:label>
</ItemTemplate>
In an aspx page I am binding the labels like this:
<asp:TemplateField HeaderText="Date of Joining">
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Eval("date_of_joining") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Paid Priviledge Date">
<ItemTemplate>
<asp:Label ID="Label8" runat="server"
Text='<%# Eval("paid_priviledge_date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
And in the code behind I'm binding the grid view like this :(minimum code is given)
GridView1.DataSource = dt2;
GridView1.DataBind();
But the gridview columns show the date like this :
4/12/2011 12:00:00 AM
4/4/2011 12:00:00 AM
Please suggest how to remove the time stamp part and to display only the date part.
I know how to do this by formatting using ToString and SubString. But I am not able to do this in gridview.
You can specify format strings for the eval statement:
Eval("date_of_joining", "{0:dd/MM/yyyy}")
Create a FormatDate method in your codebehind, and call that from your gridview.
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
http://www.csharp-examples.net/string-format-datetime/
This part will go in your code behind
private object FormatDate(DateTime input)
{
return String.Format("{0:MM/dd/yy}", input);
}
And this bit will go in your markup
<asp:TemplateField HeaderText="Date of Joining">
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# FormatDate(Eval("date_of_joining")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Paid Priviledge Date">
<ItemTemplate>
<asp:Label ID="Label8" runat="server"
Text='<%# FormatDate(Eval("paid_priviledge_date")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
This is what I would call a D.R.Y. approach to the problem. If you ever need to modify the formatting in any way. You can simply edit the code behind method and it will rain down sweet love to all of your markup.
Use "{0:d}" for short date format.
Try
Text='<%# Eval("paid_priviledge_date","{0:d}") %>'
and
Text='<%# Eval("date_of_joining", "{0:d}") %>'
You can use the DataFormatString in a bound field the same can be set as below:
<asp:Label ID="Label8" runat="server" Text='<%# Eval("paid_priviledge_date","{0:d}") %>'/>
Text='<%# (Convert.ToDateTime((Eval("date_of_joining")))).ToShortDateString() %>'
This is the simplest way I discovered.
I have a very standard Gridview, with Edit and Delete buttons auto-generated.
It is bound to a tableadapter which is linked to my RelationshipTypes table.
dbo.RelationshipTypes:
ID, Name, OriginConfigTypeID, DestinationConfigTypeID
I wish to use a label that will pull the name from the ConfigTypes table, using the OriginConfigTypeID and DestinationTypeID as the link.
dbo.ConfigTypes:
ID, Name
My problem is, I can't automatically generate Edit and Delete buttons using an Inner Join in my dataset. Or can I?
Here is my code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" CssClass="TableList"
DataKeyNames="ID" DataSourceID="dsRelationShipTypes1">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
SortExpression="ID" Visible=False/>
<asp:TemplateField HeaderText="Origin" SortExpression="OriginCIType_ID">
<EditItemTemplate>
<asp:DropDownList Enabled=true ID="DropDownList2" runat="server" DataSourceID="dsCIType1"
DataTextField="Name" DataValueField="ID" SelectedValue='<%# Bind("OriginCIType_ID") %>'>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("OriginCIType_ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name" SortExpression="Name">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Destination" SortExpression="DestinationCIType_ID">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="dsCIType1" DataTextField="Name"
DataValueField="ID" SelectedValue='<%# Bind("DestinationCIType_ID") %>'>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("DestinationCIType_ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
So I did try to create my own edit and delete buttons, but kept receiving the error
"cannot find update method"
or something similar. Do I have to manually code the delete and update methods in my code-behind?
You have to tell either the ObjectDataSource what object to use or the SQLDataSource what stored proc to use. Use the "UpdateMethod" attribute.
You can use the code behind technique to mention about what are the method that could handle the update and delete function. This is the standard way to do that. You can either use the Sqldatasorce to describe the source.You can mention which all the tables used for inner join and can also use the sql query.