Tuesday, August 26, 2008

Handaling data row bound event as required C# Asp.net

Handaling data row bound event

protected void gvAvailableVideos_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lbtnVideoFile = ((LinkButton)e.Row.Cells[0].FindControl("lbtnVideoFile"));
if (lbtnVideoFile != null)
{
lbtnVideoFile.Text = gvAvailableVideos.DataKeys[rowno]["VideoFileName"].ToString();
DataView dv = DsMediaFiles.Tables[0].DefaultView;
dv.Sort = "id";
int rowId = dv.Find(gvAvailableVideos.DataKeys[rowno]["Id"]);
string VideoPath = string.Empty;
int VideoId;
if (rowId != -1)
{
VideoPath = System.Configuration.ConfigurationManager.AppSettings["StreamingServerPath"].ToString() + dv[rowId]["VideoPath"].ToString();
VideoId = Convert.ToInt32(dv[rowId]["Id"].ToString());
lbtnVideoFile.Attributes.Add("OnClick", "return SetMovie('" + VideoPath + "','" + VideoId + "')");
}

}

HyperLink hlnkAttachment = ((HyperLink)e.Row.Cells[2].FindControl("hlnkAttachment"));
if (hlnkAttachment != null)
{
hlnkAttachment.Text = gvAvailableVideos.DataKeys[rowno]["AttachmentName"].ToString();
hlnkAttachment.NavigateUrl = gvAvailableVideos.DataKeys[rowno]["AttachmentPath"].ToString();
hlnkAttachment.Target = "_blank";
}
rowno += 1;

if (e.Row.Cells[1].Text.Length > Convert.ToInt32(Constants.GridCharactorLength))
{
e.Row.Cells[1].ToolTip = e.Row.Cells[1].Text;
e.Row.Cells[1].Text = e.Row.Cells[1].Text.Substring(0, Convert.ToInt32(Constants.GridCharactorLength)) + "....";
//e.Row.Cells[1].Text = e.Row.Cells[1].Text.ToUpper();

}

}
}

No comments: