I am developing Canteen Management System where I am displaying menuList from Database using gridview like given below.. ( this is Menu.aspx page)
<asp:DataList ID="DataList1" runat="server" RepeatColumns="3" RepeatDirection="Horizontal" OnItemCommand="DataList1_ItemCommand">
<ItemTemplate>
<table class="nav-justified" style="height: 111px">
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("menuName") %>'></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:ImageButton ID="ImageButton1" runat="server" CommandName="viewDetail" CommandArgument='<%# Eval("Id") %>' ImageUrl='<%# Eval("menuImage") %>' />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("menuPrice") %>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Cms_AspFormsConnectionString %>" SelectCommand="SELECT [menuName], [menuPrice], [menuImage], [Id] FROM [menuInfo]"></asp:SqlDataSource>
This is Menu.aspx.cs page
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if ( e.CommandName == "viewDetail" )
{
Response.Redirect("MenuDetails.aspx?Id=" + e.CommandArgument.ToString());
}
}
but When i run this this it's showing nothing, ( when i go to source page it was all empty at like given below..)
<div>
<br />
</div>
Why it' showing empty? and how to resolve this?
Add DataSourceID="SqlDataSource1" to the DataList tag. Data source was not set for the control.
Related
I was using a simple html img with jQuery to show the nested table and binding the repeater on itemdatabound. Problem is, this was very expensive by getting all sub items from items in the list at the same time. So I decided it's better when i click the collapse image to show the nested table I should bind the repeater in there.
For this I use imagebutton and command argument to get the ID and use update panel to stop postback from button, but the repeater won't update?
<asp:ScriptManager runat="server"></asp:ScriptManager>
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="rptInventarioLocalizacoes_ItemCommand">
<HeaderTemplate>
<table id="tblInventarioLocalizacoes" class="table table-bordered table-striped dataTable text-center">
<thead class="thead-dark">
<tr>
<th></th>
<th>Nª</th>
<th>Localização</th>
<th>Etq. Por Inventariar</th>
<th>Etq. Inventariadas</th>
<th>Precisão</th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:ImageButton ID="ibtnCollapse" runat="server" Style="cursor: pointer" ImageUrl="../../Images/Collapse/plus.png" Width="20" CommandName="BindEtiquetas" CommandArgument='<%# Eval("Localizacao") %>' />
<asp:Panel ID="pnlInventarioEtiquetas" runat="server" Style="display: none">
<asp:UpdatePanel runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ibtnCollapse" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Repeater ID="rptLocalizacoesEtiquetas" runat="server">
<HeaderTemplate>
<table id="tblLocalizacoesEtiquetas" class="nestedtable table table-bordered table-striped dataTable">
<thead class="thead-dark">
<tr>
<th>#</th>
<th>Etiqueta</th>
<th>Validar</th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblRowIndex" runat="server" Text='<%# (((RepeaterItem)Container).ItemIndex + 1) %>' />
</td>
<td>
<asp:Label ID="lblEtiqueta" runat="server" Text='<%# Eval("Etiqueta") %>' />
</td>
<td>
<asp:CheckBox ID="chkEtiqueta" runat="server" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
<asp:Button ID="btnAddEtiqueta" runat="server" CssClass="btn btn-default" Text="Adicionar Etiqueta" BackColor="#020023" ForeColor="White" Font-Bold="true" />
<asp:Button ID="btnInventariar" runat="server" CssClass="btn btn-default" Text="Inventariar Etiquetas" BackColor="#020023" ForeColor="White" Font-Bold="true" />
</FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
</td>
<td>
<asp:Label ID="lblRowIndex" runat="server" Text='<%# (((RepeaterItem)Container).ItemIndex + 1) %>' />
<asp:Label ID="lblIdlocalizacao" runat="server" Text='<%# Eval("IdInventarioLocalizacao") %>' Style="display: none" />
</td>
<td>
<asp:Label ID="lblLocalizacao" runat="server" Text='<%# Eval("Localizacao") %>' />
</td>
<td>
<asp:Label ID="lblEtiquetasPorInventariar" runat="server" Text='<%# Eval("EtiquetasPorInventariar") %>' />
</td>
<td>
<asp:Label ID="lblEtiquetasInventariadas" runat="server" Text='<%# Eval("EtiquetasInventariadas") %>' />
</td>
<td>
<asp:Label ID="lblPrecisao" runat="server" Text='<%# Eval("Precisao") %>' />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
In an asp.net web page with a repeater control, how can I avoid a complete page refresh when I select a checkbox in the header to check all checkboxes in the item template rows?
My project is based on asp.net C#, with SQL Server as database.
<asp:Repeater ID="Repeater_product_detail" runat="server" OnItemCommand="Repeater_product_detail_ItemCommand" OnItemDataBound="Repeater_product_detail_ItemDataBound">
<HeaderTemplate>
<table class="table table-striped table-bordered ">
<thead>
<tr>
<td> <asp:CheckBox ID="chk_select" AutoPostBack="true" runat="server" OnCheckedChanged="chk_select_CheckedChanged"/> </td>
<th>SubCategory</th>
<th>Product Name</th>
<th>Product image</th>
<th>Product Price</th>
<th>in stock</th>
<th>Type for</th>
<th>Action</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:CheckBox ID="chkDelete" AutoPostBack="true" runat="server" />
<asp:Label ID="lbl_id" Visible="false" runat="server" Text='<%# ("int_product_id") %>'></asp:Label>
</td>
<td>
<asp:Label ID="lbl_sub_cate" runat="server" Text='<%# Eval("txt_sub_category_name") %>'></asp:Label>
<asp:DropDownList ID="ddl_sub_category" Width="100px" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "txt_sub_category_name") %>' runat="server" Visible="false" > </asp:DropDownList>
</td>
<td> <asp:Label ID="lbl_product_name" runat="server" Text='<%# Eval("txt_product_name") %>'></asp:Label>
<asp:TextBox ID="txt_product_name" BackColor="#d4d0c8" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "txt_product_name")%>' Visible="false"></asp:TextBox>
</td>
<td> <%--<asp:Label ID="lbl_product_image" runat="server" Text='<%# Eval("product_img_small") %>'></asp:Label>--%>
<asp:Image ID="Image1" Height="50px" Width="50px" ImageUrl='<%# Eval("product_img_small") %>' runat="server" />
</td>
<td> <asp:Label ID="lbl_product_price" runat="server" Text='<%# Eval("txt_product_price") %>'></asp:Label>
<asp:TextBox ID="txt_product_price" Width="60px" BackColor="#d4d0c8" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "txt_product_price")%>' Visible="false"></asp:TextBox>
</td>
<td> <asp:Label ID="lbl_stock" runat="server" Text='<%# Eval("in_stock") %>'></asp:Label>
<asp:TextBox ID="txt_stock" BackColor="#d4d0c8" Width="60px" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "in_stock")%>' Visible="false"></asp:TextBox>
</td>
<td> <asp:Label ID="lbl_type" runat="server" Text='<%# Eval("cate_type") %>'></asp:Label>
<asp:DropDownList ID="ddl_type" runat="server" Width="60px" DataTextField="cate_type" Visible="false"></asp:DropDownList>
</td>
<td>
<asp:LinkButton ID="lnk_edit" CommandArgument='<%# Eval("int_product_id") %>' CommandName="edit" runat="server">Edit</asp:LinkButton>
<asp:LinkButton ID="lnk_update" CommandArgument='<%# Eval("int_product_id") %>' Visible="false" CommandName="update" runat="server">Update</asp:LinkButton>
<asp:LinkButton ID="lnk_cancel" CommandArgument='<%# Eval("int_product_id") %>' Visible="false" CommandName="cancel" runat="server">Cancel</asp:LinkButton>
<asp:LinkButton ID="lnk_delete" CommandArgument='<%# Eval("int_product_id") %>' CommandName="delete" OnClientClick='javascript:return confirm("Are you sure you want to delete?")' runat="server">Delete</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr style="background-color:#15880a">
<td colspan="8">
</tbody>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:LinkButton ID="lnk_del_selected" CommandArgument='<%# Eval("int_product_id") %>' OnClientClick='javascript:return confirm("Are you sure you want to delete?")' runat="server" OnClick="lnk_del_selected_Click">Deleted Selected</asp:LinkButton>
Behind Code
protected void chk_select_CheckedChanged(object sender, EventArgs e)
{
Control header_control = Repeater_product_detail.Controls[0].Controls[0]; // Find header Template's Items
CheckBox chk = header_control.FindControl("chk_select") as CheckBox;
if (!chk.Checked)
{
toggleCheckState(false);
}
else
{
toggleCheckState(true);
}
}
public void toggleCheckState(bool checkstate)
{
foreach (RepeaterItem item in Repeater_product_detail.Items) // Find Item Template's Items
{
if (item.ItemType == ListItemType.AlternatingItem || item.ItemType == ListItemType.Item)
{
CheckBox chk_delete = (CheckBox)item.FindControl("chkDelete");
chk_delete.Checked = checkstate;
}
}
Set AutoPostBack="false" in checkbox properties.
The crux of your question, I believe, is:
"when i select any value from drop down i load some data from database that depends on this selected value, i am facing a problem whenever selection changes page will be refreshed."
There are many ways to accomplish this, but it might require some restructuring to produce the desired effect. A relatively simple way to do this would be:
<asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional">
<ContentTemplate>
<asp:CheckBox ID="chk_select" AutoPostBack="true" runat="server" OnCheckedChanged="chk_select_CheckedChanged"/>
</ContentTemplate>
<Triggers>
<asp:Asyncpostbacktrigger controlid="chk_select" eventname="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
Set the AutoPostBack property to false on the checkbox.
The previous answer was almost correct, except the ASP.NET checkbox doesn't have a SelectedIndexChanged event. It should be CheckedChanged
<asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional">
<ContentTemplate>
<asp:CheckBox ID="chk_select" AutoPostBack="true" runat="server" OnCheckedChanged="chk_select_CheckedChanged"/>
</ContentTemplate>
<Triggers>
<asp:Asyncpostbacktrigger controlid="chk_select" eventname="CheckedChanged" />
</Triggers>
</asp:UpdatePanel>
set value of Autopostback attribute of checkbox which causing postback to false
You can set AutoPostBack property of CheckBox to false or else you can also use Ajax UpdatePanel control and put your CheckBox inside it so that whole page will not be reloaded and only checkbox value will be refreshed.
I am using a grid in which inside the item template(the first one in which radio button is there). i use link button instead of radiobutton ,when i click on it iam able to edit as the textbox appears, but if i use the radio button,that editing option is not coming;
aspx:
<div id="loginblock">
<table>
<tr>
<td>UserName:</td>
<td>
<asp:TextBox ID="username" runat="server" onBlur="txtvalidation();" AutoPostBack="true"></asp:TextBox>
</td>
<td>
<div id="warning" style="color:aqua;width:100px" runat="server">
</div>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="PlS Enter Password" ControlToValidate="pwd"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Password:</td>
<td>
<asp:TextBox ID="pwd" runat="server" TextMode="Password" ></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnLogin" runat="server" OnClick="btnLogin_Click" Text="Button" />
</td>
</tr>
<tr>
<asp:GridView ID="grd" runat="server" OnRowEditing="selectrd_CheckedChanged" AutoGenerateColumns="false" DataKeyNames="userid">
<Columns>
<asp:TemplateField HeaderText="edition">
<ItemTemplate>
<asp:RadioButton ID="rdnselect" runat="server" CommndName="edit" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="ids" DataField="userid" />
<asp:TemplateField HeaderText="password">
<ItemTemplate>
<%# Eval("pwd") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="edits" runat="server" Text='<%# Eval("pwd") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
cs:
protected void selectrd_CheckedChanged(object sender, GridViewEditEventArgs e)
{
grd.SelectedIndex = e.NewEditIndex;
ldgrid();
}
Here if we remove the radiobutton and insert link button,onclick of the link button we can edit the values,pls say me how to do the same operation with the radio button.
I am making QueryString parameter ,so I have two .aspx forms. One form Default.aspx contains three fields SId, FirstName, LastName. when I submit the values, those values are saved in database.Now I want show this data on grid for particular SId on default2.aspx. Grid takes data through the SqlDataSource.SO I want to call the SqlDataSource on button click and grid should show data for particular SId on default2.aspx.
Default.aspx :
<body>
<form id="form1" runat="server">
<div>
</div>
<table cellpadding="2" cellspacing="5">
<tr>
<td>
<asp:Label ID="lblId" runat="server" Text="SId"></asp:Label>
</td>
<td>
<asp:TextBox ID="tbid" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblname" runat="server" Text="FirstName"></asp:Label>
</td>
<td>
<asp:TextBox ID="tbfirstname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lbllastname" runat="server" Text="LastName"></asp:Label>
</td>
<td>
<asp:TextBox ID="tblastname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnsubmit" runat="server" Text="Submit"
onclick="btnsubmit_Click1" Width="102px" />
</td>
</tr>
</table>
<br />
</form>
</body>
Default2.aspx :
<body>
<form id="form1" runat="server">
<div>
<table cellpadding="2" cellspacing="5">
<tr>
<td>
SId</td>
<td>
<asp:TextBox ID="tbId" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnSearch" runat="server" Text="Search"
onclick="btnSearch_Click" />
</td>
</tr>
</table>
</div>
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
AutoGenerateSelectButton="True"
DataSourceID="SqlDataSource1" EnableModelValidation="True"
onrowcommand="GridView1_RowCommand">
<Columns>
<asp:TemplateField HeaderText="SId">
<ItemTemplate>
<asp:Label ID="lblSId" runat="server" Text='<%# Bind("SId") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="FirstName">
<ItemTemplate>
<asp:Label ID="lblFirstName" runat="server" Text='<%# Bind("FirstName")%>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="LastName">
<ItemTemplate>
<asp:Label ID="lblLastName" runat="server" Text='<%# Bind("LastName")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
SelectCommand="SELECT * FROM [Student] where SId = #tbId">
<SelectParameters>
<asp:QueryStringParameter Name="SId" QueryStringField="SId" />
</SelectParameters>
</asp:SqlDataSource>
</form>
</body>
I want to call the SqlDataSource1 on button click like..
Default2.aspx.cs :
protected void btnSearch_Click(object sender, EventArgs e)
{
string SId = tbId.Text;
SqlDataSource1.DataBind();
}
You don't need the button click. The SqlDataSource executes on every post back. The search button is going to issue a post back. But you are going to need to change a few things. First you need to get your parameters right, so remove this one:
<asp:QueryStringParameter Name="SId" QueryStringField="SId" />
and put this one in its place:
<asp:ControlParameter ControlID="tbId" PropertyName="Text" Name="tbId" />
and now remove all of this code:
protected void btnSearch_Click(object sender, EventArgs e)
{
string SId = tbId.Text;
SqlDataSource1.DataBind();
}
and now the SqlDataSource is tied directly to the control value, so when the user puts in a new control value and clicks the button it will be applied and new data retrieved without any of your interaction.
I am using C# asp.net 4.0 in my project where i need to display price in India curreny format.
eg. my number is 12550000.00 then i want to display it as 1,25,50,000.00
But i want this to be displayed in gridview when i bind the data to the gridview,
so it can be done in markup page. where we place Eval for each Item Data Bound.
However, i would also like to explain my senario for displaying comma sepearted values.
i have a set of textboxes above the gridview where user makes entries of values and click add.
this gets add in the viewstate and the viewstate is binded to gridview.
In gridview i also have Edit button on click of it the values in viewstate is passed back to textbox on RowCommand Event of gridview. and on update click the viewstate datatable is updated and Binded back to gridview.
FOR your reference:
protected void gvPropertyConfig_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
if (e.CommandName == "EditItem")
{
int index = Convert.ToInt32(e.CommandArgument);
hdnIndex.Value = index.ToString();
DataTable dt = (DataTable)ViewState["proeprtyConfig"];
DataRow dr = dt.Rows[index];
if (Request.QueryString["CMD"] == "Edit")
{
hdnPropertyConfigID.Value = dr["config_id"].ToString();
if (dr["is_active"].ToString().ToLower() == "true")
{
chkConfigVisible.Checked = true;
}
else
{
chkConfigVisible.Checked = false;
}
thIsActHed.Visible = true;
tdIsActchk.Visible = true;
tdbtnConfig.ColSpan = 2;
}
txtScalableArea.Text = dr["scalable_area"].ToString();
txtCarpetArea.Text = dr["carpet_area"].ToString();
txtPricePerSqFt.Text = dr["price_per_sq_ft"].ToString();
txtCCPricePerSqFt.Text = dr["cc_price_per_sq_ft"].ToString();
txtTotalPrice.Text = dr["total_price"].ToString();
ddlNoOfBedrooms.SelectedValue = dr["room_id"].ToString();
btnUpdateConfig.Visible = true;
btnConfigSubmit.Visible = false;
}
if (e.CommandName == "DeleteItem")
{
int index = Convert.ToInt32(e.CommandArgument);
DataTable dt = (DataTable)ViewState["proeprtyConfig"];
DataRow dr = dt.Rows[index];
if (Request.QueryString["CMD"].ToString() == "Edit")
{
int PropertyConfigID = Convert.ToInt32(dr[0].ToString());
prConfigObj.deletePropertyConfig(PropertyConfigID);
fillData();
}
else
{
dr.Delete();
gvPropertyConfig.DataSource = (DataTable)ViewState["proeprtyConfig"];
gvPropertyConfig.DataBind();
}
clearConfigTextBoxes();
btnConfigSubmit.Visible = true;
btnUpdateConfig.Visible = false;
}
setChecklistAttr();
}
catch (Exception ex)
{
throw ex;
}
}
Below is the markup for Gridview,
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="tabBord">
<table>
<tr>
<td colspan="4" class="middle">
<h4>
Property Config Information</h4>
</td>
</tr>
<tr>
<td colspan="4">
<p>
Note: Enter total prices in lacs only. Eg. If 1 Crore than enter 1,00,00,000
</p>
<p>
</p>
</td>
</tr>
<tr>
<td>
<div id="divconfigstr" runat="server">
Configuration<span style="color: Red">*</span></div>
<%--class="displaynon"--%>
</td>
<td>
<div id="divnoofbedrooms" runat="server">
<asp:DropDownList Enabled="false" ID="ddlNoOfBedrooms" runat="server">
</asp:DropDownList>
<p>
</p>
</div>
</td>
<td>
Scalable Area <span style="color: Red">*</span>
</td>
<td>
<asp:TextBox ID="txtScalableArea" runat="server" autocomplete="off" MaxLength="10"></asp:TextBox><p>
</p>
</td>
</tr>
<tr>
<td>
Carpet Area <span style="color: Red">*</span>
</td>
<td>
<asp:TextBox ID="txtCarpetArea" runat="server" autocomplete="off" MaxLength="10"></asp:TextBox><p>
</p>
</td>
<td>
Price/Sq.Ft.<span style="color: Red">*</span>
</td>
<td>
<asp:TextBox ID="txtPricePerSqFt" runat="server" autocomplete="off" MaxLength="10"></asp:TextBox><p>
</p>
</td>
</tr>
<tr>
<td>
CC Price/Sq.Ft.<span style="color: Red">*</span>
</td>
<td>
<asp:TextBox ID="txtCCPricePerSqFt" runat="server" autocomplete="off" MaxLength="10"></asp:TextBox><p>
</p>
</td>
<td>
Total Price (in lacs)<span style="color: Red">*</span>
</td>
<td>
<asp:TextBox ID="txtTotalPrice" runat="server" autocomplete="off" MaxLength="10"></asp:TextBox><p>
</p>
</td>
</tr>
<tr>
<td id="thIsActHed" runat="server">
Active
<asp:HiddenField ID="hdnPropertyConfigID" runat="server" />
<asp:HiddenField ID="hdnIndex" runat="server" />
</td>
<td id="tdIsActchk" runat="server">
<asp:CheckBox ID="chkConfigVisible" runat="server" CssClass="checklist" /><p>
</p>
</td>
<td id="tdbtnConfig" runat="server" colspan="2">
<div class="btnHold">
<asp:Button ID="btnConfigSubmit" runat="server" Text="Add" OnClientClick="return ValidatePropertyConfig();"
CssClass="sendBtn" OnClick="btnConfigSubmit_Click" />
<asp:Button ID="btnUpdateConfig" runat="server" OnClick="btnUpdateConfig_Click" OnClientClick="return ValidatePropertyConfig();"
CssClass="sendBtn" Text="Update" Visible="False" />
<asp:Label ID="lblerrconfig" CssClass="errormsg" runat="server"></asp:Label>
</div>
</td>
</tr>
<tr>
<td colspan="4">
<div class="pHold">
<div class="gridH">
<asp:GridView ID="gvPropertyConfig" runat="server" AutoGenerateColumns="False" OnRowCommand="gvPropertyConfig_RowCommand"
OnRowDataBound="gvPropertyConfig_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="No Of Bedrooms" ItemStyle-CssClass="txtLT">
<ItemTemplate>
<asp:Label ID="lblno_of_bedrooms" runat="server" Text='<%# Eval("room_no") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Scalable Area" ItemStyle-CssClass="txtRT">
<EditItemTemplate>
<asp:TextBox ID="txtscalable_area" runat="server" Text='<%# Eval("scalable_area") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblscalable_area" runat="server" Text='<%# Eval("scalable_area") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Carpet Area" ItemStyle-CssClass="txtRT">
<EditItemTemplate>
<asp:TextBox ID="txtcarpet_area" runat="server" Text='<%# Eval("carpet_area") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblcarpet_area" runat="server" Text='<%# Eval("carpet_area") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Price/SqFt." ItemStyle-CssClass="txtRT">
<EditItemTemplate>
<asp:TextBox ID="txtprice_per_sq_ft" runat="server" Text='<%# Eval("price_per_sq_ft") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblprice_per_sq_ft" runat="server" Text='<%# Eval("price_per_sq_ft") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CC Price/SqFt." ItemStyle-CssClass="txtRT">
<EditItemTemplate>
<asp:TextBox ID="txtcc_price_per_sq_ft" runat="server" Text='<%# Eval("cc_price_per_sq_ft") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblcc_price_per_sq_ft" runat="server" Text='<%# Eval("cc_price_per_sq_ft") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Price (in lacs)" ItemStyle-CssClass="txtRT">
<EditItemTemplate>
<asp:TextBox ID="txttotal_price" runat="server" Text='<%# Eval("total_price") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lbltotal_price" runat="server" Text='<%# Eval("total_price") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="" ItemStyle-CssClass="txtLT">
<ItemTemplate>
<asp:ImageButton runat="server" ID="btnEditItem" CssClass="edBtn" ImageUrl="~/Admin/Includes/Images/edit.png"
ToolTip="Edit Item" CommandName="EditItem" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
<asp:ImageButton runat="server" ID="btnDeletetem" CssClass="edBtn" ImageUrl="~/Admin/Includes/Images/delete.png"
CommandName="DeleteItem" ToolTip="Delete Item" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</div>
</td>
</tr>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
Use the "C" parameter in the ToString function, and make sure you set the globalaztion attributes.
string parseValueIntoCurrency(double number) {
// set currency format
string curCulture = Thread.CurrentThread.CurrentCulture.ToString();
System.Globalization.NumberFormatInfo currencyFormat = new
System.Globalization.CultureInfo(curCulture).NumberFormat;
currencyFormat.CurrencyNegativePattern = 1;
return number.ToString("c", currencyFormat);
}
If you want to use a different Culture (say you're in USA, and you want the Indian format) then just use the appropriate CultureInfo element rather than getting it out of the current thread.
EXTRA INFO DUE TO OP EDIT
All right, what you're wanting to do to get this into your grid, is to create a PROTECTED function which takes in the number to be converted, and returns the converted string (this is basically the code above.
Now, on the ASPX side, you need to use that function in your grid view.
So, instead of this:
<asp:TemplateField HeaderText="Total Price (in lacs)" >
<EditItemTemplate>
<asp:TextBox ID="txttotal_price" runat="server"
Text='<%# Eval("total_price") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lbltotal_price" runat="server"
Text='<%# Eval("total_price") %>'> />
</ItemTemplate>
</asp:TemplateField>
you'll use this templatefield:
<asp:TemplateField HeaderText="Total Price (in lacs)" >
<EditItemTemplate>
<asp:TextBox ID="txttotal_price" runat="server"
Text='<%# Eval("total_price") %>' />
</EditItemTemplate>
<ItemTemplate>
<%# parseValueIntoCurrency(Eval("total_price")) %>'>
</ItemTemplate>
</asp:TemplateField>
Note, two things. The first is that I'm still passing the UNFORMATTED value into the EDIT TEMPLATE, and that I'm not instantiating an extra LABEL in the ITEM TEMPLATE.
The reason I'm not doing the extra label, is because we just don't need it in there. That's just a bit more processor/memory overhead that you just don't need to incur.
As for passing the unformatted value to the text field, that's because it'll ultimately be easier to validate without having to parse out the commas and other string elements.