Merhaba arkadaşlar bu makalemizde DataTable i
kullanarak Name sütunundaki seçili satırlardaki karakterlerin küçük karakter
olarak yazılmasını sağlayacağız.Bu örneğimizde Personel Id değeri 5 den küçük
olanlar küçük karakterle, Id değeri 5 den büyük olan satırlar baş harfi büyük
karakterle yazdıracağız.
Şekil 1
Şekil 2
WebForm1.aspx.cs
using System;
using
System.Collections.Generic;
using
System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using
System.Web.UI.WebControls;
using MySql.Data;
using
MySql.Data.MySqlClient;
using System.Drawing;
namespace
gridview_datatable_lowercase2
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindList();
}
}
protected void bindList()
{
MySqlConnection con = new MySqlConnection("Server=localhost;Database=dbemployee;Uid=root;Pwd='2344';AllowUserVariables=True;UseCompression=True;");
{
con.Open();
MySqlCommand cmd = new MySqlCommand("Select
* From person", con);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
MySqlConnection con = new MySqlConnection("Server=localhost;Database=dbemployee;Uid=root;Pwd='2344';AllowUserVariables=True;UseCompression=True;");
con.Open();
MySqlCommand cmd = new MySqlCommand("Select * From person", con);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
con.Close();
DataRow[] drows = dt.Select("Id <
5");
for (int i = 0; i < drows.Length; i++)
{
dt.Rows[i][1] =
dt.Rows[i][1].ToString().ToLower();
}
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
WebForm1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="gridview_datatable_lowercase2.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" ></asp:GridView>
<br />
<asp:Button ID="Button1" runat="server" Text="Click" OnClick="Button1_Click" />
</div>
<div> </div>
<div> </div>
<div> </div>
</form>
</body>
</html>
Bir makalenin daha sonuna geldik. Bir sonraki
makalede görüşmek üzere. Bahadır ŞAHİN
0 comments:
Yorum Gönder