Introduction: This code samples shows how to
To begin with Code:
Drag Drop the Repeater on the webform
<
In code behind
C#SqlConnection cn; SqlDataAdapter da ; DataSet ds ; private void Page_Load(object sender, System.EventArgs e){// Put user code to initialize the page hereif(!Page.IsPostBack){//Code to Bind the data to the Datagridcn = new SqlConnection("Server=localhost;uid=sa;pwd=;database=northwind;");da = new SqlDataAdapter("Select * from employees order by lastname", cn);ds = new DataSet();da.Fill(ds,"Table");Repeater1.DataSource=ds;Repeater1.DataBind(); }}VB.NETDim cn As SqlConnectionDim da As SqlDataAdapterDim ds As DataSetPrivate Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadIf Not Page.IsPostBack Thencn = New SqlConnection("Server=localhost;uid=sa;pwd=;database=northwind;")da = New SqlDataAdapter("Select * from employees order by lastname", cn)ds = New DataSetda.Fill(ds, "Table")Repeater1.DataSource = dsRepeater1.DataBind()End IfEnd SubTo display the contents alphabetically based on the values in the Database
C#protected string GetFirstAlphabet(string strval){string alphabet =(string) ViewState["alphabet"];if( alphabet == strval.Substring(0,1) ){return "";}else{alphabet = strval.Substring(0,1);ViewState["alphabet"] = alphabet;return alphabet;}}VB.NETFunction GetFirstAlphabet(ByVal strval As String) As StringDim alphabet As String = ViewState("alphabet")If alphabet = Left(strval, 1) ThenReturn ""Elsealphabet = Left(strval, 1)ViewState("alphabet") = alphabetReturn alphabetEnd IfEnd Function
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: