RadGrid(ItemDataBound method) Get value of cell
protected void gridAddendum_ItemDataBound(object sender, GridItemEventArgs e)
{
//Is it a GridDataItem
if (e.Item is GridDataItem)
{
//Get the instance of the right type
GridDataItem dataBoundItem = e.Item as GridDataItem;
var logid = dataBoundItem["LogId"].Text;
var deleted = dataBoundItem["Deleted"].Text; // this is a boolean
var Ownerid = dataBoundItem["OwnerId"].Text;
var locked = Convert.ToBoolean(dataBoundItem["Locked"].Text); // this is a boolean
}
}
CheckBox Databind in RadGrid Row
ASPX:
<telerik:GridTemplateColumn HeaderText="Update">
<ItemTemplate>
<asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="true" Checked='<%# Bind("FieldName") %>' OnCheckedChanged="CheckBox2_CheckedChanged" />
</ItemTemplate>
</telerik:GridTemplateColumn>
CS:
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk = (CheckBox)sender;
bool status = chk.Checked;
GridDataItem item = (GridDataItem)chk.NamingContainer;
string keyvalue = item.GetDataKeyValue("CustomerID").ToString() ; // Set the DataKeyNames property of MasterTableView to CustomerID
// create and execute the query to update the field
}
Fetching Data from Database and Populating fields in the Form using LINQ to SQL
In my previous example I have demonstrated how to create a simple form that would allow users to insert data to the database using L2S. In this example I’m going to demonstrate how to fetch and filter data from database and fill the fields in the form using L2S. This example is basically a continuation of my previous example. So I would suggest you to take a look at my previous example first before you proceed reading this example.
STEP 1: Setting up the GUI
To get started, add a new WebForm to your application and set up the GUI. Again just for the simplicity of this demo,I just set up the GUI like this:
Continue reading »
RadGrid Getting Cell Values for Selected Rows Client-side
Getting Cell Values for Selected Rows Client-side
A fairly common task is to retrieve the values of column cells when the row that contains them is selected. This can be accomplished using the getCellByColumnUniqueName method of the GridTableView client-side object. This method takes two parameters: a row object and the UniqueName of a column. It returns the corresponding cell from the grid table.
The following example illustrates this process. It gets the cell in two cases:
At the point when the row is selected (in the RowSelected event hander)
From the onclick handler of a button placed outside the grid.
Note that this example works for a grid that allows multi-row selection.
<pre>
<script type="text/javascript">
function RowSelected(sender, eventArgs) {
var grid = sender;
var MasterTable = grid.get_masterTableView(); var row = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()];
var cell = MasterTable.getCellByColumnUniqueName(row, "CategoryID");
//here cell.innerHTML holds the value of the cell
}
function GetSelectedNames() {
var grid = $find("<%=RadGrid1.ClientID %>");
var MasterTable = grid.get_masterTableView();
var selectedRows = MasterTable.get_selectedItems();
for (var i = 0; i < selectedRows.length; i++) {
var row = selectedRows[i];
var cell = MasterTable.getCellByColumnUniqueName(row, "CategoryID")
//here cell.innerHTML holds the value of the cell
}
}
</script>
<telerik:RadGrid ID="RadGrid1" runat="server" AllowMultiRowSelection="True" DataSourceID="dsProducts">
<ClientSettings>
<Selecting AllowRowSelect="True" />
<ClientEvents OnRowSelected="RowSelected" />
</ClientSettings>
</telerik:RadGrid><input onclick="GetSelectedNames();" type="button" value="Get selected rows contact names">
</pre>
radgrid getselectedrow cell value
function GetSelectedItems() {
//alert($find(“<%= RadGrid1.MasterTableView.ClientID %>”).get_selectedItems().length);
var grid = $find(“<%=RadGrid1.ClientID %>”);
var MasterTable = grid.get_masterTableView();
var selectedRows = MasterTable.get_selectedItems();
var row = selectedRows[0];
var cell = MasterTable.getCellByColumnUniqueName(row, “Aciklama”);
//alert(cell.innerHTML);
//var lbl = $find(“<%=Label2.ClientID %>”);
document.getElementById(‘aaa’).innerHTML = cell.innerHTML;
}
NavigateUrl and EVAL
Here is how you can add a database value to the URL of a HyperLink that is in a GridView. In this example the text displayed is the same as the value added to the URL. Also the data is bound through a SqlDataSource and the “ID” value is from the output of the Select statement the SqlDataSource uses. This is a quick way to put the data in the URL without using any code in the code behind.
<asp:TemplateField HeaderText=”ID” >
<ItemTemplate>
<asp:HyperLink ID=”hlID” runat=”server” Text=’<%# EVAL(“ID”) %>‘ NavigateUrl=’<%#”Default.aspx?ID=” + EVAL(“ID”) %>‘/>
</ItemTemplate>
</asp:TemplateField>
server.mappath(“.”), server.mappath(“~”), server.mappath(@“\”), server.mappath(“/”). What is the difference?
Server.MapPath specifies the relative or virtual path to map to a physical directory.
- Server.MapPath(“.”) returns the current physical directory of the file (e.g. aspx) being executed
- Server.MapPath(“..”) returns the parent directory
- Server.MapPath(“~”) returns the physical path to the root of the application
- Server.MapPath(“/”) returns the physical path to the root of the domain name (is not necessarily the same as the root of the application)
An example:
Let’s say you pointed a web site application (http://www.example.com/) to
C:\Inetpub\wwwroot
and installed your shop application (sub web as virtual directory in IIS, marked as application) in
D:\WebApps\shop
For example, if you call Server.MapPath in following request:
http://www.example.com/shop/products/GetProduct.aspx?id=2342
then:
- Server.MapPath(“.”) returns
D:\WebApps\shop\products - Server.MapPath(“..”) returns
D:\WebApps\shop - Server.MapPath(“~”) returns
D:\WebApps\shop - Server.MapPath(“/”) returns
C:\Inetpub\wwwroot - Server.MapPath(“/shop”) returns
D:\WebApps\shop
If Path starts with either a forward (/) or backward slash (\), the MapPath method returns a path as if Path were a full, virtual path.
If Path doesn’t start with a slash, the MapPath method returns a path relative to the directory of the request being processed.
Note: in C#, @ is the verbatim literal string operator meaning that the string should be used “as is” and not be processed for escape sequences.
yerel yazdırma biriktiricisi çalışmıyor !

yerel yazdırma biriktiricisi çalışmıyor !
sorununu gidermek için aşağıdaki kodu bir alıp not defterine yapıştırıp .bat dosyası olarak kaydedin. Kaydettiğiniz bat dosyanızı yönetici olarak çalıştırın.
net stop spooler
del /q %SystemRoot%\System32\spool\printers\*.*
net start spooler
WordPress sayfalama problemi
WordPress blogumumda sayfalama ile ilgili bir hata gözüme çarptı. Sayfalama sistemim çalışmıyor. Sayfalama linklerime baktığımda şöyle bir durumla karşılaştım.
index.php/index.php/page/2/
Sorun görüldüğü gibi “index.php” nin iki kere yazılmasından kaynaklanıyor.
Bu sorunu şöyle hallettim : Continue reading »
Autocomplete örneği
Merhaba ;
Facebook yada google ı biliyoruz. Bir şey aramak üzere giriş kutusuna bir şeyler yazmaya başlayınca hemen bize asistanlık yapmaya başlıyor, aradığımız şeye yakın ihtimalleri bize listeleyerek işimizi kolaylaştırıyor. Bu yazıda Ajax Control Toolkit deki AutoCompleteExtender kontrolu ile benzer bir uygulama yapacağım.
AutoCompleteExtender kontrolu ilişkili olduğu TexBox ın her değişmesinde sizin belirlediğiniz bir süre içinde bir web servisi çalıştırıp web servisinin dizi tipinde ürettiği sonuçları ekranda listeleyebiliyor.
İlk olarak AutoCompleteExtender ve TextBox kontrolu çalışma alanıma ekleyelim. Extender ı aşağıdaki gibi düzenleyelim.
<asp:AutoCompleteExtender ID="autoCompleteMain"
runat="server"
ServicePath="AutoComplete.svc"
ServiceMethod="GetUserNameList"
CompletionSetCount="10"
MinimumPrefixLength="1"
TargetControlID="TextBox1"
CompletionInterval="0"
FirstRowSelected="True" >
</asp:AutoCompleteExtender>
Buradaki özelliklere kısaca bakalım:
ServicePath : Çağırılacak metodun bulunduğu servis dosyasının yolu ve adı
ServiceMethod : Kullanılacak metod. (Bizim GetUserNameList metodumuz aşağıda)
CompletionSetCount : Buda webmetodumuzdaki ikinci (count) parametre. Webmetod burda belirtilen sayıda sonuç döndürecektir. Örnekde 10 ayarladım bu; metin kutusu altında 10 sonuçluk bir liste oluşacağı anlamına gelir.
MinimumPrefixLength : Metin kutusuna kaç eleman girilince otomatik tamamlamanın çalışmaya başlayacağını açıklar. Hep çalışması için 1 olarak ayarladım. Sunucuyu meşgul edeceğini göz önüne alarak bu özellik ayarlanmalıdır.
TargetControlID : Extend edilecek TextBox kontrolümüz.
CompletionInterval : Servisin çalışma süresini ms cinsinden belirtiyoruz. 0 ayarlanması durumunda Textbox her değişmesinde hiç beklemeden webmetodu çalıştıracaktır.
FirstRowSelected : Listedeki ilk elemanı otomatik seçili hale getirmek için.
Daha sonra bahsettiğim web servisini ekleyelim. Kişiler tablomdaki isimleri prefixText ‘e göre listeleyen linq sorgusu çalıştırılıyor. Web servisinin içeriği aşağıdaki gibi.
public String[] GetUserNameList(String prefixText, Int32 count)
{
DataClassesDataContext Person = new DataClassesDataContext();
var kisi = from P in Person.Persons where P.Name.Contains(prefixText) select P.Name;
return kisi.ToArray();
}
Sonuç :






