I have a problem, I want to select a row in gridview on mouse click.
My code is this :
protected void PeopleGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';";
e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.gvdetails, "Select$" + e.Row.RowIndex);
}
}
it is not working. i don't know why?
plz suggest me regarding that.
"Thanks"
Found the tutorial about ASP.Net select row in gridview
In ASPX page under GridView tag add:
<SelectedRowStyle BackColor="Orange" />
In code behind try the following:
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
foreach (GridViewRow row in PeopleGridView.Rows) {
if (row.RowType == DataControlRowType.DataRow) {
row.Attributes["onmouseover"] =
"this.style.cursor='hand';this.style.textDecoration='underline';";
row.Attributes["onmouseout"] =
"this.style.textDecoration='none';";
// Set the last parameter to True
// to register for event validation.
row.Attributes["onclick"] =
ClientScript.GetPostBackClientHyperlink(PeopleGridView,
"Select$" + row.DataItemIndex, true);
}
}
base.Render(writer);
}
You can then catch this event using the RowCommand (something like).
private void PeopleGridView_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
{
if (e.CommandName == "Select") {
// Get the list of customers from the session
List<Customer> customerList =
Session["Customers"] as List<Customer>;
Debug.WriteLine(customerList[Convert.ToInt32(e.CommandArgument)].LastName);
}
}
Related
I would like to make the activity tab disappear from the code (condition caseClassid)... Not having succeeded, I tried to make the actions inactive, I don't have any errors but it doesn't work, the screen is the CR306000, thank you ! Xavier FFY
public class CRCaseMaint_Extension : PXGraphExtension<CRCaseMaint>
{
#region Event Handlers
protected void CRCase_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
var row = (CRCase)e.Row;
if (row == null) return;
Boolean xm_valfinale=true;
if ((row.CaseClassID=="F") ||(row.CaseClassID=="D"))
{
xm_valfinale=false;
PXUIFieldAttribute.SetWarning<CRCase.subject>(cache, row, "Il est nécessaire de renseigner la bonne famille !");
}
Base.Activities.AllowInsert = xm_valfinale;
Base.Activities.AllowUpdate = xm_valfinale;
Base.Activities.AllowDelete = xm_valfinale;
}
}
You need to use
Base.Activities.AllowSelect = xm_valfinale;
And on the PXTabItem in the ASPX, set
RepaintOnDemand="false"
I am trying to add a taxonomy web tagging control on to the UI dynamically when a button click event is raised, the button is placed inside of an update panel, i followed many links and as per the suggestions i am adding code for endrequest method for taxonomy controls... Adding a taxonomy control dynamically works fine if you do on page load but my scenario is to add them when a button clic event was raised from update panel ..... any help is appreciated.
public partial class TestTaxanamyControl : WebPart
{
public TestTaxanamyControl()
{
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
InitializeControl();
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void PostbackButton_OnClick(object sender, EventArgs e)
{
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
TaxonomyWebTaggingControl TaxonomyControl = new TaxonomyWebTaggingControl();
SPContext context = SPContext.Current;
SPSite site = context.Site;
TaxonomySession session = new TaxonomySession(site);
TermStore termStore = session.TermStores[0];
Group group = termStore.Groups[0];
TermSet productsTermSet = group.TermSets[0];
TaxonomyControl.SspId.Add(termStore.Id);
TaxonomyControl.TermSetId.Add(productsTermSet.Id);
TaxonomyControl.IsAddTerms = true;
TaxonomyControl.AllowFillIn = true;
TaxonomyControl.IsMulti = true;
div1.Controls.Add(TaxonomyControl);
String key = "TaxonomyWebTaggingAjaxIncludeOnce";
if (!this.Page.ClientScript.IsClientScriptBlockRegistered(base.GetType(), key))
{
this.Page.ClientScript.RegisterClientScriptBlock(base.GetType(), key, GetReloadJavaScript(TaxonomyControl), true);
}
//TextBox txt = new TextBox();
//txt.ID = "text";
//txt.Text = "Sample Text";
//div1.Controls.Add(txt);
}
private string GetReloadJavaScript(TaxonomyWebTaggingControl taxonomyControl)
{
String script = String.Empty;
String containerId = SPEncode.ScriptEncode(taxonomyControl.Controls[1].ClientID);
Type type_TaxonomyWebTaggingControl = typeof(TaxonomyWebTaggingControl);
MethodInfo mi_getOnloadJavascript = type_TaxonomyWebTaggingControl.GetMethod("getOnloadJavascript", BindingFlags.NonPublic | BindingFlags.Instance);
String fullScript = (String)mi_getOnloadJavascript.Invoke(taxonomyControl, null);
int pos = fullScript.IndexOf(String.Format("function {0}_load()", containerId));
if (pos > -1)
{
StringBuilder builder = new StringBuilder();
builder.Append("var myPrm = Sys.WebForms.PageRequestManager.getInstance();");
builder.Append("myPrm.add_endRequest(EndRequest);");
builder.Append("function EndRequest(sender, args)");
builder.Append("{");
// we get te first part of the script needed to initialization
// we start from pos 1, because we don't need the leading '{'
builder.Append(fullScript.Substring(1, pos - 1));
builder.Append("Microsoft.SharePoint.Taxonomy.ScriptForWebTaggingUI.onLoad('");
builder.Append(containerId);
builder.Append("');");
builder.Append("}}");
script = builder.ToString();
}
return script;
}
}
/////////////////// ASPX DESIGN PAGE MARKUP///////////////////////
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Always" RenderMode="Block" runat="server">
<ContentTemplate>
<div id="div1" runat="server">
</div>
<p><asp:LinkButton ID="PostbackButton" OnClick="PostbackButton_OnClick" runat="server">Postback</asp:LinkButton></p>
<p><asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">GetControl</asp:LinkButton></p>
</ContentTemplate>
</asp:UpdatePanel>
I've created a custom event document that extends the fields of the normal event document. I've added a field that can keep 0 to many category Ids in a pipe delimited list. Categories are stored in a custom table.
Here is my filter code:
public partial class CMSGlobalFiles_EventCategoryFilter : CMSAbstractDataFilterControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected override void OnInit(EventArgs e)
{
SetupControl();
base.OnInit(e);
}
protected override void OnPreRender(EventArgs e)
{
if (RequestHelper.IsPostBack())
{
setFilter();
}
base.OnPreRender(e);
}
private void SetupControl()
{
if (this.StopProcessing)
{
this.Visible = false;
}
else if (!RequestHelper.IsPostBack())
{
InitializeCategory();
}
}
private void InitializeCategory()
{
CustomTableItemProvider customTableProvider = ne CustomTableItemProvider(CMSContext.CurrentUser);
string where = "";
string tableName = "customtable.EventCategory";
DataClassInfo customTable = DataClassInfoProvider.GetDataClass(tableName);
if (customTable != null)
{
DataSet dataSet = customTableProvider.GetItems(tableName, where, null);
if (!DataHelper.DataSourceIsEmpty(dataSet))
{
this.drpCategory.DataSource = dataSet;
this.drpCategory.DataTextField = "CategoryName";
this.drpCategory.DataValueField = "ItemGUID";
this.drpCategory.DataBind();
this.drpCategory.Items.Insert(0, new ListItem("(all)", "##ALL##"));
}
}
}
private void setFilter()
{
string where = null;
if (this.drpCategory.SelectedValue != null)
{
Guid itemGUID = ValidationHelper.GetGuid(this.drpCategory.SelectedValue, Guid.Empty );
if (itemGUID != Guid.Empty)
{
where = "EventCategory LIKE \'%" + itemGUID.ToString() + "%\'";
}
}
if (where != null)
{
this.WhereCondition = where;
}
this.RaiseOnFilterChanged();
}
}
This filter works great using a basic repeater and a document data source. When I use the event calendar it does not. I'm using Kentico version 6.0.30
The problem is in the different lifecycle of the EventCalendar, based on the CMSCalendar control which is based on standard .Net Calendar.
First of all, our developers discovered a way to fix this and allow your scenario to run by default. This fix will be included in the 6.0.33 hotfix (scheduled to go out on Friday 25th).
I'm sorry for this inconvenience.
Aside from this upcoming fix, it's also possible to make the EventCalendar to filter its results by modifying (cloning) the web part, integrating the filter controls directly into that web part and set the calendar's Where condition in the OnPreRender before the DataBind as
protected override void OnPreRender(EventArgs e)
{
calItems.WhereCondition = "some filtering condition";
...
If you can hotfix your CMS instance, it would be certainly less effort.
Regards,
Zdenek / Kentico Support
I am dynamically creating a RadGrid and adding GridTemplateColumns to it. Those columns have textbox in them.
After binding datatable to the grid, after user makes changes to the textboxes and on clicking save button, I would like to access the textbox values. But I am stuck at getting hold of the textbox instance. I couldn't even get hold of GridItems!
To add more complexity, my RadGrid is in a UserControl, which is in a (multi)view.
Heres the code.
protected void Page_Init(object sender, EventArgs e)
{
DefineGridStructure();
}
protected void Page_Load(object sender, EventArgs e)
{
if (RadGrid1 != null && RadGrid1.Items.Count > 0)
{
string strtxt = ((TextBox)RadGrid1.Items[1]["ProductGroup1"].Controls[0]).Text;//For starters, load one control and check it's state
}
}
private void DefineGridStructure()
{
RadGrid1 = new RadGrid();
RadGrid1.AutoGenerateColumns = false;
RadGrid1.ShowHeader = true;
RadGrid1.NeedDataSource += RadGrid1_NeedDataSource;
foreach(GridColumn qtyColumn in BuildGridQtyColumns(PaxColumnCount))
{
RadGrid1.MasterTableView.Columns.Add(qtyColumn);
}
//Add grid to page
phRadGrid.Controls.Add(RadGrid1);
}
private List<GridColumn> BuildGridQtyColumns(int count)
{
List<GridColumn> qtyColumns = new List<GridColumn>();
for (int i = 1; i <= count; i++)
{
string qtyColumnName = string.Format("ProductGroup{0}", i);
GridTemplateColumn qtyColumn = new GridTemplateColumn();
qtyColumn.ItemTemplate = new GridNumberTemplate(qtyColumnName);//Creates a textbox control
qtyColumn.UniqueName = qtyColumnName;
qtyColumn.HeaderText = "Qty";
qtyColumn.HeaderStyle.Width = Unit.Pixel(60);
qtyColumn.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
qtyColumns.Add(qtyColumn);
}
return qtyColumns;
}
Since my control is in view, it's Page_Init is called more than once for each action that involves this view.
For a dynamically generated radgrid, it should be created in page_init method and viewstate for this grid will be restored for us automatically which we can get hold of in page_load method.
I have a usercontrol that I want to have the grid inside so I don't have to duplicate that grid on every page. Except when I sort, page, or anything that does a post back the usercontrol reloads and loses its datasource. My plan is to retrieve the search criteria from the parent page(since it already has it from the criteria controls). That way when the NeedDataSource is called it still has the criteria to pass back the right results.
How do I get where you see SuperSearch to be whichever page might be the parent like StateToState.
public SearchCriteria SearchCriteria
{
get
{
Page parent = this.Page;
if (parent != null)
{
var superSearch = parent as SuperSearch;
if (superSearch != null) return superSearch.SearchCriteria;
}
return new SearchCriteria();
}
}
Create an event handler 'event EventHandler NeedSearchCriteria' on your usercontrol that gets fired on your parent page
On your aspx page:
<UC:Grid runat="server" ID="ucGrid" OnNeedSearchCriteria="ucGrid_OnNeedSearchCriteria" />
In the code behind:
public void ucGrid_OnNeedSearchCriteria(object sender, EventArgs e)
{
ucGrid.Criteria = Criteria;
}
And on the usercontrol code behind:
public event EventHandler NeedSearchCriteria;
private SearchCriteria _criteria;
public SearchCriteria Criteria
{
get
{
if (_criteria == null && NeedSearchCriteria != null)
{
NeedSearchCriteria(this, new EventArgs());
}
return _criteria ?? new SearchCriteria();
}
set
{
_criteria = value;
}
}