2012-03-06 18 views
1

私はym Webページ上にDataListを持っています。このページから、DataList行内の特定のオプションを選択できます。データリスト内の選択した行をハイライト表示

私はこれにDataListのItemCommandを使用します。実際には、ユーザーが行内の項目をクリックすると、選択した行を強調表示したいと思います。

上記のように、ユーザーはLinkBut​​tonをクリックして項目を選択できます。対応する行またはセルのみをハイライト表示するにはどうすればよいですか?

答えて

0

使用し、選択された行を強調表示するためにデータリストのための方法を、以下:項目コマンドの

protected void DataList1_ItemDataBound(object sender, 
          DataListItemEventArgs e) 
{ 
    if (e.Item.ItemType == ListItemType.Item || 
     e.Item.ItemType == ListItemType.AlternatingItem) 
    { 
     //Add eventhandlers for highlighting 
     //a DataListItem when the mouse hovers over it. 
     e.Item.Attributes.Add("onmouseover", 
       "this.oldClass = this.className;" + 
       " this.className = 'EntryLineHover'"); 
     e.Item.Attributes.Add("onmouseout", 
       "this.className = this.oldClass;"); 
     //Add eventhandler for simulating 
     //a click on the 'SelectButton' 
     e.Item.Attributes.Add("onclick", 
       this.Page.ClientScript.GetPostBackEventReference(
       e.Item.Controls[1], string.Empty)); 
    } 
} 
0

RowDataBoundイベントには、このように追加します。

// Get the linklabel object and check for non nullity 
LinkLabel lblItem = e.Item.FindControl("Item") as LinkLabel 

if(lblitem !=null) 
{ 
// add properties to it 
lblItem.Attributes.Add("onclick", "this.style.background='#eeff00'"); 

} 
0

string[] str = e.CommandArgument.ToString().Split(';'); 
int index = Convert.ToInt32(str[2]); // ur item selected index 
DataListItemCollection xx = DataList1.Items; 
int count = 0; 
foreach (DataListItem x in xx) 
{ 
    if (count == index) 
    { 
     (x.FindControl("Item") as LinkButton).BorderColor = System.Drawing.Color.Red; 
     (x.FindControl("Item") as LinkButton).BorderWidth = 1; 
    } 
    else 
    { 
     (x.FindControl("Item") as LinkButton).BorderColor = System.Drawing.Color.White; 
     (x.FindControl("Item") as LinkButton).BorderWidth = 0; 

    } 
count = count + 1; 
} 
関連する問題