I have changed your Sp and C# code
HTML
<asp:Label ID="lblQuery" CssClass="labelbold" runat="server" Text="Query"></asp:Label>
<asp:TextBox ID="txtQuery" runat="server"></asp:TextBox>
<asp:Label ID="lblStatus" CssClass="labelbold" runat="server" Text="Active Status"></asp:Label>
<asp:DropDownList ID="ddlStatus" runat="server">
<asp:ListItem Text="--Select--"></asp:ListItem>
<asp:ListItem Text="Active" Value="True"></asp:ListItem>
<asp:ListItem Text="Inactive" Value="False"></asp:ListItem>
</asp:DropDownList>
<hr />
<asp:GridView ID="grdview" runat="server" Width="100%" AutoGenerateColumns="False"
DataKeyNames="PKID" OnRowCommand="grdview_RowCommand">
<Columns>
<asp:BoundField DataField="PKID" Visible="false" />
<asp:BoundField DataField="Query" HeaderText="Query" />
<asp:TemplateField HeaderText="Edit/View">
<ItemTemplate>
<asp:ImageButton ID="ibtnResetPWD" runat="server" CausesValidation="False" ImageUrl="~/Images/viewbut.gif"
CommandName="View" CommandArgument='<%# Eval("PKID") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Namespace
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindGrid();
}
}
public void BindGrid()
{
string str = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection connection = new SqlConnection(str))
{
using (SqlCommand command = new SqlCommand("usp_BindData", connection))
{
using (SqlDataAdapter adap = new SqlDataAdapter(command))
{
command.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
adap.Fill(ds);
grdview.DataSource = ds;
grdview.DataBind();
}
}
}
}
protected void grdview_RowCommand(object sender, GridViewCommandEventArgs e)
{
string str = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
if (e.CommandName == "View")
{
int rowIndex = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex;
int id = Convert.ToInt16(e.CommandArgument);
using (SqlConnection conn = new SqlConnection(str))
{
using (SqlCommand cmd = new SqlCommand("usp_GetData", conn))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@PKID", id);
DataTable dt = new DataTable();
da.Fill(dt);
txtQuery.Text = dt.Rows[0]["Query"].ToString();
string s = dt.Rows[0]["Status"].ToString();
ddlStatus.ClearSelection();
this.ddlStatus.Items.FindByText(dt.Rows[0]["Status"].ToString()).Selected = true;
}
}
}
}
}
Here i have cleared the DDL selection
ddlStatus.ClearSelection();
SQL
CREATE TABLE [dbo].[tblDat](
[PKID] [int] IDENTITY(1,1) NOT NULL,
[Query] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[IsActive] [bit] NULL
) ON [PRIMARY]
GO
--------
-- usp_BindData
CREATE PROCEDURE usp_BindData
AS
BEGIN
SELECT PKID
,Query
,CASE IsActive WHEN 1 THEN 'Active' ELSE 'Inactive' END AS [Status]
FROM tblDat
END
GO
-------
-- usp_GetData 2
ALTER PROCEDURE usp_GetData
(
@PKID INT
)
AS
BEGIN
SELECT PKID
,Query
,CASE IsActive WHEN 1 THEN 'Active' ELSE 'Inactive' END AS [Status]
FROM tblDat
WHERE PKID=@PKID
END
GO
In SQL SP i changed Deactive to Inactive as you are having Inactive in your DDL.