我有一個從數據庫中檢索數據的GridView。用戶具有角色,一些用戶將更新GridView中的一列,其他列將根據角色更新其他列,請參閱下面的代碼!我創建瞭如下的存儲過程,並添加了代碼。當我測試項目時,以角色(AR-Translator)作爲例子,在網格視圖中編輯列之後,用NULL值替換其他fied,所以請問我能做些什麼?更新網格視圖中的specfic列
存儲過程
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 [email protected]
,[email protected]_AR
,[email protected]_EN
WHERE [email protected]
END
aspx頁面
<div class="m10">
<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">
<FooterStyle BackColor="#CCCC99" />
<RowStyle BackColor="#F7F7DE" />
<Columns>
<asp:CommandField HeaderText="Function" ShowEditButton="True" />
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False"
ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Word" HeaderText="Word" SortExpression="Word" />
<asp:BoundField DataField="Trans_AR" HeaderText="Trans_AR"
SortExpression="Trans_AR" />
<asp:BoundField DataField="Trans_EN" HeaderText="Trans_EN"
SortExpression="Trans_EN" />
<asp:BoundField DataField="Add_Date" HeaderText="Add_Date"
SortExpression="Add_Date" />
</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="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">
<UpdateParameters>
<asp:ControlParameter ControlID="GridView1" Name="Id"
PropertyName="SelectedValue" Type="Int32" />
<asp:ControlParameter ControlID="GridView1" Name="Word"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="GridView1" Name="Trans_AR"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="GridView1" Name="Trans_EN"
PropertyName="SelectedValue" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:Label ID="ResultLBL" runat="server" Visible="false"></asp:Label>
</div>
CS
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;
}
}
}
}
莫非你澄清問題多一點?不明白你在問什麼...你想手動更新gridview列嗎? – mint 2010-07-29 14:41:39
這聽起來像他有空字符的問題......或者也許它列出了一個空列?我希望我翻譯正確.. – Nix 2010-07-29 14:48:43
我編輯了這個問題,我認爲你會明白的 – Myworld 2010-07-31 13:14:13