One Button to update GridView - c#

I want to update all rows of a GridView one time by clicking one button:
aspx:
</asp:ObjectDataSource>
<asp:ListBox ID="ListBoxRoles" runat="server" DataSourceID="ObjectDataSourceAllRoles"
AutoPostBack="true" DataTextField="RoleName" DataValueField="RoleID"
OnSelectedIndexChanged="ListBoxRoles_SelectedIndexChanged">
</asp:ListBox>
<asp:ObjectDataSource ID="ObjectDataSourceRolePermissions" runat="server"
TypeName="RolePermission" SelectMethod="GetRolePermissionByRoleID"
UpdateMethod="UpdateRolePermission">
<SelectParameters>
<asp:ControlParameter ControlID="ListBoxRoles" Name="RoleID" PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:ControlParameter ControlID="ListBoxRoles" Name="RoleID" PropertyName="SelectedValue"
Type="String" />
</UpdateParameters>
</asp:ObjectDataSource>
<asp:GridView ID="GridViewRolePermission" SkinID="GridViewSecurity" runat="server" style="width: 100%;"
HeaderStyle-Height="50" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="ObjectDataSourceRolePermissions">
<Columns>
<asp:BoundField ItemStyle-HorizontalAlign="Center" DataField="PermissionName" SortExpression="PermissionName" />
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="CheckBoxRead" runat="server" Checked='<%#Bind("Read") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="CheckBoxUpdate" runat="server" Checked='<%#Bind("Update") %>' />
</ItemTemplate>
</asp:TemplateField>
</asp:GridView>
<asp:Button runat="server" ID="ButtonUpdateRolePermissions" Text="Save" OnClick="ButtonUpdateRolePermissions_Click" />
I want to update all rows of the gridview once the ButtonUpdateRolePermissions clicked.
I tried:
protected void ButtonupdateRolePermissions_Click(object sender, EventArgs e)
{
foreach(GridViewRow RolePermission in this.GridViewRolePermission.Rows)
{
this.ObjectDataSourceRolePermissions.Update();
}
}
but the update method not take Update and Read fields into consideration.

Related

How to take ID of a row in gridview when you press a button in a row

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyNames="IDProject" DataSourceID="SqlDataSource1" GridLines="Vertical" style="margin-top:2rem" Width="1056px">
<AlternatingRowStyle BackColor="#DCDCDC" />
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:TemplateField SortExpression="ProjectLeader" HeaderText="Project Leader">
<ItemTemplate>
<asp:Label Text='<%# Bind("ProjectLeader") %>' ID="lvProjectLeader" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ProjectName" HeaderText="Project Name" SortExpression="ProjectName" />
<asp:TemplateField HeaderText="Start date:" SortExpression="StartDate">
<ItemTemplate>
<asp:Label Text='<%# Bind("StartDate") %>' ID="lbStartDate" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Client Name" SortExpression="Client name">
<ItemTemplate>
<asp:Label Text='<%# Bind("Client name") %>' ID="lbClientName" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Employees">
<ItemTemplate>
<asp:Button Text="Open" ID="EmployeesOpen" OnClick="EmployeesOpen_Click" runat="server" CssClass="btn btn-outline-primary" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
InsertCommand="Insert into Project values(#ProjectName, #ClientID,#ProjectLeader,#StartDate)"
SelectCommand="select IDProject, ProjectLeader, ProjectName, StartDate, ClientID, Client.Name from Project inner join Client on IDClient = ClientID"
UpdateCommand="Update Project set ProjectName = #ProjectName where IDProject = #IDProject">
<InsertParameters>
<asp:Parameter Name="ProjectName" />
<asp:Parameter Name="ClientID" />
<asp:Parameter Name="ProjectLeader" />
<asp:Parameter Name="StartDate" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="ProjectName" />
<asp:Parameter Name="IDProject" />
</UpdateParameters>
</asp:SqlDataSource>
I made a gridview table for Projects which has values ProjectName, ClientID, ProjectLeader, StartDate and all the employees that work on that Project. Since i cant fit all the employees that work on a single project inside a small table i made a button inside that column that redirects you to another page where you can see table with all the employees. The employees are in another table in sql and i made third table which connects Projects and employees and it only contains ProjectID and EmployeeID. I have a button inside every row but i cant find a way how to make in code behind so that it takes the id of that project and prints on another page only employees that are working on that project.
public partial class Project : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void EmployeesOpen_Click(object sender, EventArgs e)
{
Response.Redirect("Employees_On_Project.aspx");
}
}
You will find what you are looking for here : https://forums.asp.net/t/1957409.aspx?Gridview+get+SelectedRow+in+button+click+event

DetailsView OnUpdating TextBox not returning new text ASP.NET C#

I have a DetailsView and a SqlDataSource as below. The NotesTB and the NameTB are not null in the code behind but are not retaining the new values entered in. They are returning the old values binded originally. I have searched the internet and can not find the reason for this and it is perplexing me.
<asp:DetailsView ID="PhotoDetailsDV" runat="server" Height="50px" Width="125px" DefaultMode="Edit" AutoGenerateRows="False" DataKeyNames="PhotoID" DataSourceID="XXXXXXXXXX" OnDataBound="PhotoDetailsDV_DataBound" OnItemUpdating="PhotoDetailsDV_ItemUpdating1" >
<Fields>
<asp:TemplateField HeaderText="Notes" SortExpression="Notes">
<EditItemTemplate>
<asp:TextBox ID="NotesTB" runat="server" Text='<%# Bind("Notes") %>'></asp:TextBox>
<asp:HiddenField runat="server" ID="PhotoIdHF" Value='<%# Bind("PhotoID") %>'/>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="NotesLabel" runat="server" Text='<%# Bind("Notes") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name" SortExpression="Name">
<EditItemTemplate>
<asp:TextBox ID="NameTB" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource runat="server" ID="XXXXX" ConnectionString="<%$ ConnectionStrings:XXXXXXXXXXXXXXX %>" SelectCommand="SELECT [Notes], Photoid, [Name] FROM [XXXXXXXX] WHERE ([FileID] = #FileID)" UpdateCommand="UPDATE [XXXXXXX] SET [Notes] = #Notes, [Name] = #Name WHERE [PhotoID] = #PhotoID">
<SelectParameters>
<asp:Parameter Name="FileID" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Notes" Type="String" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="PhotoID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
My code behind is as follows
protected void PhotoDetailsDV_ItemUpdating1(object sender, DetailsViewUpdateEventArgs e)
{
TextBox NameTB = (TextBox) PhotoDetailsDV.FindControl("NameTB");
TextBox NotesTB = (TextBox) PhotoDetailsDV.FindControl("NotesTB");
e.NewValues["Notes"] = NotesTB.Text;//here NotesTB.Text is "" even when something is entered or it is the old value
e.NewValues["Name"] = NameTB.Text;//here NameTB.Text is "" even when something is entered or it is the old value
}
the code your bind data to your detailview, do you use a not is postback condition to make sure it will not re-bind the data after postback?

Edit button and next page link button on same gridview row

I have a gridview control on page data is showing perfectly fine. I add edit button in row to update record its also working fine until I add another link in next column which redirect me to new page.
Here is my Gridview code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1" DataSourceID="SqlDataSource1" GridLines="None" DataKeyNames="issue_id,pro_id" OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:TemplateField HeaderText="Key#" InsertVisible="False" SortExpression="issue_id">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("issue_id") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="view" CommandArgument ='<%# Eval("issue_id") %>' Text='<%# Eval("issue_id") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="pro_id" HeaderText="pro_id" SortExpression="pro_id" ReadOnly="True" Visible="False" />
<asp:BoundField DataField="name" HeaderText="Project Name" SortExpression="name" />
<asp:BoundField DataField="type" HeaderText="Issue Type" SortExpression="type" />
<asp:BoundField DataField="summary" HeaderText="Summary" SortExpression="summary" />
<asp:BoundField DataField="mem_id" HeaderText="Member Name" SortExpression="mem_id" />
<asp:TemplateField HeaderText="Priority" SortExpression="priority">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Major</asp:ListItem>
<asp:ListItem>Critical</asp:ListItem>
<asp:ListItem>Minor</asp:ListItem>
<asp:ListItem>Cosmetic</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("priority") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="status" HeaderText="Status" SortExpression="status" />
<asp:BoundField DataField="impact" HeaderText="Impact" SortExpression="impact" />
<asp:BoundField DataField="Expr1" HeaderText="Submit Date" ReadOnly="True" SortExpression="Expr1" />
</Columns>
<FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
<PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#DEDFDE" ForeColor="Black" />
<SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#594B9C" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#33276A" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:IHDConnectionString %>"
SelectCommand="SELECT issue.issue_id, issue.pro_id, project.name, issue.type, issue.summary, issue.mem_id, issue.priority, issue.status, issue.impact, CONVERT (date, GETDATE()) AS Expr1 FROM issue INNER JOIN project ON issue.pro_id = project.pro_id"
UpdateCommand="UPDATE [issue] SET [mem_id] = #mem_id, [priority] = #priority, [status] = #status WHERE [issue_id] = #issue_id AND [pro_id] = #pro_id"
<UpdateParameters>
<asp:Parameter Name="mem_id" Type="String" />
<asp:Parameter Name="priority" Type="String" />
<asp:Parameter Name="status" Type="String" />
<asp:Parameter Name="issue_id" Type="Int32" />
<asp:Parameter Name="pro_id" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
here is my redirect page control
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
Response.Redirect("~/redirect.aspx?view=" + e.CommandArgument);
}
Now problem is when I click edit it redirect me to another while it is suppose to edit the record in same page.
Change your Row_Command to this
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if(e.CommandName.ToString() == "view")
{
Response.Redirect("~/redirect.aspx?view=" + e.CommandArgument);
}
}
I would recommend using a link when you need a link, you don't need to do postback to "redirect" the user:
<asp:TemplateField HeaderText="Key#" InsertVisible="False" SortExpression="issue_id">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("issue_id") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<a href='redirect.aspx?view=<%# Eval("issue_id") %>'><%# Eval("issue_id") %></a>
</ItemTemplate>
</asp:TemplateField>

How to change the data in a asp gridlist on click with UserControls?

I'm trying to change the data of my gridlist on my homepage when you click on a button.. Tried many things nothing works. When I press the button to change gridview data nothing happpens and few secons later I get a error
How it looks: http://prntscr.com/7fa9qh
The Error : http://prntscr.com/7faam0
I have left some code out to make it not all to big, like I only have 2 buttons in code but there are more
list.aspx.cs :
protected void Page_Load(object sender, EventArgs e) {
GvTop2000 usercontrol = (GvTop2000)Page.LoadControl("~/Pages /Usercontrols/ListGv/GvTop2000.ascx");
pnlGVList.ContentTemplateContainer.Controls.Add(usercontrol);
}
protected void btnTop2000_Click(object sender, EventArgs e) {
pnlGVList.ContentTemplateContainer.Controls.Clear();
GvTop2000 usercontrol = (GvTop2000)Page.LoadControl("~/Pages/Usercontrols/ListGv/GvTop2000.ascx");
pnlGVList.ContentTemplateContainer.Controls.Add(usercontrol);
pnlGVList.Update();
}
protected void btnNieuw_Click(object sender, EventArgs e) {
pnlGVList.ContentTemplateContainer.Controls.Clear();
GvNieuw usercontrol = (GvNieuw)Page.LoadControl("~/Pages/Usercontrols/ListGv/GvNieuw.ascx");
pnlGVList.ContentTemplateContainer.Controls.Add(usercontrol);
pnlGVList.Update();
}
list.aspx :
<asp:Content ID="ContentHolderDD" runat="server" ContentPlaceHolderID="ContentHolderDD">
<asp:ScriptManagerProxy ID="smProxy" runat="server" />
<%-- Year selector --%>
<asp:DropDownList ID="ddlJaar" CssClass="ddl" runat="server" DataSourceID="DSYears" DataTextField="top2000jaar" DataValueField="top2000jaar" AutoPostBack="True" />
<asp:SqlDataSource runat="server" ID="DSYears" ConnectionString='<%$ ConnectionStrings:TOP2000_IAO4A_GROEP2ConnectionString %>' SelectCommand="sp_get_year" SelectCommandType="StoredProcedure" />
</asp:Content>
<asp:Content ID="ContentPlaceholderButtons" runat="server" ContentPlaceHolderID="ContentPlaceholderButtons">
gvTop2000 usercontrol:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="GvTop2000.ascx.cs" Inherits="Top2000.Pages.Usercontrols.ListGv.GvTop2000" %>
<asp:GridView runat="server" ID="gridList" CellPadding="10" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" DataSourceID="DSList" AllowPaging="True" PageSize="100" CssClass="GridListings">
<Columns>
<asp:BoundField DataField="positie" HeaderText="Positie" SortExpression="positie"></asp:BoundField>
<asp:HyperLinkField DataNavigateUrlFields="artiestid" DataNavigateUrlFormatString="Artists.aspx?id={0}" DataTextField="naam" HeaderText="Artiest" />
<asp:HyperLinkField DataNavigateUrlFields="songid" DataNavigateUrlFormatString="Song.aspx?id={0}" DataTextField="titel" HeaderText="Titel" />
<asp:BoundField DataField="jaar" HeaderText="Jaar" SortExpression="jaar"></asp:BoundField>
</Columns>
</asp:GridView>
<asp:SqlDataSource runat="server" ID="DSList" ConnectionString='<%$ ConnectionStrings:TOP2000_IAO4A_GROEP2ConnectionString %>' SelectCommand="sp_top2000_year" SelectCommandType="StoredProcedure" >
<SelectParameters>
<asp:ControlParameter PropertyName="SelectedValue" DefaultValue="" Name="YEAR" Type="Int32" ControlID="ContentHolderDD$ddlJaar" />
</SelectParameters>
</asp:SqlDataSource>
<asp:UpdatePanel runat="server" ID="pnlCButtons">
<ContentTemplate>
<asp:Button ID="btnTop2000" runat="server" Text="Top2000" OnClick="btnTop2000_Click" />
<asp:Button ID="btnNieuw" runat="server" Text="Nieuw" OnClick="btnNieuw_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
<asp:Content id="ContentPlaceHolder1" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
<%-- GridView --%>
<asp:UpdatePanel ID="pnlGVList" runat="server">
<ContentTemplate>
<asp:PlaceHolder runat="server" ID="phGv"/>
</ContentTemplate>
</asp:UpdatePanel>
gvNieuw usercontrol :
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="GvNieuw.ascx.cs" Inherits="Top2000.Pages.Usercontrols.ListGv.GvNieuw" %>
<asp:GridView runat="server" ID="gridList" CellPadding="10" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" DataSourceID="sqlDS" AllowPaging="True" PageSize="100" CssClass="GridListings" DataKeyNames="songid,top2000jaar,songid1,artiestid1">
<Columns>
<asp:BoundField DataField="songid" HeaderText="songid" SortExpression="songid" ReadOnly="True"></asp:BoundField>
<asp:BoundField DataField="top2000jaar" HeaderText="top2000jaar" SortExpression="top2000jaar" ReadOnly="True"></asp:BoundField>
<asp:BoundField DataField="positie" HeaderText="positie" SortExpression="positie" />
<asp:BoundField DataField="songid1" HeaderText="songid1" InsertVisible="False" ReadOnly="True" SortExpression="songid1" />
<asp:BoundField DataField="artiestid" HeaderText="artiestid" SortExpression="artiestid" />
<asp:BoundField DataField="titel" HeaderText="titel" SortExpression="titel" />
<asp:BoundField DataField="jaar" HeaderText="jaar" SortExpression="jaar" />
<asp:BoundField DataField="artiestid1" HeaderText="artiestid1" InsertVisible="False" ReadOnly="True" SortExpression="artiestid1" />
<asp:BoundField DataField="naam" HeaderText="naam" SortExpression="naam" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="sqlDS" runat="server" ConnectionString="<%$ ConnectionStrings:TOP2000_IAO4A_GROEP2ConnectionString %>" SelectCommand="sp_new_songs_year" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="ContentHolderDD$ddlJaar" Name="top2000Year" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>

Gridview not updating value

I am trying to make my gridview update a SQL record but it is not updating the values.
Here is the aspx code:
<asp:GridView ID="GridView1" runat="server" GridLines="None" AutoGenerateColumns="false"
onrowcancelingedit="GridView1_RowCancelling"
OnRowDeleting ="GridView1_RowDeleting"
onrowediting="GridView1_RowEditing"
onrowupdating="GridView1_RowUpdating"
DataKeyNames="RID"
CssClass="mGrid"
PagerStyle-CssClass="pgr"
AlternatingRowStyle-CssClass="alt">
<Columns>
<asp:TemplateField Visible="false" HeaderText="RID">
<ItemTemplate>
<asp:Label runat="server" ID="RID" Text='<%#Bind("RID")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Short Description">
<ItemTemplate>
<asp:Label runat="server" ID="short_lbl" Text='<%#Bind("SHORT_DESCRIPTION") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="SHORT_DESCRIPTION" Text='<%#Bind("SHORT_DESCRIPTION") %>' />
<asp:RequiredFieldValidator runat="server" ID="valShort" ControlToValidate="SHORT_DESCRIPTION" ValidationGroup="var1" ErrorMessage="*" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:Label runat="server" ID="desc_label" Text='<%#Bind("DESCRIPTION") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="DESCRIPTION" Text='<%#Bind("DESCRIPTION") %>' />
<asp:RequiredFieldValidator runat="server" ID="valLast" ControlToValidate="DESCRIPTION" ValidationGroup="var1" ErrorMessage="*" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:LinkButton ID="btnEdit" Text="Edit" runat="server" CommandName="Edit" />
<br />
<asp:LinkButton ID="btnDelete" Text="Delete" runat="server" CommandName="Delete" />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="btnUpdate" Text="Update" runat="server" CommandName="Update" />
<asp:LinkButton ID="btnCancel" Text="Cancel" runat="server" CommandName="Cancel" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
And the update function itself.
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string s = GridView1.DataKeys[e.RowIndex].Value.ToString();
Label RID = GridView1.Rows[e.RowIndex].FindControl("RID") as Label;
TextBox SHORT_DESCRIPTION = GridView1.Rows[e.RowIndex].FindControl("SHORT_DESCRIPTION") as TextBox;
TextBox DESCRIPTION = GridView1.Rows[e.RowIndex].FindControl("DESCRIPTION") as TextBox;
String UpdateQuery = string.Format("UPDATE TAXONOMIES SET SHORT_DESCRIPTION='{0}', DESCRIPTION='{1}' WHERE RID = {2}", SHORT_DESCRIPTION.Text, DESCRIPTION.Text, Convert.ToInt32(RID.Text));
GridView1.EditIndex = -1;
BindGridData(UpdateQuery);
}
If I put a breakpoint and look at the value, I can see that is is not the newly typed in value. I'm not sure what is going on.
I think the problem is you are binding you grid on the page-load event.
try binding it in if (!IsPostBack)
Example
private void Page_Load()
{
if (!IsPostBack)
{
//bind your grid here.
}
}
use this code
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="id" DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="id" HeaderText="id" ReadOnly="True"
SortExpression="id" />
<asp:BoundField DataField="regGroupID" HeaderText="regGroupID"
SortExpression="regGroupID" />
<asp:BoundField DataField="amountReceived" HeaderText="amountReceived"
SortExpression="amountReceived" />
<asp:BoundField DataField="other" HeaderText="other" SortExpression="other" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [Table]"
UpdateCommand="UPDATE [Table] SET [regGroupID] = #regGroupID, [amountReceived] = #amountReceived, [other] = #other WHERE [id] = #id">
<DeleteParameters>
<asp:Parameter Name="id" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="regGroupID" Type="Int32" />
<asp:Parameter Name="amountReceived" Type="Decimal" />
<asp:Parameter Name="other" Type="String" />
<asp:Parameter Name="id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
here I set id as the primary key
table structure is
Try changing the Eval to Bind. Eval is read-only so you can't actually update the value.

Categories

Resources