14 Mayıs 2013 Salı

Gridview kolon adı bilgisine ulaşmak

Gridview kolon adlarına ulaşmak için kod ;

Hardcoded approach:
string searchValue = "SpecifiedName";
// where 1 is the hardcoded cell index
var query = from GridViewRow row in GridView1.Rows
            where row.Cells[1].Text == searchValue
            select row;
GridViewRow result = query.FirstOrDefault();
Dynamic Approach (Column Index Lookup):
string colName = "name";
int index = (from DataControlField col in GridView1.Columns
            where col.HeaderText == colName
            select GridView1.Columns.IndexOf(col)).FirstOrDefault();

// index used
var query = from GridViewRow row in GridView1.Rows
        where row.Cells[index].Text == searchValue
        select row;
GridViewRow result = query.FirstOrDefault();
Alternate index lookup: instead of using HeaderText you can use BoundField.
int index = (from DataControlField col in GridView1.Columns
            where ((BoundField)col).DataField == colName
            select GridView1.Columns.IndexOf(col)).FirstOrDefault();

WinForm DataGridView

Kept this here just in case.
string name = "SpecifiedName";
var query = from DataGridViewRow row in dataGridView1.Rows
            where row.Cells["name"].Value.ToString() == name
            select row;
// the row will be returned by this or contain a default value if not found
DataGridViewRow result = query.FirstOrDefault();
Share:

10 Mayıs 2013 Cuma

Masterpage css link class erişimi




--------Masterpage code source---------

<li><a href="home.aspx" id="HomeLink" runat="server"><i class="home"></i> Home</a></li>
<li><a href="Calendar.aspx" id="CalendarLink" runat="server"><i class="calendar"></i>Calendar</a></li>
<li><a href="Bill.aspx" id="BillLink" runat="server"><i class="list"></i>Bills</a></li>



-------Masterpage code behind---------


protected void Page_Load(object sender, EventArgs e)
    {
        SetCurrentPage();
    }

    private void SetCurrentPage()
    {
        var pageName = GetPageName();

        switch (pageName)
        {
            case "home.aspx":
                HomeLink.Attributes["class"] = "current";
                break;
            case "Calendar.aspx":
                CalendarLink.Attributes["class"] = "current";
                break;
            case "Bill.aspx":
                BillLink.Attributes["class"] = "current";
                break;
        }
    }

    private string GetPageName()
    {
        return Request.Url.ToString().Split('/').Last();
    }

Share:

Blog Arşivi