December 2004 - Posts
Lets say your datagrid looks like this:
<asp:datagrid OnItemDataBound="dg1_OnItemDataBound"...>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Button runat="server" Text="Delete" id="btnDelete" CommandName="Delete" CausesValidation="false"></asp:Button>
</ItemTemplate>
</asp:TemplateColumn>
...
</asp:datagrid>
And in your ItemDataBound of the datagrid you just need to add this:
Sub dg1_OnItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
CType(e.Item.Cells(0).FindControl("btnDelete"), Button).Attributes.Add("onClick", "return confirm('Are you sure to delete this item?')")
End If
End Sub
Sonu
TopXML.com is one of the companies I work for since a while and now they have been added as a legend of the XSLT community to the <XSLT:Blog />. I am sure that I dont need to explain what TopXML.com is about. If you dont know TopXML.com, I recommend that you take a look and you surely will understand why <XSLT:Blog/> added it. A short <snip> of what <XSLT:Blog/> thinks about TopXML.
"As if I needed any more reasons to make myself look like a fool it seems I forgot to add one *VERY* obvious entry into my last post. To try and avoid any further embarrassment would like to welcome TopXML.com to the "Legends of the XSLT Community" section of this blog. If not obvious please visit TopXML.com and you will quickly understand why TopXML.com should be considered a legend of the XSLT community. TopXML has been promoting the use of XSLT for a very long time providing everything from sample code to complete applications built in XSLT to the development communities abroad."
Sonu
Just in the case you haven't recognized yet.
XMLPitStop has a new design and a cleaner structure. Furthermore we have an admin section which allows us to manage articles and code snippets easily. Feel free to submit your thoughts and ideas to
headgeek@xmlpitstop.com .
Sonu
I have seen this question many times in the ASP.NET forums and thought that it would be a good idea to blog about.
When you are working with functions in the HTML of your DataGrid and passing the value (which can be also NULL) from the database to a function, which accepts a string, then you will get such an error.
Cast from type 'DBNull' to type 'String' is not valid.
To get this working you will have to pass the value as an object. That means the function must simply accept it as an object instead of a string. Something like this:
<asp:datagrid id="datagrid".....>
<Columns>
<asp:TemplateColumn ...>
<ItemTemplate>
<%# DoSomething(Container.DataItem("TheValue")) %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
And in your Codebehind:
function public DoSomething(Dim obj as Object)
If not IsDBNull(obj) then
' Do the processing here...
End If
end function
Sonu
The Reblogger which was published on
Thursday, November 11, 2004 and started initially with 127 posts has passed today Thurday, 16 December 2004 1000 posts in nearly one month. This is so great.
Interested in Reblogger for your own WebSite?Sonu
David Silverlight the headgeek of XMLPitStop.com told me that he is looking for authors who want to contribute articles on
www.XMLPitStop.com. If you have any ideas for an article and would like to publish it on XMLPitStop.com then you can contact either me via the contact page or directly David Silverlight (
headgeek@xmlpitstop.com)
Sonu
More Posts