Note that there are some explanatory texts on larger screens.

plurals
  1. POupdate specific column in grid view
    primarykey
    data
    text
    <p>I have a GridView which retrieves data from a database. Users have roles, some of the users will update one column in the GridView and others will update a other columns according to roles see the code below!. I created the stored procedures as below and I added code. When I tested the project,with role (AR-Translator)as example after edit column in grid view it replace other fieds with NULL value, so please what I can do?</p> <p><strong>stored procedure</strong></p> <pre><code>ALTER Proc [dbo].[GetAllTranslation] AS BEGIN Select Id,Word ,Trans_AR ,Trans_EN ,Add_Date From Translation END ALTER Proc [dbo].[UpdateTranslation] ( @IdINT ,@Word NVARCHAR(MAX) ,@Trans_AR NVARCHAR(MAX) ,@Trans_EN NVARCHAR(MAX) ) AS BEGIN UPDATE Translation SET Word =@Word ,Trans_AR=@Trans_AR ,Trans_EN=@Trans_EN WHERE Id=@Id END </code></pre> <p><strong>aspx page</strong></p> <pre><code> &lt;div class="m10"&gt; &lt;asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SDSTrans" onrowupdated="GridView1_RowUpdated"&gt; &lt;FooterStyle BackColor="#CCCC99" /&gt; &lt;RowStyle BackColor="#F7F7DE" /&gt; &lt;Columns&gt; &lt;asp:CommandField HeaderText="Function" ShowEditButton="True" /&gt; &lt;asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" /&gt; &lt;asp:BoundField DataField="Word" HeaderText="Word" SortExpression="Word" /&gt; &lt;asp:BoundField DataField="Trans_AR" HeaderText="Trans_AR" SortExpression="Trans_AR" /&gt; &lt;asp:BoundField DataField="Trans_EN" HeaderText="Trans_EN" SortExpression="Trans_EN" /&gt; &lt;asp:BoundField DataField="Add_Date" HeaderText="Add_Date" SortExpression="Add_Date" /&gt; &lt;/Columns&gt; &lt;PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" /&gt; &lt;SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" /&gt; &lt;HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" /&gt; &lt;AlternatingRowStyle BackColor="White" /&gt; &lt;/asp:GridView&gt; &lt;asp:SqlDataSource ID="SDSTrans" runat="server" ConnectionString="Data Source=ELARABY-1EACFA3\SQLEXPRESS;Initial Catalog=ElarabyGroup;Integrated Security=True" ProviderName="System.Data.SqlClient" SelectCommand="GetAllTranslation" SelectCommandType="StoredProcedure" UpdateCommand="UpdateTranslation" UpdateCommandType="StoredProcedure"&gt; &lt;UpdateParameters&gt; &lt;asp:ControlParameter ControlID="GridView1" Name="Id" PropertyName="SelectedValue" Type="Int32" /&gt; &lt;asp:ControlParameter ControlID="GridView1" Name="Word" PropertyName="SelectedValue" Type="String" /&gt; &lt;asp:ControlParameter ControlID="GridView1" Name="Trans_AR" PropertyName="SelectedValue" Type="String" /&gt; &lt;asp:ControlParameter ControlID="GridView1" Name="Trans_EN" PropertyName="SelectedValue" Type="String" /&gt; &lt;/UpdateParameters&gt; &lt;/asp:SqlDataSource&gt; &lt;asp:Label ID="ResultLBL" runat="server" Visible="false"&gt;&lt;/asp:Label&gt; &lt;/div&gt; </code></pre> <p><strong>CS</strong></p> <pre><code>public void CheckLoginAuthorty() { using (SqlConnection Con = Connection.GetConnection()) { SqlCommand com = new SqlCommand("CheackLoginInRole", Con); com.CommandType = CommandType.StoredProcedure; com.Parameters.Add(Parameter.NewNVarChar("@Login", Session.Contents["Username"].ToString())); object O = com.ExecuteScalar(); if (O != null) { string S = O.ToString(); if (IsInRole("AR-Translator", O.ToString())) { ((BoundField)GridView1.Columns[2]).ReadOnly = false; ((BoundField)GridView1.Columns[2]).InsertVisible = false; ((BoundField)GridView1.Columns[4]).ReadOnly = false; ((BoundField)GridView1.Columns[4]).InsertVisible = false; } else if (IsInRole("EN-Translator", O.ToString())) { ((BoundField)GridView1.Columns[2]).ReadOnly = true; ((BoundField)GridView1.Columns[2]).InsertVisible = false; ((BoundField)GridView1.Columns[3]).ReadOnly = true; ((BoundField)GridView1.Columns[3]).InsertVisible = false; } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload