2
問題: 添加列表項時,將值字段設置爲文本字段。最初我雖然問題與主鍵(group_type_id)的輸入參數有關,因爲它被配置爲OUTPUT變量。列表框 - 正在設置爲文本字段的值
有趣的是,當我觀察所有的值時,一切都是正確的。 因此,例如,我會看這些:
ddr["group_type_name"] comes out as "Dept"
ddr["grouptypeid"] comes out as 4
將項目然而創建,
itms.TEXT = "Dept"
itms.Value = "Dept" <-- THIS IS THE PROBLEM
我在爲什麼在列表框中的值被設置爲文本時的值損失我可以清楚地看到數據讀取器的值是正確的。 ?
代碼示例在這裏:
DbDataReader ddr = grp.GetGroupTypeList(grp);
if (ddr.HasRows)
{
ListItem itm = new ListItem();
itm.Text = "Select Group";
itm.Value = "0";
lb.Items.Add(itm);
while (ddr.Read())
{
ListItem itms = new ListItem(ddr["group_type_name"] as string, ddr["grouptypeid"] as string);
}
lb.SelectedValue = lbSelected;
}
程序:
ALTER PROCEDURE [dbo].[asp_Group_Type]
@driver char(1)='I',
@group_type_id int=null OUTPUT,
@group_type_name varchar(50)=null,
@par_group_id int=null,
@active bit
AS
DECLARE @SQL varchar(8000)
DECLARE @boolWhere varchar(10)
SET @boolWhere = ' WHERE '
SET NOCOUNT ON
IF (@driver = 'I')
BEGIN
INSERT INTO [dbo].[group_type]
([group_type_name],
[Par_Group_Id])
VALUES
(RTRIM(LTRIM(@group_type_name)),
@par_group_id)
SELECT @group_type_id = SCOPE_IDENTITY()
END
IF (@driver = 'U')
BEGIN
UPDATE [dbo].[group_type]
SET [group_type_name] = RTRIM(LTRIM(@group_type_name))
,[Par_Group_Id] = @par_group_id
WHERE [group_type_id] = @group_type_id
END
IF (@driver = 'S')
BEGIN
SET @SQL = ' SELECT [group_type_id] AS [grouptypeid], [group_type_id], [group_type_name],[Par_Group_Id] FROM [dbo].[group_type] '
IF (@group_type_id > 0)
BEGIN
SET @SQL = @SQL + @boolWhere + '[group_type_id] = ''' + CAST(@group_type_id AS VARCHAR) + ''''
SET @boolWhere = ' AND '
END
IF (@active > 0)
BEGIN
SET @SQL = @SQL + @boolWhere + ' [active] = ''' + CAST(@active AS VARCHAR) + ''''
END
SET @SQL = @SQL + ' ORDER BY [group_type_name] '
PRINT(@SQL)
EXEC(@SQL)
END
工作!謝謝。 – ericm 2011-03-07 22:41:32
然後請將我的答案標記爲回答您問題的答案。 – 2011-03-08 01:46:18