Wednesday, December 3, 2014

An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode

In your web.config, make sure these keys exist:

<configuration>
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
    </system.webServer>
</configuration>

Tuesday, December 2, 2014

asp.net dropdown add select option

   if (dsRiskCategories.Tables[0].Rows.Count > 0)
                {
                    DataRow dr = dsRiskCategories.Tables[0].NewRow();
                    dr["CategoryId"] = "0";
                    dr["CategoryName"] = "Select Risk Category";
                    dsRiskCategories.Tables[0].Rows.InsertAt(dr, 0);
                }

                ddlCategory.DataSource = dsRiskCategories;
                ddlCategory.DataTextField = "CategoryName";
                ddlCategory.DataValueField = "CategoryId";
                ddlCategory.DataBind();

Saturday, November 29, 2014

asp.net edit command field with css and image

 <asp:CommandField ButtonType="Image" EditText="Edit" EditImageUrl="~/images/Edit.jpg"
                            HeaderStyle-CssClass="centerText" ItemStyle-CssClass="centerText" ControlStyle-CssClass="editIconSize"
                            HeaderText="Edit" ShowEditButton="True" ShowCancelButton="false" UpdateImageUrl="~/images/save.jpg" />

Thursday, November 27, 2014

Select nth row of a table in sql server

SELECT * FROM (
     SELECT     ROW_NUMBER() OVER (ORDER BY CategoryId) AS RowNo,CategoryId, CategoryName, LessThan, GreaterThan, AdvisorId, CategoryRating
          FROM CategoryMapping
WHERE     (AdvisorId = 1)

 ) AS foo
WHERE RowNo= 2

asp.net gridview get column data from datatable

 for (int i = 0; i < tableQuestion.Rows.Count; i++)
            {
 string answer = tableQuestion.Rows[i]["Sanswer"].ToString();
}

asp.net gridview hide and show linkbutton in template field

ASPX -

 <asp:TemplateField HeaderText="Publish">
                        <ItemTemplate>
                            <asp:Label ID="lblStatus" Text='<%# Eval("Status") %>' runat="server" Visible="false"></asp:Label>
                            <asp:LinkButton ID="linkpublishQues" runat="server" CommandArgument='<%#Eval("QuestionId")%>'
                                CommandName="Publish" OnClientClick="return confirm('Do you want to publish this question?')">Publish</asp:LinkButton>
                            <asp:LinkButton ID="linkunpublishQues" runat="server" CommandArgument='<%#Eval("QuestionId")%>'
                                CommandName="UnPublish" OnClientClick="return confirm('Do you want to unpublish this question?')">UnPublish</asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>


.CS -

 Label lblStatus = e.Row.FindControl("lblStatus") as Label;

                if (lblStatus.Text == "Save")
                {
                    LinkButton linkunpublishQues = (LinkButton)e.Row.FindControl("linkunpublishQues");
                    LinkButton linkpublishQues = (LinkButton)e.Row.FindControl("linkpublishQues");
                    linkunpublishQues.Visible = false;
                    linkpublishQues.Visible = true;

                }
                else if (lblStatus.Text == "Publish")
                {
                    LinkButton linkunpublishQues = (LinkButton)e.Row.FindControl("linkunpublishQues");
                    LinkButton linkpublishQues = (LinkButton)e.Row.FindControl("linkpublishQues");
                    linkunpublishQues.Visible = true;
                    linkpublishQues.Visible = false;
                }

asp.net gridview change update button text on commandfield edit button

  <asp:CommandField HeaderText="Edit" ShowEditButton="True"  UpdateText="Save" />