|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
RowDataBound bool to stringprotected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.Cells[3] = true) { e.Row.Cells[3].Text = "D"; } else duration = new DateTime((e.Row.Cells[4].Text), 0, 0, 0); uno = new DateTime(1, 0, 0, 0); duration = duration + uno; if (DateTime.Now < duration) { e.Row.Cells[3].Text = "A"; } else e.Row.Cells[3].Text = "E"; } Luis,
It looks like you're trying to change the value of a bound column to display your text. If you want to display a function computed from a bound column, you need to do so in an unbound column. In other words, create an unbound column in your dataset or gridview and compute its "Text" property (using the code you provided) based on the source column of the data. You can't change the "Text" property of a bound column to a value that you DON'T want to put in the column in that data source. Cheers, Kelly Show quoteHide quote "lui***@runbox.com" wrote: > > i have one bool value. if the value is true i want to display in my gridview "D" or the other 2 options. please help me, i know that i am missing something. but it is not working. > > protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) > { > if (e.Row.RowType == DataControlRowType.DataRow) > { > > if (e.Row.Cells[3] = true) > { > e.Row.Cells[3].Text = "D"; > } > else > duration = new DateTime((e.Row.Cells[4].Text), 0, 0, 0); > uno = new DateTime(1, 0, 0, 0); > duration = duration + uno; > if (DateTime.Now < duration) > { > e.Row.Cells[3].Text = "A"; > } > else > e.Row.Cells[3].Text = "E"; > } > Luis,
You might want to have a look at Template-d Column rather than Bound Column whose value is not customizable. -- Cheers, Gaurav Vaish http://mastergaurav.org ------------------------------- To Hell with Murphy's Law.. When things go broke, FIX Them ------------------------------- Luis,
You might want to have a look at Template-d Column rather than Bound Column whose value is not customizable. -- Cheers, Gaurav Vaish http://mastergaurav.org http://www.edujini.in ------------------------------- To Hell with Murphy's Law.. When things go broke, FIX Them ------------------------------- I would agree with MasterGaurav. Templating is the best way to go here.
Check out TemplateField and ItemTemplate. Show quoteHide quote "MasterGaurav" wrote: > Luis, > > You might want to have a look at Template-d Column rather than Bound > Column whose value is not customizable. > > > -- > Cheers, > Gaurav Vaish > http://mastergaurav.org > http://www.edujini.in > ------------------------------- > To Hell with Murphy's Law.. When things go broke, FIX Them > ------------------------------- > >
Other interesting topics
FileUpload, Wizard, and saving the data
Web Standards Compliance - Autopostback / Javascript off access control in a Repeater from javascript Wizard, goto page, need to set values of a control in a Repeater asp.net menu to show only parent, siblings and children as static menus Set file extensions for FileUpload delete rows in dataset Custom Web Control and Default Height/Width Dynamic Menu Control in ASP.NET2 User Control question - REPOSTED |
|||||||||||||||||||||||