Friday, October 5, 2007

Working with GridView contol

GridView, Columns, asp:BoundField - sortexpression acts as the order parameter. You can make the grid sort based on this field. It doesn't have to be the field of the displayed value.

GridView, asp:boundfield, insertvisible - when working with the control, set this to true or false to state whether or not this field shows up when the user is makeing an insert.

Had a challenge on what to name the uploaded files. Just settled on naming them with a randomly generated name. This doesn't help seo though.

Reminder: after all of this is implemented, because i had a datagrid talking to a dataview, i had to update the datagrid after the items were updated. So, i had to put in code... datagrid.databind() for the _itemupdated and _iteminserted, _itemdeleted.

Ajax, DetailsView, FileUpload, _ItemUploading and _ItemInserting -

Situation: I am allowing a client to upload a graphic. To make things convenient, I want them to see the graphic.

Challenge: The fileUpload does not fill in or show the client the file name. Plus, when they click on the update, i don't have a filename to reference, so it deletes the filename that was there before.

Solution:
When uploading a graphics file, i had to do a workaround.
I've added a couple of new lines in the update view:


  • IMG - An image to show the graphic
  • asp:label - I'm using this to display the file name. I'm also using this as a reference to the id of the record. This way, I can take this value and put it in place of the value for the fileupload filename.

In the code behind, I have code that handles it. Here is an example:


Dim fupTemp As FileUpload = CType(sender.findControl("fupx"), FileUpload)
If fupTemp.HasFile Then
Dim sPath = sImagePath & fupTemp.FileName
fupTemp.SaveAs(sPath)
e.NewValues("filename") = fupTemp.FileName
Else
Try
e.NewValues("filename") = CType(sender.findControl("imgFileName"), Label).Text
Catch ex As Exception
e.NewValues("filename") = "transparent.gif"
End Try
End If

No comments: