Site Search

Thursday, June 30, 2011

StringSplit function -SQL

This is a function used to split string and fie sql queries
ALTER PROCEDURE [Door].[XXXXXXXXXXXXXXXXXXXXXXXXXXx]
@GroupIdList varchar(max)
,@Type int
AS
BEGIN
DECLARE @Delimeter CHAR(1);

Fire javascript function by code behind

You can access JavaScript function by code behind and fire those easily.
Server side
string myScript = "close();";
ScriptManager.RegisterStartupScript(this.Page, typeof(Page),"CloseWindowKey", myScript, true);
Client side
function close() {
//Functionality for close pop up window
}

Adding Image button to data grid view

1.Add image button under template field it will be easier than adding a command field.
<Columns>
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<HeaderStyle HorizontalAlign="center" Width="35px" />
<ItemTemplate>
<asp:ImageButton ID="selectButton" CommandName="Select" runat="server"/>
ItemTemplate>
asp:TemplateField>
<asp:BoundField DataField="Name">
<HeaderStyle HorizontalAlign="Left" />
asp:BoundField>
<asp:BoundField DataField="Id">
<HeaderStyle HorizontalAlign="Left" />
asp:BoundField>
<asp:BoundField DataField="MainCreditorName">
<HeaderStyle HorizontalAlign="Left" />
asp:BoundField>
Columns>
2.Add the SelectedIndexChanged event and it will fire when you click on image button on the grid.
protected void XXXXXXXXXX_SelectedIndexChanged(object sender, EventArgs e)
{
}
3.You are done

Server side Row Click - Get data from GridView

ASPX Page

<asp:GridView ID="GridViewUsers" runat="server" AutoGenerateColumns="False"Width="100%"
OnSelectedIndexChanged="GridViewUsers_SelectedIndexChanged"DataKeyNames="Id" OnRowCommand="GridViewUsers_RowCommand">
<Columns>
<asp:BoundField HeaderText="User Name" DataField="Name" />
<asp:BoundField HeaderText="Main Creditor" DataField="Id" />
<asp:BoundField HeaderText="Main CReditorName" DataField="MainCreditorName"/>
Columns>
<HeaderStyle HorizontalAlign="Left" CssClass="spn_gridHeader" />
<%-- --%>
asp:GridView>


CS
protected void GridViewUsers_SelectedIndexChanged(object sender, EventArgse)
{
}
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
foreach (GridViewRow row in GridViewUsers.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
ClientScriptManager cs = Page.ClientScript;
row.Attributes["onmouseover"] =
"this.style.cursor='hand';this.style.textDecoration='underline';";
row.Attributes["onmouseout"] =
"this.style.textDecoration='none';";
// Set the last parameter to True
// to register for event validation.
row.Attributes["onclick"] =
cs.GetPostBackClientHyperlink(GridViewUsers,
"Select$" + row.DataItemIndex, true);
}
}
base.Render(writer);
}


Page Load
GridViewUsers.RowCommand += GridViewUsers_RowCommand;

First Post

This site is all about sharing the knowledge with the world freely coz I believe that the human knowledge should share among us coz it belongs to the world. So take time surf yourself and make life easy.