Friday, February 18, 2011

Update query of sql server in asp.net

query = "update dbo_personaldata set name='" + txtName.Text + "',[date]=#" + lblDate.Text + "#,gender='" + gender + "',father_name='" + txtFather.Text + "',date_of_birth=#" + datDate.Text + "#,nationality='" + txtNationality.Text + "',address='" + txtMailAddress.Text + "',city='" + txtCity.Text + "',state='" + txtState.Text + "',postal_code='" + txtPostal.Text + "',mobile_no='" + txtMobile.Text + "',category='" + txtCategory.Text + "',email='" + txtEmail.Text + "',state_of_domicile='" + txtDomicile.Text + "'where id=" + id;

Tuesday, February 15, 2011

Repeater Control in Asp.net

Hello,
Repeater control in asp.net like Grid View.
Most of the company use repeater control for data dispaly like.
Default.aspx page
    <form id="form1" runat="server">
    <div>
        <asp:Repeater ID="RepeatInformation" runat="server">
            <HeaderTemplate>
                <table class="tblcolor">
                    <tr>
                        <b>
                            <td>
                                Roll No
                            </td>
                            <td>
                                Student Name
                            </td>
                            <td>
                                Total Fees
                            </td>
                        </b>
                    </tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr class="tblrowcolor">
                    <td>
                        <%#DataBinder.Eval(Container,"DataItem.RollNo")%>
                    </td>
                    <td>
                        <%#DataBinder.Eval(Container,"DataItem.Name")%>
                    </td>
                    <td>
                        <%#DataBinder.Eval(Container,"DataItem.Fees")%>
                    </td>
                </tr>
            </ItemTemplate>
            <SeparatorTemplate>
                <tr>
                    <td>
                        <hr />
                    </td>
                    <td>
                        <hr />
                    </td>
                    <td>
                        <hr />
                    </td>
                </tr>
            </SeparatorTemplate>
            <AlternatingItemTemplate>
                <tr>
                    <td>
                        <%#DataBinder.Eval(Container,"DataItem.RollNo")%>
                    </td>
                    <td>
                        <%#DataBinder.Eval(Container,"DataItem.Name")%>
                    </td>
                    <td>
                        <%#DataBinder.Eval(Container,"DataItem.Fees")%>
                    </td>
                </tr>
            </AlternatingItemTemplate>
            <SeparatorTemplate>
                <tr>
                    <td>
                        <hr />
                    </td>
                    <td>
                        <hr />
                    </td>
                    <td>
                        <hr />
                    </td>
                </tr>
            </SeparatorTemplate>
            <FooterTemplate>
                <tr>
                    <td>
                        School Records displayed
                    </td>
                </tr>
                </table>
            </FooterTemplate>
        </asp:Repeater>
    </div>
    </form>
 Or on page of .cs file Default.aspx.cs page like
 public partial class _Default : System.Web.UI.Page
{
   
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con;
        SqlCommand cmd = new SqlCommand();
        con = new SqlConnection(ConfigurationManager.ConnectionStrings["abc"].ConnectionString);
        cmd.Connection = con;
        cmd.CommandText = "select * from employee";
        con.Open();
        RepeatInformation.DataSource = cmd.ExecuteReader();
        RepeatInformation.DataBind();
        con.Close();
    }


Here the example show data binding through Ado.net We can also Linq to Sql for Binding.

Thankx