G
Guest
I have 2 Databinding questions and perhaps the answer is the same.
I have a dataset in which I DO NOT have a field which identifies the record number but I want to show the specific item number of the row within a DataList control. I was thinking that I would set up a method which would have a counter in it and each time it is executed it would incriment the counter by 1 and then return the string value of the count. So on the HTML document I would have something like the following:
<%# GetRowNumber() %>
An then the method would look like this:
Public string GetRowNumber()
{
_ModuleCtr ++;
return _ModuleCtr.ToString();
}
Is there a better way to do this?
Second question - I may or may not want to display the contents of a data column based upon some condition. I am guessing that I could place script in the HTML to test the variable and either bind the Datacolumn to the field on the HTML or bind the field to a space, so that nothing would show. If I created a method to do this test, how would I pass the Datarow which is being bound at that time (within the DataList). So right now, without the test, the code would look like the following:
<%# DataBinder.Eval(Container.DataItem,"PERIOD_END", "{0:MM/dd/yyyy}") %>
But if I created a method which did the test (the above does not do the test), how do I pass the "context" which will allow me to pass the appropriate value. So for instance...
Public string GetTheRightValue( ? ? ? ?)
{
if (OKToPrintContents)
Return dataTable[rowNumber]["MyField"].ToString();
else
return " ";
}
So in the above, what is being passed to me which will allow me to get a reference to the row which is being databound for the specific row? I realize I could probably us the OnItemDataBound event or a half a dozen other ways, but can I do it this way?
I have a dataset in which I DO NOT have a field which identifies the record number but I want to show the specific item number of the row within a DataList control. I was thinking that I would set up a method which would have a counter in it and each time it is executed it would incriment the counter by 1 and then return the string value of the count. So on the HTML document I would have something like the following:
<%# GetRowNumber() %>
An then the method would look like this:
Public string GetRowNumber()
{
_ModuleCtr ++;
return _ModuleCtr.ToString();
}
Is there a better way to do this?
Second question - I may or may not want to display the contents of a data column based upon some condition. I am guessing that I could place script in the HTML to test the variable and either bind the Datacolumn to the field on the HTML or bind the field to a space, so that nothing would show. If I created a method to do this test, how would I pass the Datarow which is being bound at that time (within the DataList). So right now, without the test, the code would look like the following:
<%# DataBinder.Eval(Container.DataItem,"PERIOD_END", "{0:MM/dd/yyyy}") %>
But if I created a method which did the test (the above does not do the test), how do I pass the "context" which will allow me to pass the appropriate value. So for instance...
Public string GetTheRightValue( ? ? ? ?)
{
if (OKToPrintContents)
Return dataTable[rowNumber]["MyField"].ToString();
else
return " ";
}
So in the above, what is being passed to me which will allow me to get a reference to the row which is being databound for the specific row? I realize I could probably us the OnItemDataBound event or a half a dozen other ways, but can I do it this way?