Category: Javascript

Mar 02 2010

Making GridView Rows or Individual Cells Clickable and Selectable.

Getting gridview row cells values by clicking use GridView1_RowDataBound , add DataKeyNames,onselectedindexchanging

<asp:GridView ID=”GridView1″ runat=”server” AutoGenerateColumns=”False”

BackColor=”White” BorderColor=”#999999″

BorderStyle=”None” BorderWidth=”1px”

CellPadding=”3″ Font-Names=”Verdana”

Font-Size=”9pt” GridLines=”Vertical”                                          onrowdatabound=”GridView1_RowDataBound”

DataKeyNames=”EmpID onselectedindexchanging=”GridView1_SelectedIndexChanging” >

<RowStyle BackColor=”#EEEEEE” ForeColor=”Black” />

<Columns>

<asp:ButtonField CommandName=”Select” Visible=”False” />

<asp:TemplateField>

<HeaderTemplate>

Details                                                                                                                </HeaderTemplate>

<ItemTemplate>

<asp:LinkButton ID=”lbtnEditUserData” runat=”server”

<asp:LinkButton ID=”lbtnRegisterDetails” runat=”server”

CommandArgument=’<%# DataBinder.Eval(Container.DataItem,”EmpID”) %>’

Font-Underline=”False” oncommand=”lbtnRegisterDetails_Command”>Details</asp:LinkButton>

</ItemTemplate>

</asp:TemplateField>

<asp:BoundField DataField=”Ecode” HeaderText=”ECode” />

<asp:BoundField DataField=”EName” HeaderText=”Employee_Name” />

<asp:BoundField DataField=”EmailID” HeaderText=”EmailID” />

<asp:BoundField DataField=”ProdUserName” HeaderText=”UserName” />

<asp:BoundField DataField=”MobileNo” HeaderText=”MobileNo” />

</Columns>

<SelectedRowStyle BackColor=”#008A8C” Font-Bold=”True” ForeColor=”White” />

<HeaderStyle CssClass=”strip” Font-Bold=”True” ForeColor=”Black” />

</asp:GridView>

<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>

<asp:TextBox ID=”TextBox2″ runat=”server”></asp:TextBox>

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.GridView1, “Select$” + e.Row.RowIndex);

}

}

protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)

{

//Retrieve empcode and empname by clicking gridview row

GridViewRow row = GridView1.Rows[e.NewSelectedIndex];

TextBox1.Text = row.Cells[2].Text;  // getting EmpCode contain in gridview cells[2]

TextBox2.Text = row.Cells[3].Text;  //getting EmpName contain in gridview cells[3]

}

Mar 02 2010

Gridview Row MouseOver and MouseOut

<script language=”javascript” type=”text/javascript”>

var oldgridSelectedColor;

function setMouseOverColor(element)

{

oldgridSelectedColor = element.style.backgroundColor;

element.style.backgroundColor=’yellow’;

element.style.cursor=’hand’;

element.style.textDecoration=’underline’;

}

function setMouseOutColor(element)

{

element.style.backgroundColor=oldgridSelectedColor;

element.style.textDecoration=’none’;

}

</script>

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

e.Row.Attributes["onmouseover"] =”javascript:setMouseOverColor(this);”;

e.Row.Attributes["onmouseout"] =”javascript:setMouseOutColor(this);”;

}

}

Alibi3col theme by Themocracy