Gridview row editing is not working - c#

can anyone tell me what i am missing why my row editing event is not firing.
I am trying to give edit facility in same grid as well as Add new data.
I am able to add new data (new row) but unable to edit existing row for update.
my row editing event is not firing.
<asp:GridView ID="grdHierarchy" runat="server" AllowSorting="True" AutoGenerateColumns="False" CssClass="tableGridBorder" GridLines="None" ShowFooter="True" ShowHeaderWhenEmpty="True" Width="100%" OnRowCommand="grdHierarchy_RowCommand" OnRowDataBound="grdHierarchy_RowDataBound"
OnRowEditing="grdHierarchy_RowEditing">
<AlternatingRowStyle CssClass="AlternateRow" />
<Columns>
<asp:TemplateField HeaderText="Sr.#">
<ItemTemplate>
<asp:Label ID="lblSrNo" runat="server" Text="<%# Container.DataItemIndex + 1 %>"></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="textAlignCenter" />
<HeaderStyle CssClass="textAlignCenter" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lblName" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:RequiredFieldValidator ID="rfvHierarchyName" runat="server" SetFocusOnError="True" ControlToValidate="txtHierarchyName" ErrorMessage="Enter Reference." ValidationGroup="grpHierarchy">
<asp:TextBox ID="txtHierarchyName" CssClass="textBoxSmall" Style="visibility: visible" runat="server" Text='<%# Bind("Name") %>' MaxLength="50"></asp:TextBox>
</asp:RequiredFieldValidator>
<span style="color: Red;">*</span>
<asp:RegularExpressionValidator ID="regexValiator3" runat="server" ControlToValidate="txtAPReference" ErrorMessage='Invalid Reference.' Display="None" ValidationGroup="grpHierarchy" ValidationExpression='([^<>\"\^])*'>
</asp:RegularExpressionValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:RequiredFieldValidator ID="rfvHierarchyName" runat="server" SetFocusOnError="True" ControlToValidate="txtHierarchyName" ErrorMessage="Enter Reference." ValidationGroup="grpfHierarchy">
<asp:TextBox ID="txtHierarchyName" CssClass="textBoxSmall" Style="visibility: visible" runat="server" Text='<%# Bind("Name") %>' MaxLength="50"></asp:TextBox>
</asp:RequiredFieldValidator>
<span style="color: Red;">*</span>
<asp:RegularExpressionValidator ID="regexValiator4" Display="None" runat="server" ControlToValidate="txtHierarchyName" ErrorMessage='Invalid Reference.' ValidationGroup="grpfHierarchy" ValidationExpression='([^<>\"\^])*'>
</asp:RegularExpressionValidator>
</FooterTemplate>
<ItemStyle CssClass="textAlignLeft" />
<HeaderStyle CssClass="textAlignLeft" />
<FooterStyle CssClass="textAlignLeft" />
</asp:TemplateField>
<asp:TemplateField HeaderText="LevelName">
<ItemTemplate>
<asp:Label ID="lblName" runat="server" Text='<%# Bind("Level.Name") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:RequiredFieldValidator ID="rfvLevelName" runat="server" SetFocusOnError="True" ControlToValidate="ddlLevelName" ErrorMessage="Select Level Number." Width="100px" CssClass="redborderlarge" ValidationGroup="grpHierarchy" InitialValue="--Select--">
<asp:DropDownList ID="ddlLevelName" Width="200px" Style="visibility: visible" runat="server">
</asp:DropDownList>
</asp:RequiredFieldValidator><span style="color: Red; margin-top: 4px;">*</span>
</EditItemTemplate>
<FooterTemplate>
<asp:RequiredFieldValidator ID="rfvCustomerName" runat="server" SetFocusOnError="True" ControlToValidate="ddlLevelName" ErrorMessage="Select Customer." ValidationGroup="grpfHierarchy" InitialValue="--Select--">
<asp:DropDownList ID="ddlLevelName" Width="200px" Style="visibility: visible" runat="server">
</asp:DropDownList>
</asp:RequiredFieldValidator><span style="color: Red;">*</span>
</FooterTemplate>
<ItemStyle CssClass="textAlignLeft" />
<HeaderStyle CssClass="textAlignLeft" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Action" ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="btnHierarchyEdit" runat="server" CausesValidation="false" CommandName="Edit" Text="Edit"></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="btnHierarchyUpdate" runat="server" CommandName="Select" Text="Update" CausesValidation="true" ValidationGroup="grpfHierarchy" OnClick="btnHierarchyUpdate_Click" OnClientClick="return ToggleCursor2(1,'grpAP',true);"></asp:LinkButton>
<asp:LinkButton ID="btnHierarchyCancel" runat="server" CausesValidation="false" CommandName="Select" Text="Cancel" OnClick="btnHierarchyCancel_Click"></asp:LinkButton>
</EditItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="btnHierarchyAdd" runat="server" CausesValidation="true" ValidationGroup="grpfHierarchy" CommandName="New" Text="Add" OnClientClick="return true;"></asp:LinkButton>
</FooterTemplate>
<ItemStyle CssClass="textAlignCenter" />
<HeaderStyle CssClass="textAlignCenter" />
<FooterStyle CssClass="textAlignCenter" />
</asp:TemplateField>
</Columns>
<HeaderStyle CssClass="Header" />
<RowStyle CssClass="Row" />
<FooterStyle CssClass="Header borderBttm" />
</asp:GridView>
and my code behind code is this event is not firing.where I am wrong
protected void grdHierarchy_RowEditing(object sender, GridViewEditEventArgs e)
{
grdHierarchy.EditIndex = e.NewEditIndex;
grdHierarchy.ShowFooter = false;
}
protected void grdHierarchy_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("New"))
{
Hierarchy Hierarchy = new Hierarchy();
TextBox txtHierarchyName = (TextBox)grdHierarchy.FooterRow.FindControl("txtHierarchyName");
DropDownList ddlLevelName = (DropDownList)grdHierarchy.FooterRow.FindControl("ddlLevelName");
string HierarchyName = txtHierarchyName.Text.Trim();
bool IsNameExist = Hierarchy.IsNameExist(Session, HierarchyName);
if (IsNameExist == false)
{
Hierarchy.Id = 0;
Hierarchy.Name = HierarchyName;
Hierarchy.LevelId = Convert.ToInt64(ddlLevelName.SelectedValue);
Hierarchy.CreatedDtTm = DateTime.Now;
Hierarchy.ModifiedDtTm = DateTime.Now;
Hierarchy.Save(Session);
fillHierarchyGrid();
}
else
{
cGlobalUI.showPopupMsg(Page, "Hierarchy Name is already Exist", cGlobalUI.MessageType.mtInformation);
}
}
}

Related

RowUpdating event in grid view is not firing

I have a grid view and I wanna update data in the row. I have written a C# code and I've noticed that the RowUpdating event is not firing.
I am using Template Field in my grid. The RowCommand event is working properly, however, the RowUpdating event is not firing.
What should I do? I need your help, please.
The event is like the below:
protected void grdPeople_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
SqlConnection con = new SqlConnection(strCon);
if (con.State == ConnectionState.Closed)
con.Open();
SqlCommand com = new SqlCommand("InsertUpdatePerson", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("#pr_id", Convert.ToInt32(grdPeople.DataKeys[e.RowIndex].Value.ToString()));
com.Parameters.AddWithValue("#pr_name", (grdPeople.FooterRow.FindControl("txtNameFooter") as TextBox).Text.Trim());
com.Parameters.AddWithValue("#pr_gender", (grdPeople.FooterRow.FindControl("rdoMaleFooter") as RadioButton).Checked);
com.Parameters.AddWithValue("#pr_nationality", (grdPeople.FooterRow.FindControl("txtNationalityFooter") as TextBox).Text.Trim());
com.Parameters.AddWithValue("#pr_idn", (grdPeople.FooterRow.FindControl("txtIDnoFooter") as TextBox).Text.Trim());
com.Parameters.AddWithValue("#pr_passport", (grdPeople.FooterRow.FindControl("txtPassportFooter") as TextBox).Text.Trim());
com.Parameters.AddWithValue("#pr_resident", (grdPeople.FooterRow.FindControl("rdoYesFooter") as RadioButton).Checked);
com.Parameters.AddWithValue("#pr_phone", (grdPeople.FooterRow.FindControl("txtPhoneFooter") as TextBox).Text.Trim());
com.Parameters.AddWithValue("#pr_email", (grdPeople.FooterRow.FindControl("txtEmailFooter") as TextBox).Text.Trim());
com.Parameters.Add(new SqlParameter("#ERR_MESSAGE", SqlDbType.NVarChar, 255)).Direction = ParameterDirection.Output;
com.Parameters.Add(new SqlParameter("#ERR_NUMBER", SqlDbType.Int)).Direction = ParameterDirection.Output;
com.ExecuteNonQuery();
int ErrNo = int.Parse(com.Parameters["#ERR_NUMBER"].Value.ToString());
if (ErrNo != 0)
{
lblSuccess.Text = "Data saved successfully.";
grdPeople.EditIndex = -1;
}
else
{
lblError.Text = com.Parameters["#ERR_MESSAGE"].Value.ToString();
}
}
catch (Exception ex)
{
lblSuccess.Text = "";
lblError.Text = ex.Message;
}
}
The below you will find the design of the asp page:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ValidationGridView.Default" EnableEventValidation="false" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Table runat="server">
<asp:TableRow>
<asp:TableCell>
<asp:TextBox runat="server" ID="txtSearch" />
</asp:TableCell>
<asp:TableCell>
<asp:Button runat="server" ID="btnSearch" Text="Search" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</div>
<div>
<asp:GridView ID="grdPeople" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None" AutoGenerateColumns="false"
OnRowCommand="grdPeople_RowCommand"
OnRowEditing="grdPeople_RowEditing"
OnRowCancelingEdit="grdPeople_RowCancelingEdit"
OnRowUpdating="grdPeople_RowUpdating"
ShowFooter="true" DataKeyNames="pr_id">
<AlternatingRowStyle BackColor="White" 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" />
<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" />
<Columns>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label runat="server" Text='<%# Bind("pr_name") %>' ID="lblName" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtName" Text='<%# Bind("pr_name") %>' runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtName" ErrorMessage="Name is required." ForeColor="Red" Text="*" ValidationGroup="Fields" />
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox runat="server" ID="txtNameFooter" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtNameFooter" ErrorMessage="Name is required." ForeColor="Red" Text="*" ValidationGroup="FieldsFooter" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Gender">
<ItemTemplate>
<asp:Label Text='<%# Bind("pr_gender") %>' runat="server" ID="lblGender" />
</ItemTemplate>
<EditItemTemplate>
<asp:RadioButton ID="rdoMale" Text ="Male" Checked='<%# Bind("pr_gender_value") %>' GroupName="Gender" runat="server" />
<asp:RadioButton ID="rdoFemale" Text="Female" runat="server" GroupName="Gender" />
</EditItemTemplate>
<FooterTemplate>
<asp:RadioButton ID="rdoMaleFooter" Text="Male" checked="true" runat="server" GroupName="Gender" />
<asp:RadioButton ID="rdoFemaleFooter" Text="Female" runat="server" GroupName="Gender" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Nationality">
<ItemTemplate>
<asp:Label Text='<%# Bind("pr_nationality") %>' runat="server" ID="lblNationality" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtNationality" Text='<%# Bind("pr_nationality") %>' runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" ControlToValidate="txtNationality" runat="server" ErrorMessage="Nationality is required." ForeColor="Red" Text="*" ValidationGroup="Fields" />
</FooterTemplate>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNationalityFooter" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtNationalityFooter" ErrorMessage="Nationality is required." ForeColor="Red" ValidationGroup="FieldsFooter" Text="*" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ID Number">
<ItemTemplate>
<asp:Label Text='<%# Bind("pr_idn") %>' runat="server" ID="lblIDNo" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtIDNo" Text='<%# Bind("pr_idn") %>' runat="server" />
<asp:CustomValidator ID="cstIDNo" runat="server" Text="*" ControlToValidate="txtIDNo" ForeColor="Red" ValidateEmptyText="True" ValidationGroup="Fields" />
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtIDnoFooter" runat="server" />
<asp:CustomValidator ID="cstIDNoFooter" runat="server" Text="*" ControlToValidate="txtIDnoFooter" ForeColor="Red" ValidateEmptyText="True" ValidationGroup="FieldsFooter" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Passport">
<ItemTemplate>
<asp:Label Text='<%# Bind("pr_passport") %>' runat="server" ID="lblPassport" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtPassport" Text='<%# Bind("pr_passport") %>' runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="txtPassport" ErrorMessage="Passport is required." ForeColor="Red" ValidationGroup="Fields" Text="*" />
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtPassportFooter" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="txtPassportFooter" ErrorMessage="Passport is required." ForeColor="Red" ValidationGroup="FieldsFooter" Text="*" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Resident">
<ItemTemplate>
<asp:Label Text='<%# Bind("pr_resident") %>' runat="server" ID="lblResident" />
</ItemTemplate>
<EditItemTemplate>
<asp:RadioButton ID="rdoYes" Text="Yes" Checked='<%# Bind("pr_resident_value") %>' GroupName="Resident" runat="server" />
<asp:RadioButton ID="rdoNo" Text="No" runat="server" GroupName="Resident" />
</EditItemTemplate>
<FooterTemplate>
<asp:RadioButton ID="rdoYesFooter" Text="Yes" Checked="true" GroupName="Resident" runat="server" />
<asp:RadioButton ID="rdoNoFooter" Text="No" runat="server" GroupName="Resident" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Phone">
<ItemTemplate>
<asp:Label Text='<%# Bind("pr_phone") %>' runat="server" ID="lblPhone" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtPhone" Text='<%# Bind("pr_phone") %>' runat="server" />
<asp:CustomValidator ID="cstPhone" runat="server" Text="*" ControlToValidate="txtPhone" ForeColor="Red" ValidateEmptyText="True" ValidationGroup="Fields" />
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtPhoneFooter" runat="server" />
<asp:CustomValidator ID="cstPhoneFooter" runat="server" Text="*" ControlToValidate="txtPhoneFooter" ForeColor="Red" ValidateEmptyText="True" ValidationGroup="FieldsFooter" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email">
<ItemTemplate>
<asp:Label Text='<%# Bind("pr_email") %>' runat="server" ID="lblEmail" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtEmail" Text='<%# Bind("pr_email") %>' runat="server" />
<asp:CustomValidator ID="cstEmail" runat="server" Text="*" ControlToValidate="txtEmail" ForeColor="Red" ValidateEmptyText="True" ValidationGroup="Fields" />
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtEmailFooter" runat="server" />
<asp:CustomValidator ID="cstEmailFooter" runat="server" Text="*" ControlToValidate="txtEmailFooter" ForeColor="Red" ValidateEmptyText="True" ValidationGroup="FieldsFooter" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton runat="server" ImageUrl="~/icons/edit.png" CommandName="Edit" ToolTip="Edit" Width="20px" Height="20px" />
<asp:ImageButton runat="server" ImageUrl="~/icons/delete.png" CommandName="Delete" ToolTip="Delete" Width="20px" Height="20px" />
<asp:ImageButton runat="server" ImageUrl="~/icons/email.png" CommandName="Mail" ToolTip="Mail" Width="20px" Height="20px" />
</ItemTemplate>
<EditItemTemplate>
<asp:ImageButton runat="server" ImageUrl="~/icons/save.png" CommandName="Save" ToolTip="Save" Width="20px" Height="20px" ValidationGroup="Fields"/>
<asp:ImageButton runat="server" ImageUrl="~/icons/cancel.png" CommandName="Cancel" ToolTip="Cancel" Width="20px" Height="20px" />
</EditItemTemplate>
<FooterTemplate>
<asp:ImageButton runat="server" ID="btnInsert" ImageUrl="~/icons/add.png" ValidationGroup="FieldsFooter" CommandName="Insert" ToolTip="Insert" Width="20px" Height="20px" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<asp:Label runat="server" ID="lblSuccess" ForeColor="Green" />
<br />
<asp:Label runat="server" ID="lblError" ForeColor="Red" />
</div>
<div>
<asp:ImageButton ID="btnImportExl" runat="server" ImageUrl="~/icons/excel.png" Width="40px" Height="40px" />
</div>
<div>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ForeColor="Red" ValidationGroup="Fields" />
</div>
</form>
</body>
</html>
I added the grid design above to show you how I designed it and how I set its properties.
Thank you.
In your GridView's EditItemTemplate, you miss out a button with CommandName="Update" which this button will trigger the grdPeople_RowUpdating event.
<EditItemTemplate>
<asp:ImageButton runat="server" ImageUrl="~/icons/save.png" CommandName="Save" ToolTip="Save" Width="20px" Height="20px" ValidationGroup="Fields"/>
<asp:ImageButton runat="server" ImageUrl="~/icons/cancel.png" CommandName="Cancel" ToolTip="Cancel" Width="20px" Height="20px" />
</EditItemTemplate>
SOLUTION
Change the Save button CommandName's value from CommandName="Save" to CommandName="Update".
<EditItemTemplate>
<asp:ImageButton runat="server" ImageUrl="~/icons/save.png" CommandName="Update" ToolTip="Save" Width="20px" Height="20px" ValidationGroup="Fields"/>
<asp:ImageButton runat="server" ImageUrl="~/icons/cancel.png" CommandName="Cancel" ToolTip="Cancel" Width="20px" Height="20px" />
</EditItemTemplate>
REFERENCE
Edit and Update Record in GridView in ASP.Net

How to get item in ItemDataBound?

Hope everything is fine.
How can I find control ItemDataBound
I have this
<telerik:RadGrid RenderMode="Lightweight" runat="server" ID="RadGrid1" OnItemDataBound="RadGrid1_ItemDataBound" OnInsertCommand="RadGrid1_InsertCommand" OnUpdateCommand="RadGrid1_UpdateCommand"
AutoGenerateColumns="False" GridLines="None"
PageSize="3">
<PagerStyle Mode="NumericPages" AlwaysVisible="true"></PagerStyle>
<MasterTableView AutoGenerateColumns="false" AllowAutomaticUpdates="false" Width="100%" CommandItemDisplay="Top" DataKeyNames="ID" >
<CommandItemSettings ShowRefreshButton="false" />
<CommandItemSettings ShowAddNewRecordButton="true" />
<Columns>
<telerik:GridEditCommandColumn>
<HeaderStyle Width="36px"></HeaderStyle>
</telerik:GridEditCommandColumn>
<telerik:GridTemplateColumn HeaderText="ImageName" UniqueName="ImageName">
<ItemTemplate>
<asp:Label runat="server" ID="lblName" Text='<%# Eval("Id") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadTextBox RenderMode="Lightweight" runat="server" Width="300px" ID="txbName" Text='<%# Eval("Url") %>'>
</telerik:RadTextBox>
<asp:RequiredFieldValidator ID="Requiredfieldvalidator1" runat="server" ControlToValidate="txbName"
ErrorMessage="Please, enter a name!" Display="Dynamic" SetFocusOnError="true"></asp:RequiredFieldValidator>
</EditItemTemplate>
<HeaderStyle Width="30%"></HeaderStyle>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn DataField="Url" HeaderText="Url" UniqueName="Url">
<ItemTemplate>
<telerik:RadBinaryImage runat="server" ID="RadBinaryImage1" ImageUrl='<%#Request.ApplicationPath + "/images/" + Eval("Url") %>'
AutoAdjustImageControlSize="false" Height="80px" Width="80px" ToolTip='<%#Eval("Url") %>'
AlternateText='<%#Eval("Url") %>'></telerik:RadBinaryImage>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadAsyncUpload RenderMode="Lightweight" runat="server" ID="AsyncUpload1"
AllowedFileExtensions="jpg,jpeg,png,gif" MaxFileSize="1048576">
</telerik:RadAsyncUpload>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="Status" Checked='<%# Convert.ToBoolean(Eval("Status")) %>' runat="server" AutoPostBack="true" />
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox runat="server" ID="Status" AutoPostBack="true" Checked='<%# Convert.ToBoolean(Eval("Status")) %>'></asp:CheckBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Title" UniqueName="Title">
<ItemTemplate>
<asp:Label runat="server" ID="lbltitle" Text='<%# Eval("Title") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadTextBox RenderMode="Lightweight" runat="server" Width="300px" ID="txtTitle" Text='<%# Eval("Title") %>'>
</telerik:RadTextBox>
</EditItemTemplate>
<HeaderStyle Width="30%"></HeaderStyle>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Album" UniqueName="Album">
<ItemTemplate>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%data source=cr-test-db01;initial catalog=CRAWebsite;User ID=sa;Password=P#ssword; Application Name=CRA; %>" SelectCommand="SELECT * FROM [dbo].[Album]"></asp:SqlDataSource>
<telerik:RadDropDownList RenderMode="Lightweight" runat="server" Width="300px" ID="ddlAlbums">
<Items>
<telerik:DropDownListItem runat="server" Text="A" Value="A" />
</Items>
</telerik:RadDropDownList>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadDropDownList RenderMode="Lightweight" runat="server" Width="300px" ID="ddlAlbums">
<Items>
<telerik:DropDownListItem runat="server" Text="A" Value="A" />
</Items>
</telerik:RadDropDownList>
</EditItemTemplate>
<HeaderStyle Width="30%"></HeaderStyle>
</telerik:GridTemplateColumn>
</Columns>
<EditFormSettings>
<EditColumn ButtonType="FontIconButton">
</EditColumn>
</EditFormSettings>
<PagerStyle AlwaysVisible="True"></PagerStyle>
</MasterTableView>
</telerik:RadGrid>
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridCommandItem)
{
GridCommandItem item = (GridCommandItem)e.Item;
var RadDropDownList = (RadDropDownList)item.FindControl("ddlAlbums");
(RadDropDownList)item.FindControl("ddlAlbums"); show null why ???
}
var albums = DBLayer.DbLayer.GetAlbums();
foreach (var item in albums.Tables[0].Rows)
{
}
foreach (DataRow row in albums.Tables[0].Rows)
{
DropDownListItem item2 = new DropDownListItem();
item2.Text = row["Content_Name_a"].ToString();
item2.DropDownList.DataTextField = row["Content_Name_a"].ToString();
item2.DropDownList.DataValueField = row["Id"].ToString();
}
}
You need to be sure its a item type, not command item
if((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
{
var RadDropDownList = (RadDropDownList)e.item.FindControl("ddlAlbums");
if(RadDropDownList != null)
{
//do what you need here
}
}
https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.datagrid.onitemdatabound?view=netframework-4.8

Checkbox in datgridview not refrashing page when checked

I am trying to follow this exemple https://www.aspsnippets.com/Articles/Transfer-Selected-Rows-from-one-GridView-to-Another-in-Asp.net.aspx however my version dose not refreash the page when a checkbox is checked why is that?
Here is my front end code,
<asp:GridView ID="gvPurchases" runat="server" AutoGenerateColumns="false" ShowFooter="true" onrowdatabound="gvPurchases_RowDataBound"
ShowHeaderWhenEmpty="true" AllowPaging="True" OnPageIndexChanging="gridView_PageIndexChanging" DataKeyNames="compras_id"
OnRowCommand="gvPurchases_RowCommand" OnRowEditing="gvPurchases_RowEditing" OnRowCancelingEdit="gvPurchases_RowCancelingEdit"
OnRowUpdating="gvPurchases_RowUpdating" CellPadding="3" AllowUserToResizeColumns="True" PageSize="5" AllowSorting="true" onsorting="gvPurchases_Sorting" GridLines="None" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt">
<PagerSettings Mode="Numeric" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkRow" AutoPostBack="true" EnableViewState="true" runat="server" onclick = "Check_Click(this)" OnCheckedChanged="CheckBox_CheckChanged" />
<%--<asp:CheckBox ID="chkRow" runat="server" />--%>
<asp:ImageButton ImageUrl="~/Images/edit.png" runat="server" CommandName="Edit" ToolTip="Edit" Width="20px" Height="20px"/>
<asp:ImageButton ImageUrl="~/Images/delete.png" runat="server" CommandName="Delete" ToolTip="Delete" Width="20px" Height="20px"/>
</ItemTemplate>
<EditItemTemplate>
<asp:ImageButton ImageUrl="~/Images/save.png" runat="server" CommandName="Update" ToolTip="Update" Width="20px" Height="20px"/>
<asp:ImageButton ImageUrl="~/Images/cancel.png" runat="server" CommandName="Cancel" ToolTip="Cancel" Width="20px" Height="20px"/>
</EditItemTemplate>
<FooterTemplate>
<asp:ImageButton ImageUrl="~/Images/addnew.png" runat="server" CommandName="AddNew" ToolTip="Add New" Width="20px" Height="20px"/>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Compras ID" SortExpression="compras_id">
<ItemTemplate>
<asp:Label DataField="compras_id" ID="lblPurschaseID" CssClass="gridTextbox" Text='<%# Eval("compras_id") %>' runat="server" />
</ItemTemplate>
<%--<EditItemTemplate>
<asp:TextBox CssClass="gridTextbox" ID="txtType" Text='<%# Eval("tipo") %>' runat="server" />
</EditItemTemplate>--%>
<FooterTemplate>
<asp:TextBox CssClass="gridTextbox" ID="txtPurschaseIDFooter" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Contract Number" >
<ItemTemplate>
<asp:Label DataField="numero_contrato" ID="lblContractNumber" CssClass="gridTextbox" Text='<%# Eval("numero_contrato") %>' runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="drGridContractID" Runat="server" AutoPostBack="false" OnSelectedIndexChanged="DropDown_SelectedIndexChanged" />
<%-- <asp:TextBox CssClass="gridTextbox" ID="txtSupplier" Text='<%# Eval("nombre_proveedor") %>' runat="server" />--%>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox CssClass="gridTextbox" ID="txtContractNumberFooter" runat="server" />
</FooterTemplate>
</asp:TemplateField>
And here is my backend:
protected void CheckBox_CheckChanged(object sender, EventArgs e)
{
GetData();
SetData();
BindSecondaryGrid();
}
However the page does not refresh when checkbox is checked why is that?
I had to remove onclick = "Check_Click(this)" to fix the proble the onClick is useless.
Change
<asp:CheckBox ID="chkRow" AutoPostBack="true" EnableViewState="true" runat="server" onclick = "Check_Click(this)" OnCheckedChanged="CheckBox_CheckChanged" />
to
<asp:CheckBox ID="chkRow" AutoPostBack="true" EnableViewState="true" runat="server" OnCheckedChanged="CheckBox_CheckChanged" />

I have a group of radio button in each row of the gridview. Base on the user selection of the radio button, I would like to update the database

I have a group of radio button in each row of the gridview. Base on the user selection of the radio button, I would like to update the database, when user click the Submit Button on the page. How do I reference those radio button in the code page?
source code
<asp:GridView ID="gvActList" runat="server" Font-Size="Smaller" Width="100%" CssClass="tableStyle"
EmptyDataText="No Data Found" AllowPaging="false"
CellPadding="4" AutoGenerateColumns="False" autopostback="true">
<FooterStyle Font-Bold="True" CssClass="tablefooter" />
<RowStyle CssClass="tableRow1" />
<SelectedRowStyle Font-Bold="True" CssClass="tableRowHighlight" />
<HeaderStyle Font-Bold="True" CssClass="tableHeader" Font-Size="9px" />
<Columns>
<asp:TemplateField HeaderText="TM Activity Code" HeaderStyle-HorizontalAlign="Center">
<ItemStyle Width="5%" HorizontalAlign="Left"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lbl_Activity_Code" runat="server" Visible="true" Text='<%# Bind("ACTIVITY_CODE") %>'></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description" HeaderStyle-HorizontalAlign="Center">
<ItemStyle Width="19%" HorizontalAlign="Left"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lbl_ACTDESC" runat="server" Text='<%# Bind("ACTIVITY_DESC") %>' Visible="true"></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="User Details" HeaderStyle-HorizontalAlign="Center">
<ItemStyle Width="5%"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lbl_User_Details" runat="server" Text='<%# Bind("CREATED_BY") %>' Visible="true"></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Type" HeaderStyle-HorizontalAlign="Center">
<ItemStyle Width="5%"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lbl_PROMO_TYPE" runat="server" Text='<%# Bind("PROMO_TYPE") %>' Visible="true"></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Category" HeaderStyle-HorizontalAlign="Center">
<ItemStyle Width="5%"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lblCatgDescription" runat="server" Text='<%# Bind("CATEGORY_CODE") %>'
Visible="true"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date Range" HeaderStyle-HorizontalAlign="Center">
<ItemStyle Width="5%"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lblACTIVEFROM" runat="server" Text='<%# Bind("ACTIVE_FROM") %>' Visible="true"></asp:Label>  To  
<asp:Label ID="lblACTIVETO" runat="server" Text='<%# Bind("ACTIVE_TO") %>' Visible="true"></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Activity Type" HeaderStyle-HorizontalAlign="Center">
<ItemStyle Width="5%"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lbl_Actvity_Type" runat="server" Text='<%# Bind("ACTIVITY_TYPE") %>' Visible="true"></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Current Status" HeaderStyle-HorizontalAlign="Center">
<ItemStyle Width="5%"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lbl_Current_Status" runat="server" Text='<%# Bind("status") %>' Visible="true"></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="View Details" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<itemstyle width="5%" />
<asp:LinkButton CssClass="l_link" Text="View" ID="lnkView" runat="server" ToolTip="View" /></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-HorizontalAlign="Center">
<HeaderTemplate>
<asp:Label ID="lblCap" Text="Confirm" runat="server"></asp:Label></HeaderTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<itemstyle width="1%" font-size="2px" horizontalalign="Center" />
<table style="text-align: Center; vertical-align: text-top;">
<tr>
<td style="width: 98%;">
<asp:RadioButton ID="rdYes" runat="server" Text="Yes" GroupName="CH"></asp:RadioButton></td>
</tr>
<tr>
<td style="width: 98%;">
<asp:RadioButton ID="rdNo" runat="server" Text="No" GroupName="CH"></asp:RadioButton></td>
</tr>
<tr>
<td style="width: 98%;">
<asp:RadioButton ID="rdNone" runat="server" Text="None" GroupName="CH"></asp:RadioButton></td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle CssClass="tableRowHighlight" />
<RowStyle CssClass="odd_tb" />
<PagerStyle CssClass="foot_tbl" />
<AlternatingRowStyle CssClass="even_tb" />
<PagerSettings Mode="NextPreviousFirstLast" />
</asp:GridView>
pls help me
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (gvActList.Rows.Count > 0)
{
foreach (GridViewRow row in gvActList.Rows)
{
RadioButton rdYes= (RadioButton)row.FindControl("rdYes");
RadioButton rdNo = (RadioButton)row.FindControl("rdNo");
RadioButton rdNone = (RadioButton)row.FindControl("rdNone");
if (rdYes != null && rdNo != null && rdNone != null)
{
if (rdYes.Checked == true)
{
//some code
}
else if (rdNo.Checked == true)
{
//some code
}
}
}
}
}
You can use above code on the button click. One suggestion is to use RadiobuttonList instead of RadioButton so that it will reduce the code.
on button click declare a gridview row. make a for loop and find the radio button in each row and other controls whose value you want to update. check the conditions as per your requirement and update accordingly

Problems with nested gridview

I am trying to design gridview inside gridview with insert update and delete but in this i cant insert record. Can anyone Help?
Here is database table
1) tbl_SShow(ShowTimeId{P-Auto inc.},TheatreId,MovieId,FromDate,ToDate)
2) tbl_Show(ShowID{P-Auto inc.},ShowTime,Silver,Gold, Platinum,ShowTimeId)
3) tbl_Theatre(TheatreId{P-Auto inc.}, TName, Taddress)
and here is aspx page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script language=javascript type="text/javascript">
function expandcollapse(obj,row)
{
var div = document.getElementById(obj);
var img = document.getElementById('img' + obj);
if (div.style.display == "none")
{
div.style.display = "block";
if (row == 'alt')
{
img.src = "minus.gif";
}
else
{
img.src = "minus.gif";
}
img.alt = "Close to view other Customers";
}
else
{
div.style.display = "none";
if (row == 'alt')
{
img.src = "plus.gif";
}
else
{
img.src = "plus.gif";
}
img.alt = "Expand to show Orders";
}
}
</script>
</head>
<body>
<form id="AddEventForm" runat="server">
<ul id="tabsmenu1" class="tabsmenu">
<li class="active">Add Show Time</li>
</ul>
<div class="form">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" BackColor="#f1f1f1"
AutoGenerateColumns=false DataSourceID="SqlDataSource1" DataKeyNames="MovieID"
GridLines=None OnRowDataBound="GridView1_RowDataBound"
OnRowCommand = "GridView1_RowCommand" OnRowUpdating = "GridView1_RowUpdating" BorderStyle=Outset
OnRowDeleting = "GridView1_RowDeleting" OnRowDeleted = "GridView1_RowDeleted"
OnRowUpdated = "GridView1_RowUpdated" AllowSorting=true
Width="80%" >
<RowStyle BackColor="Gainsboro" />
<AlternatingRowStyle BackColor="White" />
<HeaderStyle BackColor="#0083C1" ForeColor="White"/>
<FooterStyle BackColor="White" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<a href="javascript:expandcollapse('div<%# Eval("ShowTimeId") %>', 'one');">
<img id="imgdiv<%# Eval("ShowTimeId") %>" alt="Click to show/hide Orders for Customer <%# Eval("ShowTimeId") %>" width="9px" border="0" src="../images/plus.gif"/>
</a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Theatre Id" SortExpression="TheatreId">
<ItemTemplate>
<asp:Label ID="lblShowTimeId" Text='<%# Eval("ShowTimeId") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblShowTimeId" Text='<%# Eval("ShowTimeId") %>' runat="server"></asp:Label>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Theatre Id" SortExpression="TheatreId">
<ItemTemplate>
<asp:Label ID="lblTheatreId" Text='<%# Eval("TheatreId") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblTheatreId" Text='<%# Eval("TheatreId") %>' runat="server"></asp:Label>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlTheatre" runat="server" CssClass="form_input" AutoPostBack="True" TabIndex="1">
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Movie Id" SortExpression="MovieId">
<ItemTemplate><%# Eval("MovieId")%></ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlMovie" runat="server" CssClass="form_input" AutoPostBack="True" TabIndex="2">
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlMovie" runat="server" CssClass="form_input" AutoPostBack="True" TabIndex="2">
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="From Date" SortExpression="FromDate">
<ItemTemplate><%# Eval("FromDate")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtFromDate" Text='<%# Eval("FromDate") %>' runat="server"></asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/cal/calendar.gif" AlternateText="Click to show calendar" TabIndex="3" />
<asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtFromDate" Format="dd/MM/yyyy" PopupButtonID="ImageButton1">
</asp:CalendarExtender>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtFromDate" Text='' runat="server"></asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/cal/calendar.gif" AlternateText="Click to show calendar" TabIndex="3" />
<asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtFromDate" Format="dd/MM/yyyy" PopupButtonID="ImageButton1">
</asp:CalendarExtender>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="To Date" SortExpression="ToDate">
<ItemTemplate><%# Eval("ToDate")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtToDate" Text='<%# Eval("ToDate") %>' runat="server"></asp:TextBox>
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/cal/calendar.gif" AlternateText="Click to show calendar" TabIndex="3" />
<asp:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="txtToDate" Format="dd/MM/yyyy" PopupButtonID="ImageButton2">
</asp:CalendarExtender>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtToDate" Text='' runat="server"></asp:TextBox>
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/cal/calendar.gif" AlternateText="Click to show calendar" TabIndex="3" />
<asp:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="txtToDate" Format="dd/MM/yyyy" PopupButtonID="ImageButton2">
</asp:CalendarExtender>
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="Edit" ShowEditButton="True" />
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="linkDeleteShow" CommandName="Delete" runat="server">Delete</asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="linkAddShow" CommandName="AddShow" runat="server">Add</asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<tr>
<td colspan="100%">
<div id="div<%# Eval("ShowTimeId") %>" style="display:none;position:relative;left:15px;OVERFLOW: auto;WIDTH:97%" >
<asp:GridView ID="GridView2" AllowPaging="True" AllowSorting="true" BackColor="White" Width=100% Font-Size=X-Small
AutoGenerateColumns="false" Font-Names="Verdana" DataKeyNames="ShowTimeId" runat="server" ShowFooter="true"
OnPageIndexChanging="GridView2_PageIndexChanging" OnRowUpdating = "GridView2_RowUpdating" CssClass="Gridview"
OnRowCommand = "GridView2_RowCommand" OnRowEditing = "GridView2_RowEditing" GridLines=None
OnRowUpdated = "GridView2_RowUpdated" OnRowCancelingEdit = "GridView2_CancelingEdit" OnRowDataBound = "GridView2_RowDataBound"
OnRowDeleting = "GridView2_RowDeleting" OnRowDeleted = "GridView2_RowDeleted" OnSorting = "GridView2_Sorting"
BorderStyle=Double BorderColor="#0083C1">
<RowStyle BackColor="Gainsboro" />
<AlternatingRowStyle BackColor="White" />
<HeaderStyle BackColor="#0083C1" ForeColor="White"/>
<FooterStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Show ID" SortExpression="ShowID">
<ItemTemplate>
<asp:Label ID="lblShowID" Text='<%# Eval("ShowID") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblShowID" Text='<%# Eval("ShowID") %>' runat="server"></asp:Label>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ShowTime" SortExpression="ShowTime">
<ItemTemplate><%# Eval("ShowTime")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtShowTime" Text='<%# Eval("ShowTime")%>' runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtShowTime" Text='' runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Silver" SortExpression="Silver">
<ItemTemplate><%# Eval("Silver")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtSilver" Text='<%# Eval("Silver")%>' runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtSilver" Text='' runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Gold" SortExpression="Gold">
<ItemTemplate><%# Eval("Gold")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtGold" Text='<%# Eval("Gold")%>' runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtGold" Text='' runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Platinum" SortExpression="Platinum">
<ItemTemplate><%# Eval("Platinum")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtPlatinum" Text='<%# Eval("Platinum")%>' runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtPlatinum" Text='' runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="Edit" ShowEditButton="True" />
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="linkDeleteCust" CommandName="Delete" runat="server">Delete</asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="linkAddOrder" CommandName="AddShow" runat="server">Add</asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Event_MovieConnectionString %>"
SelectCommand="SELECT s.[ShowTimeId], s.[TheatreId], s.[MovieId], s.[FromDate], s.[ToDate], s.[Created],
s.[Modified] FROM [tbl_SShow] s ORDER BY s.[ShowTimeId]">
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
Please give me a solutions
Thanks.

Categories