Tuesday, July 24, 2012

Active/Inactive

In Gridview Define templatefield inside column

<asp:GridView ID="gvContent" runat="server" CssClass="body-text-black" Width="750px" AllowPaging="True" AutoGenerateColumns="False" HeaderStyle-CssClass="gridhead" CellPadding="5" RowStyle-CssClass="gridrow1" AlternatingRowStyle-CssClass="gridrow2" BorderWidth="0px" GridLines="None" HeaderStyle-VerticalAlign="top" HorizontalAlign="Left" HeaderStyle-HorizontalAlign="left" RowStyle-VerticalAlign="top" onpageindexchanging="gvContent_PageIndexChanging" onrowcommand="gvContent_RowCommand" PageSize=30 onrowdatabound="gvContent_RowDataBound">
 <Columns>

<asp:TemplateField HeaderText="S.No.">
 <ItemTemplate>
<%# Container.DataItemIndex + 1 %> </ItemTemplate>
 </asp:TemplateField>

<asp:templatefield headertext="Active/InActive">
 <itemtemplate>
<asp:button causesvalidation="false" commandargument="<%#Eval("DestID")%>" commandname="Status" cssclass="btn" id="btnStatus" onclientclick="return
ConfirmStatus()" runat="server" text="<%#Eval("Status1")%>"> </asp:button>
</itemtemplate>

</asp:templatefield>
</Columns>

</asp:GridView>
I have used command name and command arguement and it will handle inside rowcommand event.

Row command Code of Cs page

protected void gvContent_RowCommand(object sender, GridViewCommandEventArgs e)
{
 if (e.CommandName == "Status")
{
 int index = Convert.ToInt32(e.CommandArgument.ToString());
 try
{
 int iRow = DAL.ExecuteNonQuery(ConnectionString, "prcDesttemp", "4", index, "","", "", "", "","", "","","","","", "1", "0" ,0, 0 ,0,"0"); Fillgridview(); lblMsg.Text = "Status Changed Successfully.";
 }
 catch (Exception ex)
 { }
 }
 }
I have used pocedure to do this task -which is easy to maintain.And used a Dal Class for this where i am passing connection string , procedure name, action Id and parameter.


CREATE procedure [dbo].[prcDesttemp]
(
@ActionId tinyint,
@DestID int,
@DestName nvarchar(100),
@DestiShortDesc nvarchar (200),
@DestiLongDesc text,
@PlaceDesc text,
@WeatherDesc text,
@HistoryDesc text,
@VisitDesc text,
@SmallImage nvarchar(200),
@LongImage nvarchar(200),
@MetaTitle text,
@MetaDesc text, @Status tinyint ,
@Result tinyint output,
@RegionID int,
@CountryID int,
@CityID int ,
@Displayonhome tinyint
)
--sp_help tblArticleMasterClient
as
begin
set nocount on
if @ActionId=1 --Add Destination
begin
insert into tblArticleMasterDestination (DestName,DestiShortDesc,DestiLongDesc,PlaceDesc,WeatherDesc, HistoryDesc, VisitDesc,SmallImage,LongImage,MetaTitle,MetaDesc,Status,CreateDate , RegionID , CountryID , CityID,Displayonhome ) values (@DestName, @DestiShortDesc, @DestiLongDesc,@PlaceDesc, @WeatherDesc, @HistoryDesc, @VisitDesc, @SmallImage , @LongImage , @MetaTitle, @MetaDesc, '1', getdate() , @RegionID , @CountryID , @CityID,@Displayonhome)
end
if @ActionId=2 --Update Destination
begin
update tblArticleMasterDestination set
DestName = @DestName,
DestiShortDesc = @DestiShortDesc ,
DestiLongDesc = @DestiLongDesc ,
PlaceDesc = @PlaceDesc ,
WeatherDesc=@WeatherDesc,
HistoryDesc=@HistoryDesc,
VisitDesc=@VisitDesc,
SmallImage=@SmallImage,
LongImage=@LongImage,
MetaTitle=@MetaTitle,
MetaDesc=@MetaDesc,
UpdateDate = getdate()
, RegionID = @RegionID ,
CountryID = @CountryID ,
CityID = @CityID
where DestID = @DestID
end
if @ActionId=3 --Select records
begin
select *, case status when '1' then 'Active' when '0' then 'In-Active' end as Status1 from tblArticleMasterDestination order by Destname end
if @ActionId=4 --Change Status
begin
select @Status=Status from tblArticleMasterDestination where DestID=@DestID
if @Status=0 --InActive
begin
Update tblArticleMasterDestination set Status=1 where DestID=@DestID end
else --Active
begin
update tblArticleMasterDestination set Status=0 where DestID=@DestID end
end
end --set nocount off end


Get Dal class And copy it and put this in app_code library

No comments:

Post a Comment