Gridview postback datasource persistance - c#

I have a grid that is data bound to a generic list. Which I edit and need to persist the changes of, to the db.
The problem is when I hit the submit button it does a PostBack. And sets the data source of the gridview to null.
I've tried storing the data source in the view state ViewState["data"] which works great but the data isn't being updated in the ViewState when changes are made on the grid.
Any ideas?
Here is the code for the GridView:
<asp:GridView ID="dgMerchantConfiguration" runat="server"
AutoGenerateColumns="False"
CausesValidation="False" CustomPagerCssClass="" HeaderHeight="30px" NumberOfPagesHeight="15px"
NumberOfPagesWidth="40px" PagerHeight="15px" PagerWidth="40px" ShowDataGridCustomPaging="None"
SortHeight="15px" SortWidth="70px" BackColor="White" BorderColor="#999999" BorderWidth="1px"
CellPadding="1" Font-Size="Smaller" GridLines="Vertical" Width="100%"
onrowdatabound="dgMerchantConfiguration_RowDataBound" ViewStateMode="Enabled" EnableViewState="False">
<SelectedRowStyle Font-Bold="True" ForeColor="White" BackColor="#f80000"></SelectedRowStyle>
<AlternatingRowStyle BackColor="Gainsboro"></AlternatingRowStyle>
<RowStyle ForeColor="Black" BackColor="#EEEEEE"></RowStyle>
<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#bd0000" HorizontalAlign="Center"></HeaderStyle>
<FooterStyle ForeColor="Black" BackColor="#CCCCCC"></FooterStyle>
<Columns>
<asp:BoundField DataField="Id" HeaderText="ID">
<HeaderStyle HorizontalAlign="Center" CssClass="NormalBold"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" CssClass="Normal"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="CommissionType" HeaderText="Commission Type">
<HeaderStyle HorizontalAlign="Center" CssClass="NormalBold"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" CssClass="Normal"></ItemStyle>
</asp:BoundField>
<asp:TemplateField HeaderText="Select">
<HeaderStyle HorizontalAlign="Center" CssClass="NormalBold"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" CssClass="Normal"></ItemStyle>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" Checked='<%# Bind("Selected") %>' OnCheckedChanged="chkSelect_CheckedChanged" AutoPostBack="True" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Override">
<HeaderStyle HorizontalAlign="Center" CssClass="NormalBold"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" CssClass="Normal"></ItemStyle>
<ItemTemplate>
<asp:CheckBox ID="chkOverride" runat="server" Checked='<%# Bind("Default") %>' OnCheckedChanged="chkOverride_CheckedChanged" AutoPostBack="True" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Comission Structure">
<HeaderStyle HorizontalAlign="Center" CssClass="NormalBold"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" CssClass="Normal"></ItemStyle>
<ItemTemplate>
<asp:DropDownList ID="drpCommissionStructure" runat="server" Width="200px" OnSelectedIndexChanged="drpCommissionStructure_SelectedIndexChanged" AutoPostBack="True"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Min">
<HeaderStyle HorizontalAlign="Center" CssClass="NormalBold"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" CssClass="Normal"></ItemStyle>
<ItemTemplate>
<asp:TextBox ID="txtMin" runat="server" Width="50px" Text='<%# Bind("Min") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Max">
<HeaderStyle HorizontalAlign="Center" CssClass="NormalBold"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" CssClass="Normal"></ItemStyle>
<ItemTemplate>
<asp:TextBox ID="txtMax" runat="server" Width="50px" Text='<%# Bind("Max") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Fixed">
<HeaderStyle HorizontalAlign="Center" CssClass="NormalBold"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" CssClass="Normal"></ItemStyle>
<ItemTemplate>
<asp:TextBox ID="txtFixed" runat="server" Width="50px" Text='<%# Bind("Fixed") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Cost Per Unit">
<HeaderStyle HorizontalAlign="Center" CssClass="NormalBold"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" CssClass="Normal"></ItemStyle>
<ItemTemplate>
<asp:TextBox ID="txtCostPerUnit" runat="server" Width="50px" Text='<%# Bind("CostPerUnit") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Unit Value">
<HeaderStyle HorizontalAlign="Center" CssClass="NormalBold"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" CssClass="Normal"></ItemStyle>
<ItemTemplate>
<asp:TextBox ID="txtUnitValue" runat="server" Width="50px" Text='<%# Bind("UnitValue") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Excluded Amount">
<HeaderStyle HorizontalAlign="Center" CssClass="NormalBold"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" CssClass="Normal"></ItemStyle>
<ItemTemplate>
<asp:TextBox ID="txtExclAmount" runat="server" Width="50px" Text='<%# Bind("ExcludedAmount") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Percentage">
<HeaderStyle HorizontalAlign="Center" CssClass="NormalBold"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" CssClass="Normal"></ItemStyle>
<ItemTemplate>
<asp:TextBox ID="txtPercentage" runat="server" Width="50px" Text='<%# Bind("Percentage") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
And how the data source is set:
protected void ddlMerchants_SelectedIndexChanged(object sender, EventArgs e)
{
// Load the selected businesses config from the db
var t = client.GetMerchantCommissionStructure(new GetMerchantCommissionStructureRequest() { MerchantID = Int32.Parse(ddlMerchants.SelectedItem.Value) });
ViewState["data"] = t.Configurations;
dgMerchantConfiguration.DataSource = t.Configurations;
dgMerchantConfiguration.DataBind();
}
Thanks in Advance!

Related

Add different numbers in each row in the Gridview

hi i have a Gridview that load from the database and i create a column in the Gridview name lblImportanceRatio and i need this column to generate those number in every row 25,20,35,20
this is the Gridview:
enter image description here
and the column name SymbolicRate i wanna just generate those number 25,20,35,20 in every row i tried to add the generate number in the Grirdview row data bound in for loop but it only give me the last number in the all column i'm Using Asp.net C#
this the Gridview:
<asp:GridView ID="gvRptBattalion" runat="server" AutoGenerateColumns="False" CssClass="table" OnRowDataBound="gvRptBattalion_RowDataBound" Visible="false">
<Columns>
<asp:BoundField DataField="ReadinessTypeName" HeaderText="Type" />
<asp:BoundField DataField="SymbolicRate" HeaderText="Rate" />
<asp:TemplateField>
<HeaderTemplate>
<asp:Label runat="server" Text="SymbolicRate"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblImportanceRatio" runat="server"></asp:Label>
</ItemTemplate>
<ItemStyle Width="50px" />
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
<asp:Label runat="server" Text="Total"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblTotal" runat="server"></asp:Label>
</ItemTemplate>
<ItemStyle Width="50px" />
</asp:TemplateField>
<asp:BoundField DataField="BattalionDate" HeaderText="#">
<FooterStyle CssClass="hide_identity" />
<HeaderStyle CssClass="hide_identity" HorizontalAlign="Right" />
<ItemStyle CssClass="hide_identity" />
</asp:BoundField>
<asp:BoundField DataField="SUnitId" HeaderText="#">
<FooterStyle CssClass="hide_identity" />
<HeaderStyle CssClass="hide_identity" HorizontalAlign="Right" />
<ItemStyle CssClass="hide_identity" />
</asp:BoundField>
<asp:TemplateField>
<HeaderTemplate>
<asp:Label runat="server" Text="TotalAll"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblFormla" runat="server"></asp:Label>
</ItemTemplate>
<FooterStyle CssClass="lbl" />
<HeaderStyle CssClass="lbl" HorizontalAlign="Right" />
<ItemStyle CssClass="lbl" />
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
<asp:Label runat="server" Text="TotalALL2"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblG" runat="server"></asp:Label>
</ItemTemplate>
<FooterStyle CssClass="lbl" />
<HeaderStyle CssClass="lbl" HorizontalAlign="Right" />
<ItemStyle CssClass="lbl" />
</asp:TemplateField>
</Columns>
</asp:GridView>

Adding blank row in gridview with button in footer

I have gridview with footer and addbutton on that, how to add new rows if I push the addbutton ? so I can enter new data on that. I also want save them all into database, can somebody explain please
this my front code:
<asp:GridView ID="GridView1" AutoGenerateColumns="False" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None" ShowFooter="True" Width="707px" >
<AlternatingRowStyle BackColor="White"/>
<Columns>
<asp:TemplateField>
<FooterTemplate>
<asp:Button ID="AddProduct" runat="server" CssClass="button" Text="Add" onclick="AddProduct_Click" ></asp:Button>
</FooterTemplate>
</asp:TemplateField>
<asp:BoundField HeaderStyle-Width="120px" HeaderText="Id Trans" DataField="Id_Trans" ShowHeader="False" Visible="False">
<HeaderStyle Width="120px"></HeaderStyle>
</asp:BoundField>
<asp:TemplateField HeaderText="Nama Barang" SortExpression="Nama_Item">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="tampilbarang" DataTextField="Nama_Item" DataValueField="Id_Item">
</asp:DropDownList>
<asp:SqlDataSource ID="tampilbarang" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Item]"></asp:SqlDataSource>
</ItemTemplate>
<HeaderStyle Width="120px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="QTY">
<ItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</ItemTemplate>
<HeaderStyle Width="120px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Keterangan Penggunaan">
<ItemTemplate>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</ItemTemplate>
<HeaderStyle Width="120px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Aksi">
<ItemTemplate>
<asp:Button ID="Del" runat="server" Height="22px" Text="Delete" Width="57px" />
</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>
There are a lot of things to explain in answer your question, so instead I'd recommend a good tutorial - try this - https://quickstarts.asp.net/quickstartv20/aspnet/doc/ctrlref/data/gridview.aspx
You can add a button in footer template like this example:
<asp:gridview ID="Gridview1" runat="server" ShowFooter="true" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="RowNumber" HeaderText="Row Number" />
<asp:TemplateField HeaderText="Header 1">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Header 2">
<ItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Header 3">
<ItemTemplate>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</ItemTemplate>
<FooterStyle HorizontalAlign="Right" />
<FooterTemplate>
<asp:Button ID="ButtonAdd" runat="server" Text="Add New Row" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:gridview>

Prevent GridView OnRowCommand to execute for specific gridview column Asp.net

I have a GridView defined like this:
<asp:GridView ID="GridView_Messages" runat="server" AutoGenerateColumns="False" PageSize="5" CellPadding="4" AllowPaging="true" Width=100% AllowSorting="true" OnSorting="GridView_Messages_Sorting"
ForeColor="#333333" GridLines="None" OnRowDataBound="GridView_Messages_OnRowDataBound" OnPageIndexChanging="GridView_Messages_PageIndexChanged" OnRowCommand="GridView_Messages_OnRowCommand" EmptyDataText="<%$ Resources:Localization, NoMsg %>">
<%--CssClass="Grid" AlternatingRowStyle-CssClass="alt" PagerStyle-CssClass="pgr"--%>
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField HeaderText="" ItemStyle-Width="75" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle">
<HeaderTemplate>
<asp:CheckBox ID="allchk" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="check" Text="" TextAlign="Right" AutoPostBack="false" Checked="false" runat="server" OnCheckedChanged="GridView_Messages_CheckedChanged"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="MessageID" ItemStyle-Width="150" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" Visible="false">
<ItemTemplate>
<asp:Label ID="GridView_Messages_lblMessageID" runat="server" Text='<%# Eval("MessageID") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="<%$ Resources:Localization, Title2 %>" ItemStyle-Width="150" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" SortExpression="it.Title">
<ItemTemplate>
<asp:Label ID="GridView_Messages_lblTitle" runat="server" Text='<%# Eval("Title") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description" ItemStyle-Width="150" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" Visible="false">
<ItemTemplate>
<asp:Label ID="GridView_Messages_lblDescription" runat="server" Text='<%# Eval("Description")%>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="FromUserID" ItemStyle-Width="150" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" Visible="false">
<ItemTemplate>
<asp:Label ID="GridView_Messages_lblFromUserID" runat="server" Text='<%# Eval("FromUserID")%>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="<%$ Resources:Localization, From %>" ItemStyle-Width="150" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" SortExpression="it.UserName">
<ItemTemplate>
<asp:Label ID="GridView_Messages_lblFromUserName" runat="server" Text='<%# Eval("UserName")%>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Notes" ItemStyle-Width="150" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" Visible="false">
<ItemTemplate>
<asp:Label ID="GridView_Messages_lblNotes" runat="server" Text='<%# Eval("Notes") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="<%$ Resources:Localization, IsRead %>" Visible="false" ItemStyle-Width="150" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" SortExpression="it.IsRead">
<ItemTemplate>
<asp:Label ID="GridView_Messages_lblIsRead" runat="server" Text='<%# Eval("IsRead") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="<%$ Resources:Localization, TimeSent %>" ItemStyle-Width="150" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" SortExpression="it.SentDateTime">
<ItemTemplate>
<asp:Label ID="GridView_Messages_lblDateTime" runat="server" Text='<%# Eval("SentDateTime") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="Msg_lnkBtnClk" runat="server" CommandName="SingleClick" Text="click"
Visible="true" CssClass="hidden"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="Msg_lnkBtnDblClk" runat="server" CommandName="DoubleClick" Text="dblClick"
Visible="true" CssClass="hidden"/>
</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="#C7B88D" />
</asp:GridView>
I don't want my OnRowCommand to execute for the first column of my GridView. Actually I don't want my event to fire when some of my checkboxes is clicked. How to determine if I have clicked on a checkbox or I have clicked somewhere else in a gridview? In WPF I could use e.OriginalSource property but here this is not possible.
Using JQuery:
If you haven't already added JQuery to your page, add this tag to your page's head section:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
And this is the actual code. Add this after the link to JQuery, in the .aspx page's head section:
<script type="text/javascript">
$(function(){
$('#<%= GridView_Messages.ClientID %> input[type="checkbox"]')
.click(function(event){
event.stopPropagation();
event.preventDefault();
})
});
</script>

gridview sort order changes when editing row

i have a gridview which simply displays records based on a filter from a dropdownlist, when i change the dropdownlist the page postbacks fine and the filter works, but when i click to edit a row the sort order changes based on the new filter. when i change the drop down back to the original filter and click edit the sort order remains the same.
any ideas?
<asp:DropDownList ID="ddlFilterDocs" runat="server"
AutoPostBack="True"
onselectedindexchanged="ddlFilterDocs_SelectedIndexChanged">
<asp:ListItem Text="MissingData"
Value="MissingData" >MissingData</asp:ListItem>
<asp:ListItem Text="AllData" Value="AllData"
>AllData</asp:ListItem>
</asp:DropDownList>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" PageSize="35"
AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None"
onrowcommand="GridView1_RowCommand" DataKeyNames="customerCode"
onpageindexchanging="GridView1_PageIndexChanging"
onsorting="GridView1_Sorting">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField SortExpression="CustomerCode">
<ItemTemplate>
<asp:LinkButton ID="lbEdit" ForeColor="DarkGreen" Font-
Bold="True" CommandArgument='<%# Eval("customerCode") %>' CommandName="EditRow"
runat="server">Edit</asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="lbUpdate" CommandArgument='<%#
Eval("customerCode") %>' CommandName="UpdateRow" runat="server"
ForeColor="White">Update</asp:LinkButton>
<asp:LinkButton ID="lblCancel" CommandArgument='<%#
Eval("customerCode") %>' CommandName="CancelUpdate" runat="server"
ForeColor="White">Cancel</asp:LinkButton>
</EditItemTemplate>
<HeaderStyle Width="100px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Customer ID"
SortExpression="CustomerCode">
<EditItemTemplate>
<asp:Label ID="lblCustCodeEdit" runat="server" Text='<%#
Eval("CustomerCode") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblCustCode" runat="server" Text='<%#
Bind("CustomerCode") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="Name"
SortExpression="Name"
ReadOnly="True" >
<HeaderStyle Width="100px" />
</asp:BoundField>
<asp:TemplateField HeaderText="StreetAddress"
SortExpression="StreetAddress">
<EditItemTemplate>
<asp:TextBox ID="tbxStreetAddress" runat="server"
Text='<%# Bind("StreetAddress") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblStreetAddress" runat="server" Text='<%#
Bind("StreetAddress") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle Width="150px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="City" SortExpression="City">
<EditItemTemplate>
<asp:TextBox ID="tbxCity" runat="server" Text='<%#
Bind("City") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblCity" runat="server" Text='<%#
Bind("City") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle Width="100px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Zip" SortExpression="Zip">
<EditItemTemplate>
<asp:TextBox ID="tbxZip" runat="server" Text='<%#
Bind("Zip") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblZip" runat="server" Text='<%#
Bind("Zip") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle Width="50px" />
</asp:TemplateField>
<asp:BoundField DataField="DocNumber" HeaderText="DocNumber"
SortExpression="DocNumber" ReadOnly="True">
<HeaderStyle Width="50px" />
</asp:BoundField>
<asp:BoundField DataField="GrossAmount" HeaderText="Gross"
SortExpression="GrossAmount" ReadOnly="True"
DataFormatString="{0:c2}" >
<HeaderStyle Width="70px" />
</asp:BoundField>
<asp:BoundField DataField="NetAmount" HeaderText="Net"
SortExpression="NetAmount" ReadOnly="True" DataFormatString="
{0:c2}" >
<HeaderStyle Width="70px" />
</asp:BoundField>
<asp:BoundField DataField="VATAmount" HeaderText="VAT"
SortExpression="VATAmount" ReadOnly="True" DataFormatString="
{0:c2}" >
<HeaderStyle Width="70px" />
</asp:BoundField>
<asp:BoundField DataField="FromVoucNbr" HeaderText="Voucher"
SortExpression="FromVoucNbr" ReadOnly="True" >
<HeaderStyle Width="70px" />
</asp:BoundField>
<asp:BoundField DataField="LastModDate" HeaderText="Date"
SortExpression="LastModDate" ReadOnly="True"
DataFormatString="{0:G}" >
<HeaderStyle Width="70px" />
</asp:BoundField>
<asp:BoundField DataField="LastModUser" HeaderText="LastModUser"
SortExpression="LastModUser" ReadOnly="True">
<HeaderStyle Width="50px" />
</asp:BoundField>
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<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>
If you are rebinding the data into the Row_Editing event then you need to filter that with the drop down selected value.
Regards,

how Aggregate="sum" For TemplateColumns In RadGrid (Telerik) -> showing in footer

my TemplateColumn In RadGrid (Telerik) is like below :
<telerik:GridTemplateColumn FilterControlAltText="Filter TemplateColumn_Benefit"
HeaderText="Benefit" UniqueName="TemplateColumn_Benefit" FilterImageToolTip="Filter">
<ItemTemplate>
<asp:Label ID="lblBenefitInsideGrd" runat="server" Font-Size="11px" Text='<%# (bool)Convert.IsDBNull(Eval("Benefit")) ? "<span class=\"lblInsideGrd\">Empty</span>" : String.Format("{0:#,0 Dollar;#,0- Dollar}", Eval("Benefit")) %>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="60px" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="60px" />
</telerik:GridTemplateColumn>
the showfooter property of RadGrid Is true ...
when add the below properties to this template column , so we will have an exeption ...
properties : FooterText="my sum" Aggregate="Sum"
error message : Sum is not supported for type "System.Object"
how can i have sum of such these columns in radgrid ?
thanks in advance
You have to add the DataField="Benefit" to the GridTemplateColumn.
<telerik:GridTemplateColumn FilterControlAltText="Filter TemplateColumn_Benefit" DataField="Benefit"
HeaderText="Benefit" UniqueName="TemplateColumn_Benefit" FilterImageToolTip="Filter">
<ItemTemplate>
<asp:Label ID="lblBenefitInsideGrd" runat="server" Font-Size="11px" Text='<%# (bool)Convert.IsDBNull(Eval("Benefit")) ? "<span class=\"lblInsideGrd\">Empty</span>" : String.Format("{0:#,0 Dollar;#,0- Dollar}", Eval("Benefit")) %>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="60px" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="60px" />
</telerik:GridTemplateColumn>

Categories

Resources