I have a gridview where the data it shows depends on the textbox and button control. Since the gridview doesnt show anything (unless a user typed an input in the textbox) how can I fill it with all data from the tables? I'm thinking of inserting another gridview inside of the EmptyDataTemplate but is there any way I could show all the records even without user input?
Just started in ASP.NET so I really need your help guys.
Thanks in advance ;)
Here's my code sample:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="lenid" DataSourceID="returningDataSource" ForeColor="#333333"
GridLines="None">
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:CommandField HeaderStyle-Width="120px" ButtonType="Button" ShowEditButton="True" ShowDeleteButton="True" />
<asp:BoundField DataField="bookid" HeaderText="Book ID/ISBN"
SortExpression="bookid" />
<asp:BoundField DataField="booktitle" HeaderText="Title"
SortExpression="booktitle" />
<asp:BoundField DataField="EmployeeID" HeaderText="Employee ID"
SortExpression="EmployeeID" />
<asp:BoundField DataField="department" HeaderText="Department"
SortExpression="department" />
<asp:BoundField DataField="dateborrowed" HeaderText="Date borrowed"
SortExpression="dateborrowed" />
<asp:BoundField DataField="datereturned" HeaderText="Date returned"
SortExpression="datereturned" NullDisplayText="-- not yet returned --" />
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<EmptyDataTemplate>
<asp:GridView ID="GridView2" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="lenid" DataSourceID="returningDataSource" ForeColor="#333333"
GridLines="None">
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:CommandField HeaderStyle-Width="120" ButtonType="Button" ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="bookid" HeaderText="Book ID/ISBN"
SortExpression="bookid" />
<asp:BoundField DataField="booktitle" HeaderText="Title"
SortExpression="booktitle" />
<asp:BoundField DataField="EmployeeID" HeaderText="Employee ID"
SortExpression="EmployeeID" />
<asp:BoundField DataField="department" HeaderText="Department"
SortExpression="department" />
<asp:BoundField DataField="dateborrowed" HeaderText="Date borrowed"
SortExpression="dateborrowed" />
<asp:BoundField DataField="datereturned" HeaderText="Date returned"
SortExpression="datereturned" NullDisplayText="-- not yet returned --" />
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="returningDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
DeleteCommand="DELETE FROM [LendTable] WHERE [lenid] = #lenid"
InsertCommand="INSERT INTO [LendTable] ([bookid], [EmployeeID], [department], [dateborrowed], [datereturned]) VALUES (#bookid, #EmployeeID, #department, #dateborrowed, #datereturned)"
SelectCommand="SELECT dbo.LendTable.lenid, dbo.LendTable.bookid, dbo.LendTable.EmployeeID, dbo.LendTable.department, dbo.LendTable.dateborrowed, dbo.LendTable.datereturned, dbo.TblBooks.booktitle FROM dbo.LendTable INNER JOIN dbo.TblBooks ON dbo.LendTable.bookid = dbo.TblBooks.bookid"
UpdateCommand="UPDATE [LendTable] SET [bookid] = #bookid, [EmployeeID] = #EmployeeID, [department] = #department, [dateborrowed] = #dateborrowed, [datereturned] = #datereturned WHERE [lenid] = #lenid">
<DeleteParameters>
<asp:Parameter Name="lenid" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="bookid" Type="Int64" />
<asp:Parameter Name="EmployeeID" Type="String" />
<asp:Parameter Name="department" Type="String" />
<asp:Parameter Name="dateborrowed" Type="DateTime" />
<asp:Parameter Name="datereturned" Type="DateTime" />
<asp:Parameter Name="lenid" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="bookid" Type="Int64" />
<asp:Parameter Name="EmployeeID" Type="String" />
<asp:Parameter Name="department" Type="String" />
<asp:Parameter Name="dateborrowed" Type="DateTime" />
<asp:Parameter Name="datereturned" Type="DateTime" />
</InsertParameters>
</asp:SqlDataSource>
</EmptyDataTemplate>
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
I want to display all the records from a table if a user doesn't type any input (or fill the EmptyDataTemplate with records from the database).
Thanks again!
Execute the Select command of the returning data source as its gonna return the entire rows od the table and bind to the original grid in the (!IsPostBack) of the page_load and next time when you need to bind data based on text box input execute the query and bind the data to same grid.
Related
I'm trying to create a GridView to display the contents of a table on my database. I want the user to be able to edit only one of the columns, so I set every other one to read only. When I test this, I can only edit the one column, like intended, but after updating, the other columns become null and post to the database. I don't know how to stop this from happening. Here is my code for the GridView. It is bound with one of Visual Studio's SQLDataSources.
I tried to create several events including RowEditing, RowUpdated, and RowUpdating, but with no luck. Nothing would stop the non-edited fields from getting replaced with NULL.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" Align="center" Height="138px" Width="548px" BorderColor="#6600FF" BorderStyle="Ridge" HorizontalAlign="Center" DataKeyNames="Id" DataSourceID="SqlDataSource1" >
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" Visible="False" />
<asp:BoundField DataField="PhoneName" HeaderText="PhoneName" SortExpression="PhoneName" ReadOnly="True" />
<asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="Amount" />
<asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" ReadOnly="True" />
<asp:BoundField DataField="TotalPrice" HeaderText="TotalPrice" SortExpression="TotalPrice" ReadOnly="True" />
</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="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
Edit: I found a working solution by changing the SQLDataSource's Update Query String to set the unchangeable categories to their original values and leaving the one changeable field to a parameter. I'll post the code for that here.
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="*connection string here*" ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [Cart]" DeleteCommand="DELETE FROM [Cart] WHERE [Id] = #original_Id" InsertCommand="INSERT INTO [Cart] ([PhoneName], [Amount], [Price], [TotalPrice]) VALUES (#PhoneName, #Amount, #Price, #TotalPrice)" OldValuesParameterFormatString="original_{0}" UpdateCommand="UPDATE [Cart] SET [PhoneName] = PhoneName, [Amount] = #Amount, [Price] = Price, [TotalPrice] = TotalPrice WHERE [Id] = #original_Id" DataSourceMode="DataReader">
<DeleteParameters>
<asp:Parameter Name="original_Id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="PhoneName" Type="String" />
<asp:Parameter Name="Amount" Type="Int32" />
<asp:Parameter Name="Price" Type="String" />
<asp:Parameter Name="TotalPrice" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="PhoneName" Type="String" />
<asp:Parameter Name="Amount" Type="Int32" />
<asp:Parameter Name="Price" Type="String" />
<asp:Parameter Name="TotalPrice" Type="String" />
<asp:Parameter Name="original_Id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
I've got a GridView who's DataSource SELECTs based on the SelectedValue of another GridView.
On the GridView with the SelectedValue (DataKeyName), I need to execute the Select command when the grid loads, rather that using a "Select" button.
I've tried using the SelectedIndex attribute of the GridView but this wont do it for me.
I've also looked at various methods and events but I cant seem to find a good way of doing this.
In the code below, there is a ButtonField with a "Select" button but I would like the Select command to take place as or after the grid is populated.
Thanks in advance.
<asp:GridView ID="ClientDetailsGridView" runat="Server" AutoGenerateColumns="False" DataKeyNames="AccountNumber" DataSourceID="ZeNetAccounts" CellPadding="2" ForeColor="#333333" GridLines="None" Width="749px">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:ButtonField ButtonType="Button" CommandName="Select" HeaderText="More Information" Text="View" />
<asp:BoundField DataField="AccountNumber" HeaderText="Account #" SortExpression="AccountNumber" />
<asp:BoundField DataField="AccountName" HeaderText="Client Name" SortExpression="AccountName" />
<asp:BoundField DataField="Address1" HeaderText="Address" SortExpression="Address1" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
<asp:BoundField DataField="PostalCode" HeaderText="Zip" SortExpression="PostalCode" />
<asp:BoundField DataField="PrimaryPhoneNumberFormatted" HeaderText="Phone" SortExpression="PrimaryPhoneNumberFormatted" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="Transparent" Font-Bold="True" ForeColor="White" Height="25px" CssClass="GridHeaderBasic" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="Transparent" Font-Bold="True" ForeColor="#333333" Height="25px" CssClass="GridDataRows" />
<SelectedRowStyle BackColor="Transparent" Font-Bold="True" ForeColor="#333333" Height="25px" CssClass="GridDataRows" />
<SortedAscendingCellStyle BackColor="Transparent" Font-Bold="True" ForeColor="#333333" Height="25px" CssClass="GridDataRows" />
<SortedAscendingHeaderStyle BackColor="Transparent" Font-Bold="True" ForeColor="#333333" Height="25px" CssClass="GridDataRows" />
<SortedDescendingCellStyle BackColor="Transparent" Font-Bold="True" ForeColor="#333333" Height="25px" CssClass="GridDataRows" />
<SortedDescendingHeaderStyle BackColor="Transparent" Font-Bold="True" ForeColor="#333333" Height="25px" CssClass="GridDataRows" />
</asp:GridView>
<br />
<br />
<asp:GridView ID="CustomFieldsGridView" runat="server" AutoGenerateColumns="False" SelectedIndex="0" DataKeyNames="DocumentNumber,DocumentType,CustomFieldDefinitionKeyID" DataSourceID="ZeNetCustomFields">
<Columns>
<asp:BoundField DataField="DocumentNumber" HeaderText="DocumentNumber" ReadOnly="True" SortExpression="DocumentNumber" />
<asp:BoundField DataField="DocumentType" HeaderText="DocumentType" ReadOnly="True" SortExpression="DocumentType" />
<asp:BoundField DataField="CustomFieldDefinitionKeyID" HeaderText="CustomFieldDefinitionKeyID" ReadOnly="True" SortExpression="CustomFieldDefinitionKeyID" />
<asp:BoundField DataField="CustomFieldValue" HeaderText="CustomFieldValue" SortExpression="CustomFieldValue" />
</Columns>
</asp:GridView>
<br />
<asp:SqlDataSource ID="ZeNetAccounts" runat="Server" ConnectionString="<%$ ConnectionStrings:Ze-Net_Technologies %>"
SelectCommand="SELECT * FROM [tblAccounts] WHERE ([AccountName] = #AccountName)">
<SelectParameters>
<asp:ControlParameter ControlID="ClientSearch" Name="AccountName" PropertyName="Text" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="ZeNetCustomFields" runat="Server" ConnectionString="<%$ ConnectionStrings:Ze-Net_Technologies %>"
SelectCommand="SELECT * FROM [tblCustomFieldValues] WHERE ([DocumentNumber] = #DocumentNumber)">
<SelectParameters>
<asp:ControlParameter ControlID="ClientDetailsGridView" Name="DocumentNumber" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
One of the fields in my database could have hundreds or even thousands of words. I want to know how to make the edit button in gridview work as an action event but also turn the rest of its automatic functions off. What I mean is I don't want the the actual cells editable in the table and I don't want the update and cancel button to become visible.
Here is the gridview:
<asp:Panel ID="updatePanel" runat="server" Visible="false">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource4"
AllowPaging="True" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None"
BorderWidth="1px" CellPadding="3" CellSpacing="2" OnRowDeleting="GridView1_OnRowDeleting" OnRowEditing="GridView1_OnRowEditing"
DataKeyNames="PK_DailyTaskHours, PK_NonScrumStory">
<Columns>
<asp:BoundField DataField="Catagory" HeaderText="Support Catagory" SortExpression="Catagory" />
<asp:BoundField DataField="AppName" HeaderText="Application Name" SortExpression="IncidentNumber" />
<asp:BoundField DataField="IncidentNumber" HeaderText="Incident #" SortExpression="IncidentNumber" />
<asp:BoundField DataField="Hours" HeaderText="Hours" SortExpression="Hours" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
<asp:BoundField DataField="CreatedDate" HeaderText="Created Date" SortExpression="CreatedDate" />
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FFF1D4" />
<SortedAscendingHeaderStyle BackColor="#B95C30" />
<SortedDescendingCellStyle BackColor="#F1E5CE" />
<SortedDescendingHeaderStyle BackColor="#93451F" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
SelectCommand="SELECT [NonScrumStory].[IncidentNumber], [NonScrumStory].[Description], [NonScrumStory].[CreatedDate],
[DailyTaskHours].[Hours], [Application].[AppName], [SupportCatagory].[Catagory], [DailyTaskHours].[PK_DailyTaskHours],
[NonScrumStory].[PK_NonScrumStory] FROM [NonScrumStory], [DailyTaskHours], [Application], [SupportCatagory] WHERE
([NonScrumStory].[UserId] = #userIdSelected) AND ([NonScrumStory].[PK_NonScrumStory] = [DailyTaskHours].[NonScrumStoryId])
AND ([NonScrumStory].[CatagoryId] = [SupportCatagory].[PK_SupportCatagory]) AND
([NonScrumStory].[ApplicationId] = [Application].[PK_Application]) AND ([NonScrumStory].[Deleted] != 1)"
DeleteCommand="UPDATE [NonScrumStory] SET [Deleted] = 1 WHERE (PK_NonScrumStory = #nonScrumStoryPK);
UPDATE [DailyTaskHours] SET [Deleted] = 1 WHERE (PK_DailyTaskHours = #dailyTaskHoursPK); ">
<SelectParameters>
<asp:QueryStringParameter Name="userIdSelected" Type="String" />
</SelectParameters>
<DeleteParameters>
<asp:QueryStringParameter Name="dailyTaskHoursPK" Type="String" />
<asp:QueryStringParameter Name="nonScrumStoryPK" Type="String" />
</DeleteParameters>
</asp:SqlDataSource>
Additionally, I have the action event working:
protected virtual void GridView1_OnRowEditing(object sender, GridViewEditEventArgs e)
{
}
And I know using ReadOnly="false" prevents the cells from becoming editable. How do I get rid of the update / cancel? Is it possible to execute cancel immediately so the user doesn't see the change?
When the user pressed edit, the panel showing the gridview will become invisible and a new panel will appear with edit options.
I'm writing an web-app that keeps track of deadlines. With this app you have to be able to update records that are being saved in an SQL DB.
However I'm having some problem with my update in my aspx-file.
<asp:GridView ID="gv_editMilestones" runat="server" DataSourceID="sql_ds_milestones"
CellPadding="4" ForeColor="#333333" GridLines="None" Font-Size="Small"
AutoGenerateColumns="False" DataKeyNames="id" Visible="false"
onrowupdated="gv_editMilestones_RowUpdated"
onrowupdating="gv_editMilestones_RowUpdating"
onrowediting="gv_editMilestones_RowEditing">
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="id" HeaderText="id" SortExpression="id"
ReadOnly="True" Visible="false"/>
<asp:BoundField DataField="ms_id" HeaderText="ms_id"
SortExpression="ms_id" ReadOnly="True"/>
<asp:BoundField DataField="ms_description" HeaderText="ms_description"
SortExpression="ms_description"/>
<%-- <asp:BoundField DataField="ms_resp_team" HeaderText="ms_resp_team"
SortExpression="ms_resp_team"/>--%>
<asp:TemplateField HeaderText="ms_resp_team" SortExpression="ms_resp_team">
<ItemTemplate>
<%# Eval("ms_resp_team") %>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="DDL_ms_resp_team" runat="server"
DataSourceID="sql_ds_ms_resp_team" DataTextField="team_name"
DataValueField="id">
<%--SelectedValue='<%# Bind("ms_resp_team") %>'--%>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ms_focal_point" HeaderText="ms_focal_point"
SortExpression="ms_focal_point" />
<asp:BoundField DataField="ms_exp_date" HeaderText="ms_exp_date"
SortExpression="ms_exp_date" DataFormatString="{0:d}"/>
<asp:BoundField DataField="ms_deal" HeaderText="ms_deal"
SortExpression="ms_deal" ReadOnly="True"/>
<asp:CheckBoxField DataField="ms_active" HeaderText="ms_active"
SortExpression="ms_active"/>
</Columns>
<FooterStyle BackColor="#CCCC99" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#999999" />
</asp:GridView>
<asp:SqlDataSource ID="sql_ds_milestones" runat="server"
ConnectionString="<%$ ConnectionStrings:testServer %>"
SelectCommand="SELECT [id]
,[ms_id]
,[ms_description]
,(SELECT [team_name] FROM [NSBP].[dbo].[tbl_teams] as teams
WHERE milestones.[ms_resp_team] = teams.[id]) as 'ms_resp_team'
,[ms_focal_point]
,[ms_exp_date]
,(SELECT [deal] FROM [NSBP].[dbo].[tbl_deals] as deals
WHERE milestones.[ms_deal] = deals.[id]) as 'ms_deal'
,[ms_active]
FROM [NSBP].[dbo].[tbl_milestones] as milestones"
UpdateCommand="UPDATE [NSBP].[dbo].[tbl_milestones]
SET [ms_description] = #ms_description
,[ms_focal_point] = #ms_focal_point
,[ms_active] = #ms_active
WHERE [ms_id] = #ms_id">
<UpdateParameters>
<asp:Parameter Name="ms_description" Type="String" />
<%-- <asp:Parameter Name="ms_resp_team" Type="String" />--%>
<asp:Parameter Name="ms_focal_point" Type="String" />
<asp:Parameter Name="ms_exp_date" Type="DateTime" />
<asp:Parameter Name="ms_active" Type="Boolean" />
<%-- <asp:Parameter Name="ms_id" Type="String" />--%>
</UpdateParameters>
</asp:SqlDataSource>
You can see my complete GridView-structure + my datasource bound to this GridView.
There is nothing written in my onrowupdating-function in my code-behind file.
Thx in advance
You are using #ms_id in the where clause of your SQL Statement, but the line that sets that <asp:Parameter ... /> is commented out. Try uncommenting:
<%-- <asp:Parameter Name="ms_id" Type="String" /> --%>
and try again
This line;
<%-- <asp:Parameter Name="ms_id" Type="String" />--%>
appears to be commented out and is used in the SQL where clause.
I had grid view which bind sql data source and added field to update data in grid view but it did not do any update and no error appeared and I did not know where the error
SQL Stored Procedures:
ALTER proc [dbo].[GetNewswithType]
As
Begin
Select News.Id,News.Type_Id,
News.Header,News.HText,News.DText,News.Active,News.Add_Date,
NewsType.Type_AR,NewsType.Type_EN
From News
Inner Join NewsType On
NewsType.Id=News.Type_Id
End
ALTER Proc [dbo].[UpdateNews]
(
#Id Int
,#Header Nvarchar(50)
,#HText Nvarchar(Max)
,#DText Nvarchar(Max)
,#Type_Id Int
,#Active Bit
)
AS
BEGIN
Update News Set
#Header =Header
,#HText =HText
,#DText =DText
,#Type_Id=Type_Id
,#Active =Active
WHERE #Id=Id
END
ASPX Page:
<div class="m10">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px"
CellPadding="4" DataKeyNames="Id" DataSourceID="SDSNews" ForeColor="Black"
GridLines="Vertical"
onselectedindexchanged="GridView1_SelectedIndexChanged"
onselectedindexchanging="GridView1_SelectedIndexChanging"
onpageindexchanging="GridView1_PageIndexChanging" AllowPaging="True"
onrowupdated="GridView1_RowUpdated"
onrowdatabound="GridView1_RowDataBound">
<FooterStyle BackColor="#CCCC99" />
<RowStyle BackColor="#F7F7DE" />
<Columns>
<asp:CommandField HeaderText="Function" ShowEditButton="True" />
<asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id"
Visible="False" />
<asp:BoundField DataField="Header" HeaderText="Header"
SortExpression="Header" />
<asp:BoundField DataField="HText" HeaderText="HomeText"
SortExpression="HText" />
<asp:BoundField DataField="DText" HeaderText="DetailsText"
SortExpression="DText" />
<asp:BoundField DataField="Type_Id" HeaderText="TypeNumber"
SortExpression="Type_Id" />
<asp:BoundField DataField="Type_AR" HeaderText="Type_AR"
SortExpression="Type_AR" InsertVisible="False" ReadOnly="True" />
<asp:BoundField DataField="Type_EN" HeaderText="Type_EN"
SortExpression="Type_EN" InsertVisible="False" ReadOnly="True" />
<asp:CheckBoxField DataField="Active" HeaderText="Active"
SortExpression="Active" />
<asp:BoundField DataField="Add_Date" HeaderText="Add_Date"
SortExpression="Add_Date" InsertVisible="False" ReadOnly="True" />
</Columns>
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SDSNews" runat="server"
ConnectionString="Data Source=ELARABY-1EACFA3\SQLEXPRESS;Initial Catalog=ElarabyGroup;Integrated Security=True"
ProviderName="System.Data.SqlClient" SelectCommand="GetNewswithType"
SelectCommandType="StoredProcedure" UpdateCommand="UpdateNews"
UpdateCommandType="StoredProcedure">
<UpdateParameters>
<asp:ControlParameter ControlID="GridView1" Name="Id"
PropertyName="SelectedValue" Type="Int32" />
<asp:ControlParameter ControlID="GridView1" Name="Header"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="GridView1" Name="HText"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="GridView1" Name="DText"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="GridView1" Name="Type_Id"
PropertyName="SelectedValue" Type="Int32" />
<asp:ControlParameter ControlID="GridView1" Name="Active"
PropertyName="SelectedValue" Type="Boolean" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
Add some code to your update procedure to determine if it's being called:
Create a table called Logging (or any name of your choice) that has a column called Message (again, or any name of your choice)
Add a line to your UpdateNews procedure to INSERT INTO [dbo].[Logging] (Message) VALUES ('Procedure Called'). You could log the values of the parameters passed in, if you so wished.
By doing this you can determine if the stored procedure is actually being called or not. The other option is to use Sql Server Profiler to determine this. If you can determine that it is calling the stored procedure, then something is going wrong in there and by logging the parameters you can "hand call" it to find out why.
More likely is that the stored procedure is never being called, how are you telling the grid to persist the changes back out to the database? Looking at this tutorial, I would suggest that your updates are not triggering a "save".