1
Answer

ItemDataBound issue with foreach

william 0

william 0

20y
2k
1
Anyone... I converted the VB code snippet below to C#. It seemed to have worked okay except for the bad line below... This is the bad line: dv = dgContactHistory.DataSource; 'Cannot implicitly convert type 'object' to 'System.Data.DataView' dgContactHistory is a datagrid on my web form. The VB code seems to make this assignment without issue; I thought it would work in C#. I have tried to type-cast this line and it compiles, but the application doesn't like the (DataView) type-cast. Could anyone offer a suggestion? Thank you very much. William C# private void dgContactHistory_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { string strID; DataView dv; DataColumnCollection dc; dv = dgContactHistory.DataSource; dc = dv.Table.Columns; foreach (DataColumn dcCol in dv.Table.Columns) { if ((e.Item.ItemType == ListItemType.AlternatingItem) || (e.Item.ItemType == ListItemType.Item)) { strID = dgContactHistory.DataKeys[e.Item.ItemIndex].ToString(); e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#99ccff'"); ... VB Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, _ ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound Dim dv As DataView = DataGrid1.DataSource Dim dcCol As DataColumn Dim dc As DataColumnCollection = dv.Table.Columns Dim strID As String For Each dcCol In dv.Table.Columns If e.Item.ItemType = ListItemType.AlternatingItem Or _ e.Item.ItemType = ListItemType.Item Then strID = DataGrid1.DataKeys(e.Item.ItemIndex) e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#99ccff'")
Answers (1)
0
Iftikar Hussain

Iftikar Hussain

NA 18.9k 275.4k 11y
try like this


declare @time1  varchar(20)
declare @time2  varchar(20)

set @time1='01:05:10 Pm'
set @time2='02:15:11 Pm'
select convert(varchar,CAST(@time2 as datetime)-CAST(@time1 as datetime),108) as Diff

Regards,
Iftikar
Accepted
0
suren v

suren v

NA 113 33.1k 11y
Hai,Iftikar Hussain,


    Hai dude i found solution....Thanks for your code...it really works Good:)
0
Iftikar Hussain

Iftikar Hussain

NA 18.9k 275.4k 11y
what result you are getting? Can you share your code?

Regards,
Iftikar
0
suren v

suren v

NA 113 33.1k 11y
Hai, Iftikar Hussain Dude,


 It's not working dude.... 


Thanks for your reply :)
0
suren v

suren v

NA 113 33.1k 11y
Hai, Iftikar Hussain,

           Yes,I'm looking in sql only,.....



0
Iftikar Hussain

Iftikar Hussain

NA 18.9k 275.4k 11y
Hi,
        Are you looking for in SQL?

Regards,
Iftikar
0
nishant ranjan

nishant ranjan

NA 415 0 11y
try this

DateTime startTime =Convert.ToDateTime( "01:05:10 Pm");

DateTime endTime =Convert.ToDateTime( " 02:05:10 Pm");

TimeSpan span = endTime.Subtract(startTime);
Response.Write("Time Difference : " + span);