Thursday, September 27, 2012

Select Griview row by clicking anywhere

1. Add a CommandArgument to the link button.
<asp:LinkButton ID="LinkBtn3" runat="server" CommandName="Date" CommandArgument='<%# Eval("id") %>'  Text='<%#Eval("id") %>' Font-Underline="false" ForeColor="Black"></asp:LinkButton>
2. In the RowDataBound event
e.Row.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(DirectCast(sender, System.Web.UI.Control), "Select$" + e.Row.RowIndex.ToString()))
3. Then on the RowCommand Event:
If e.CommandName = "Select" Then
GrvDraft.EditIndex = e.CommandArgument
End If
4. If you get this error: Invalid postback or callback argument. Add this.
Protected Overloads Overrides Sub Render(ByVal writer As HtmlTextWriter)
For i As Integer = 0 To Me.GrvDraft.Rows.Count - 1
Page.ClientScript.RegisterForEventValidation(Me.GrvDraft.UniqueID, "Select$" & i)
Next
MyBase.Render(writer)
End Sub

Friday, September 21, 2012

Gridview with ImageURL

<asp:GridView ID="gvEmployees" runat="server" AutoGenerateColumns="False" pagesize="5" AllowPaging="True">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Team" HeaderText="Team" />
<asp:BoundField DataField="dateHired" HeaderText="Date Hired"
DataFormatString="{0:MMMM dd, yyyy}" />
<asp:BoundField DataField="empStatus" HeaderText="Employment Status" />
<asp:BoundField DataField="birthday" HeaderText="Birthday" />
<asp:BoundField DataField="civilStatus" HeaderText="Civil Status" />
<asp:BoundField DataField="noOfChildren" HeaderText="No. Of Children" />
<asp:BoundField DataField="cellphoneNo" HeaderText="Cellphone #" />
<asp:BoundField DataField="address" HeaderText="Address" />
<asp:BoundField DataField="contactPerson" HeaderText="Contact Person" />
<asp:BoundField DataField="contactNo" HeaderText="Emergency #" />
<asp:TemplateField>
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl ='<%# "~/Images/EmpImage/"+Eval("idemployee").tostring()+".png" %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>