2017-09-14 46 views
0

我正在使用Telerix RadGrid並且似乎無法獲取代碼以提供複選框的值。這是我的C#代碼爲什麼我無法使用此代碼在「我的Gridview」中工作

protected void gvMembers_UpdateCommand(object sender, GridCommandEventArgs e) 
    { 
     var editableItem = ((GridEditableItem)e.Item); 
     var memberId = (int)editableItem.GetDataKeyValue("UserID"); 
     int Role = 1; 
     CheckBox active = (CheckBox)editableItem["valid"].Controls[0]; 
     Boolean boolactive = Convert.ToBoolean(active.Checked = !String.IsNullOrEmpty(e.Item.Cells[0].Text)); 
     string strFirstName = (editableItem["firstname"].Controls[0] as TextBox).Text; 
     string strLastName = (editableItem["lastname"].Controls[0] as TextBox).Text; 
     string strUserName = (editableItem["username"].Controls[0] as TextBox).Text; 
     string strEmail = (editableItem["firstname"].Controls[0] as TextBox).Text; 

代碼編譯並運行,但複選框值始終爲false。我錯過了什麼?

我做了一些更多的故障排除,並已發現了這個代碼:

CheckBox active = (CheckBox)editableItem["valid"].Controls[0]; 

返回該值{文本=「」選中=真}

我加入這個作爲我的下一行代碼:

string str = active.Text; 

並檢查字符串的值它返回一個空字符串。

任何關於如何從複選框中獲取布爾值的想法,以便我可以將它傳遞給數據庫?

+0

不明白你的情況'active.Checked =!String.IsNullOrEmpty(e.Item.Cells [0] .Text' –

+0

也許你的意思是'=='而不是'='? –

+0

你是不是存儲返回我認爲你的意思是這樣的:'active.Checked =!String.IsNullOrEmpty(e.Item.Cells [0] .Text);'然後'布爾boolactive = Convert.ToBoolean(active.Checked); ''或另一種方式做同樣的'bool?boolactive = active.Checked =!String.IsNullOrEmpty(e.Item.Cells [0] .Text);' – praty

回答

1

我能夠通過使用以下命令獲取布爾值來解決這個問題:

  CheckBox active = (CheckBox)editableItem["valid"].Controls[0]; 
     Boolean bactive = active.Checked; 

感謝您的意見。

相關問題