Hello again,
I need some help to know how i can get a property from the selectedItem of my Radgrid, so i can execute a delete on a table on my database...
I'm populating data from a stored procedure, using entity.
I need to when click a button "delete", get a property("UserName") from RadGrid2 selected Item, so i can use it like a parametter and execute a storeCommand like this:
I need some help to know how i can get a property from the selectedItem of my Radgrid, so i can execute a delete on a table on my database...
I'm populating data from a stored procedure, using entity.
EscalonamentoFacturasEntities objectContx = new EscalonamentoFacturasEntities(); RadGrid2.DataSource = objectContx.UsersAssignResume(); RadGrid2.DataBind();I need to when click a button "delete", get a property("UserName") from RadGrid2 selected Item, so i can use it like a parametter and execute a storeCommand like this:
objectContx.ExecuteStoreCommand(
"Delete from Table Where Table.UserName = @par");
11 Answers, 1 is accepted
0
Ricardo
Top achievements
Rank 1
answered on 23 Aug 2011, 05:09 PM
I forget to tell that my RadGrid have autogenerateCollumns "True" ...
Here is the code:
Here is the code:
<telerik:RadGrid ID="RadGrid2" runat="server" Skin="Black" CellSpacing="0" GridLines="None" Width="460px" Height="400px" AllowSorting="True"> <ClientSettings> <Selecting AllowRowSelect="True" /> <Scrolling AllowScroll="True" UseStaticHeaders="False" /> </ClientSettings> <MasterTableView> <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings> <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"> <HeaderStyle Width="20px"></HeaderStyle> </RowIndicatorColumn> <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"> <HeaderStyle Width="20px"></HeaderStyle> </ExpandCollapseColumn> <EditFormSettings> <EditColumn FilterControlAltText="Filter EditCommandColumn column"> </EditColumn> </EditFormSettings> </MasterTableView> <FilterMenu EnableImageSprites="False"> </FilterMenu> <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Windows7"> </HeaderContextMenu> </telerik:RadGrid>0
Ricardo
Top achievements
Rank 1
answered on 23 Aug 2011, 05:52 PM
At this moment i have another doubt...It's possible to get more than one datakeyname for the selectedItem ??
I have this code, but at this time i can't get inside the if clause:
However I need to make a delete but with all the columns values for the selectedItem...To make my query like this:
Is possible to get all the values using datakeysNames???
I have this code, but at this time i can't get inside the if clause:
rotected void RadButton4_Click(object sender, EventArgs e) { EscalonamentoFacturasEntities objectContx = new EscalonamentoFacturasEntities(); foreach (GridDataItem item in RadGrid2.Items) { if (item.Selected) { string test = item.GetDataKeyValue("UserName").ToString(); objectContx.ExecuteStoreCommand("Delete from UsersAssign Where CompName = {0}", item.GetDataKeyValue("UserName").ToString()); } }However I need to make a delete but with all the columns values for the selectedItem...To make my query like this:
objectContx.ExecuteStoreCommand("Delete from UsersAssign Where CompName = {0} AND Priority = {1} AND Staging = {2}", item.GetDataKeyValue("UserName").ToString(), @par2, @par3);0
Jayesh Goyani
Top achievements
Rank 2
answered on 23 Aug 2011, 07:26 PM
Hello,
Yes it is possible,
Please check below code snippet.
Thanks,
Jayesh Goyani
Yes it is possible,
Please check below code snippet.
<MasterTableView DataKeyNames="ID,Name,Address" >oreach (GridDataItem item in RadGrid1.Items) { if (item.Selected) { int ID =Convert.ToInt32(item.GetDataKeyValue("ID").ToString()); string strName = item.GetDataKeyValue("Name").ToString(); string strAddress = item.GetDataKeyValue("Address").ToString(); objectContx.ExecuteStoreCommand("Delete from UsersAssign Where CompName = {0}", item.GetDataKeyValue("UserName").ToString()); } }Thanks,
Jayesh Goyani
0
Ricardo
Top achievements
Rank 1
answered on 23 Aug 2011, 08:31 PM
Hello Jayesh after tried your code...I verify that nover get inside the condition:
if (item.Selected)
Can you help me??? After i click the button and raise the event the app don't recognize any item as selected....0
Jayesh Goyani
Top achievements
Rank 2
answered on 24 Aug 2011, 08:10 AM
Hello,
Please check below code snippet.
Let me know if you not understand.
if you not solve your issue then please provide your code also.
Thanks,
Jayesh Goyani
Please check below code snippet.
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="true" OnNeedDataSource="RadGrid1_NeedDataSource" AllowMultiRowSelection="true"> <MasterTableView DataKeyNames="ID,Name"> </MasterTableView> <ClientSettings> <Selecting AllowRowSelect="true" /> </ClientSettings> </telerik:RadGrid> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { dynamic data = new[] { new { ID = 1, Name ="Name1"}, new { ID = 2, Name = "Name2"}, new { ID = 3, Name = "Name3"}, new { ID = 4, Name = "Name4"}, new { ID = 5, Name = "Name5"}, new { ID = 6, Name ="Name6"}, new { ID = 7, Name = "Name7"}, new { ID = 8, Name = "Name8"}, new { ID = 9, Name = "Name9"}, new { ID = 10, Name = "Name10"}, new { ID = 11, Name ="Name11"}, new { ID = 12, Name = "Name12"}, new { ID = 13, Name = "Name13"}, new { ID = 14, Name = "Name14"}, new { ID = 15, Name = "Name15"} }; RadGrid1.DataSource = data; } protected void Button1_Click(object sender, EventArgs e) { foreach (GridDataItem item in RadGrid1.Items) { if (item.Selected) { int ID = Convert.ToInt32(item.GetDataKeyValue("ID").ToString()); string strName = item.GetDataKeyValue("Name").ToString(); } } }Let me know if you not understand.
if you not solve your issue then please provide your code also.
Thanks,
Jayesh Goyani
0
Ricardo
Top achievements
Rank 1
answered on 24 Aug 2011, 09:18 AM
Hello Jayesh...
My last code is bellow, i still don't get inside the if clause...Can you please take a look...
ASPX.CS
And that's my ASPX:
My last code is bellow, i still don't get inside the if clause...Can you please take a look...
ASPX.CS
protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { this._presenter.OnViewInitialized(); //criar instancia da Info para aceder ao metodo que me vai buscar a lista de users ao AD Info x = new Info("mchdfcq", "Fcp2004", "LDAP://mch.moc.sgps/DC=mch,DC=moc,DC=sgps"); //get da lista dos direct report em user,key para manager(alice silva) Dictionary<string, string> networkUser = new Dictionary<string, string>(); networkUser = x.GetHierarchyTree("apsilva3"); //Lista para preencher com key=user de rede e respectivo nome completo Dictionary<string, string> aux = new Dictionary<string, string>(); foreach (KeyValuePair<string, string> kvp in networkUser) { //kvp.Key = user de rede string userCompName = x.GetUserInfo("cn", kvp.Key); aux.Add(kvp.Key, userCompName);//Dictionary com key = user de rede e Value = nomeCompleto Utilizador } //Popular dados na listBox de Users com o nome completo e como value o user de rede RadListBox1.DataTextField = "Value"; RadListBox1.DataValueField = "Key"; RadListBox1.DataSource = aux; RadListBox1.DataBind(); //popuplar users sem assign RadGrid3.DataSource = this.Unassigned; RadGrid3.HorizontalAlign = HorizontalAlign.Left;//Not working!!!!! RadGrid3.DataBind(); //Popular dados na listbox stagins RadListBox2.DataSource = this.Staging; RadListBox2.DataTextField = "Process"; RadListBox2.DataValueField = "Process"; RadListBox2.DataBind(); //Popular dados na listbox grupos //para fazer o get das prioridades especificas a uma stanging basta fazer 1 select da table //das prioridades from sapdocuments left join priorities e staging RadListBox3.DataSource = this.Priorities; RadListBox3.DataTextField = "Priority"; RadListBox3.DataValueField = "Priority"; RadListBox3.DataBind(); } this._presenter.OnViewLoaded(); //para ir buscar o login user //Implementar o presenter(xamar o metodo) o interface da view , add da propriedade aqui //MessageBox.Show("TOTAL INVOICES" + this.SapDocuments.Count); //Popular dados no Daily Resume EscalonamentoFacturasEntities objectContx = new EscalonamentoFacturasEntities(); RadGrid1.DataSource = objectContx.ScalingResume(); RadGrid1.DataBind(); object ob = RadGrid1.SelectedValue; //Popular dados no Resumo Users Atribuidos RadGrid2.DataSource = objectContx.UsersAssignResume(); RadGrid2.DataBind(); //List<ScalingResume_Result> procReturn = objectContx.ScalingResume().ToList(); //string Description, Staging; //int? Priority, TotalInvoice; //foreach (ScalingResume_Result v in procReturn) //{ // Description = v.Description; // Priority = v.Priority; // Staging = v.Staging; // TotalInvoice = v.TotalInvoices; //} //Popular dados no Resumo Users Atribuidos RadGrid4.DataSource = objectContx.UnassignedInvoicesResume(); RadGrid4.HorizontalAlign = HorizontalAlign.Left; RadGrid4.DataBind(); } ............ protected void RadButton4_Click(object sender, EventArgs e) { EscalonamentoFacturasEntities objectContx = new EscalonamentoFacturasEntities(); foreach (GridDataItem item in RadGrid2.Items) { string test = item.GetDataKeyValue("UserName").ToString(); //if (item.Selected) //{ objectContx.ExecuteStoreCommand("Delete from UsersAssign Where CompName = {0}", item.GetDataKeyValue("UserName").ToString()); //} } //actualiza o resumo de assigned users RadGrid2.DataSource = objectContx.UsersAssignResume(); RadGrid2.DataBind(); //Popular dados no Resumo Users Atribuidos RadGrid4.DataSource = objectContx.UnassignedInvoicesResume(); RadGrid4.DataBind(); //actualiza o resumo unassigned users UsersAssignBO users = new UsersAssignBO(); this.Unassigned = users.GetUnassignedUsers(); RadGrid3.DataSource = this.Unassigned; RadGrid3.DataBind(); }And that's my ASPX:
............... <telerik:RadPageView ID="pvAssignInvoices" runat="server"> <table> <tr> <td> <telerik:RadListBox ID="RadListBox1" runat="server" AllowReorder="True" Skin="Black" Sort="Ascending" Height="400px" Width="220px" EnableDragAndDrop="True"> <ButtonSettings TransferButtons="All"></ButtonSettings> <HeaderTemplate> <h5 style="color: White; text-align: center"> USERS</h5> </HeaderTemplate> </telerik:RadListBox> </td> <td> <telerik:RadListBox ID="RadListBox2" runat="server" EnableDragAndDrop="True" Height="400px" AllowReorder="True" Width="140px" Skin="Black"> <ButtonSettings TransferButtons="All"></ButtonSettings> <HeaderTemplate> <h5 style="color: White; text-align: center"> STAGING</h5> </HeaderTemplate> </telerik:RadListBox> </td> <td> <telerik:RadListBox ID="RadListBox3" runat="server" SelectionMode="Multiple" EnableDragAndDrop="True" Height="400px" Width="140px" AllowReorder="True" Skin="Black"> <ButtonSettings TransferButtons="All"></ButtonSettings> <HeaderTemplate> <h5 style="color: White; text-align: center"> GROUP</h5> </HeaderTemplate> </telerik:RadListBox> </td> <td> <telerik:RadButton ID="RadButton1" runat="server" Text="Assign" Skin="Black" Width="100px" Height="40px" OnClick="RadButton1_Click"> </telerik:RadButton> <br /> <br /> <telerik:RadButton ID="RadButton2" runat="server" Text="Unassign" Skin="Black" Width="100px" Height="40px" OnClick="RadButton2_Click"> </telerik:RadButton> <br /> <br /> <telerik:RadButton ID="RadButton3" runat="server" Text="Unassign All" Skin="Black" Width="100px" Height="40px" OnClick="RadButton3_Click"> </telerik:RadButton> <br /> <br /> <telerik:RadButton ID="RadButton4" runat="server" Text="TEST--->" Skin="Black" Width="100px" Height="40px" OnClick="RadButton4_Click"> </telerik:RadButton> </td> <td style="width: 10px"> </td> <td> <telerik:RadGrid ID="RadGrid2" runat="server" Skin="Black" CellSpacing="0" GridLines="None" Width="460px" Height="400px" AllowSorting="True"> <ClientSettings> <Selecting AllowRowSelect="True" /> <Scrolling AllowScroll="True" UseStaticHeaders="False" /> </ClientSettings> <MasterTableView DataKeyNames="UserName,Group,Staging"> <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings> <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"> <HeaderStyle Width="20px"></HeaderStyle> </RowIndicatorColumn> <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"> <HeaderStyle Width="20px"></HeaderStyle> </ExpandCollapseColumn> <EditFormSettings> <EditColumn FilterControlAltText="Filter EditCommandColumn column"> </EditColumn> </EditFormSettings> </MasterTableView> <FilterMenu EnableImageSprites="False"> </FilterMenu> <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Windows7"> </HeaderContextMenu> </telerik:RadGrid> </td> </tr> </table> .................0
Ricardo
Top achievements
Rank 1
answered on 24 Aug 2011, 09:35 AM
Hello again Jayesh i have already tried this code...and the problem remains....I can't get inside the if clause:
protected void RadButton4_Click(object sender, EventArgs e) { EscalonamentoFacturasEntities objectContx = new EscalonamentoFacturasEntities(); foreach (GridDataItem item in RadGrid2.Items) { if (item.Selected) { string usrName = item.GetDataKeyValue("UserName").ToString(); int group = Convert.ToInt32(item.GetDataKeyValue("Group").ToString()); string staging = item.GetDataKeyValue("Staging").ToString(); objectContx.ExecuteStoreCommand("Delete from UsersAssign Where CompName = {0} AND Priority = {1} AND Process = {2}", usrName, group, staging); } } //actualiza o resumo de assigned users RadGrid2.DataSource = objectContx.UsersAssignResume(); RadGrid2.DataBind(); //Popular dados no Resumo Users Atribuidos RadGrid4.DataSource = objectContx.UnassignedInvoicesResume(); RadGrid4.DataBind(); //actualiza o resumo unassigned users UsersAssignBO users = new UsersAssignBO(); this.Unassigned = users.GetUnassignedUsers(); RadGrid3.DataSource = this.Unassigned; RadGrid3.DataBind(); } //ADDED NEW protected void RadGrid2_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { EscalonamentoFacturasEntities objectContx = new EscalonamentoFacturasEntities(); //actualiza o resumo de assigned users RadGrid2.DataSource = objectContx.UsersAssignResume(); RadGrid2.DataBind(); }0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 24 Aug 2011, 10:10 AM
Hello,
step 1
Remove/Comment Below Code From Every where in your page.
step 2
Please modify RadGrid's NeedDataSource Event.
step 3
Modify your Button_clickEvent
Let me know If any concern.
Thanks,
Jayesh Goyani
step 1
Remove/Comment Below Code From Every where in your page.
RadGrid2.DataSource = objectContx.UsersAssignResume();RadGrid2.DataBind()step 2
Please modify RadGrid's NeedDataSource Event.
protected void RadGrid2_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { EscalonamentoFacturasEntities objectContx = new EscalonamentoFacturasEntities(); RadGrid2.DataSource = objectContx.UsersAssignResume(); }step 3
Modify your Button_clickEvent
protected void Button1_Click(object sender, EventArgs e) { foreach (GridDataItem item in RadGrid2.Items) { if (item.Selected) { int ID = Convert.ToInt32(item.GetDataKeyValue("ID").ToString()); string strName = item.GetDataKeyValue("Name").ToString(); } } RadGrid2.Rebind(); }Let me know If any concern.
Thanks,
Jayesh Goyani
0
Ricardo
Top achievements
Rank 1
answered on 24 Aug 2011, 10:40 AM
Thank you a lot Jayesh ;)
0
Ricardo
Top achievements
Rank 1
answered on 25 Aug 2011, 06:48 PM
Now i have another problem, two of the grid columns are navigation properties...The problem is when
i enter on the page, all columns fields has data.But when i click to
sort those two columns came without values..
I have already verify that the list i'm using as DataSource, has allways those two columns with values...The problem is that when i sort the Grid comes without values on "Priority" and "Process" fields.....
That's my code (ASPX.CS)
That's my ASPX Code:
I have already verify that the list i'm using as DataSource, has allways those two columns with values...The problem is that when i sort the Grid comes without values on "Priority" and "Process" fields.....
That's my code (ASPX.CS)
protected void Page_Load(object sender, EventArgs e) { ObjectResult<SapDocuments> objectSapDocs; if (!this.IsPostBack) { this._presenter.OnViewInitialized(); string user = Page.User.Identity.Name.Substring(Page.User.Identity.Name.IndexOf("\\") + 1); EscalonamentoFacturasEntities objectContx = new EscalonamentoFacturasEntities(); objectSapDocs = objectContx.ShowUnprocessedInvoices(user); List<SapDocuments> listSapDocuments = new List<SapDocuments>(); foreach (var item in objectSapDocs) { listSapDocuments.Add(item); } ViewState["Data"] = listSapDocuments; } this._presenter.OnViewLoaded(); if (ViewState["Data"] != null) { RadGrid1.DataSource = (List<SapDocuments>)ViewState["Data"]; } else { RadGrid1.DataSource = null; } //RadGrid1.DataBind(); } [CreateNew] public InvoicesScalePresenter Presenter { set { this._presenter = value; this._presenter.View = this; } } protected void ShowProcessed_Click(object sender, EventArgs e) { ObjectResult<SapDocuments> objectSapDocs; string user = Page.User.Identity.Name.Substring(Page.User.Identity.Name.IndexOf("\\") + 1); EscalonamentoFacturasEntities objectContx = new EscalonamentoFacturasEntities(); objectSapDocs = objectContx.ShowProcessedInvoices(user); List<SapDocuments> listSapDocuments = new List<SapDocuments>(); foreach (var item in objectSapDocs) { listSapDocuments.Add(item); } ViewState["Data"] = listSapDocuments; if (ViewState["Data"] != null) { RadGrid1.DataSource = (List<SapDocuments>)ViewState["Data"]; } else { RadGrid1.DataSource = null; } } ....That's my ASPX Code:
<telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" Width="97%" enableajax="True" AllowFilteringByColumn="True" ShowFooter="True" Skin="Black" OnItemCommand="RadGrid1_ItemCommand" OnGridExporting="RadGrid1_GridExporting" AllowMultiRowSelection="True"> <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle> <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True" EnablePostBackOnRowClick="true"> <Selecting AllowRowSelect="True" /> </ClientSettings> <MasterTableView DataKeyNames="SequencialNumber" Width="100%" CommandItemSettings-ShowExportToCsvButton="True" CommandItemSettings-ShowAddNewRecordButton="false" CommandItemDisplay="Top"> <Columns> <telerik:GridBoundColumn DataField="SequencialNumber" HeaderText="SequencialNumber" UniqueName="SequencialNumber" SortExpression="SequencialNumber"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Priorities.Priority" HeaderText="Priority" UniqueName="Priority" FilterControlAltText="Filter Priority column" SortExpression="Priorities.Priority" DataType="System.Int32"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Staging.Process" HeaderText="Staging" UniqueName="Process" SortExpression="Staging.Process" FilterControlAltText="Filter Process column"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="SupplierCode" HeaderText="SupplierCode" UniqueName="SupplierCode" SortExpression="SupplierCode" FilterControlAltText="Filter SupplierCode column"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="MessageStatus" HeaderText="MessageStatus" UniqueName="MessageStatus" SortExpression="MessageStatus" FilterControlAltText="Filter MessageStatus column"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="DocumentType" HeaderText="DocumentType" UniqueName="DocumentType" FilterControlAltText="Filter DocumentType column" SortExpression="DocumentType"> </telerik:GridBoundColumn> <telerik:GridDateTimeColumn UniqueName="InvoiceCreationDate" DataField="InvoiceCreationDate" HeaderText="InvoiceCreationDate" FilterControlAltText="Filter InvoiceCreationDate column" SortExpression="InvoiceCreationDate"> <FilterTemplate> <telerik:RadDatePicker ID="RadDatePicker1" runat="server"> </telerik:RadDatePicker> </FilterTemplate> </telerik:GridDateTimeColumn> <telerik:GridBoundColumn DataField="SupplierVatNumber" FilterControlAltText="Filter SupplierVatNumber column" HeaderText="SupplierVatNumber" SortExpression="SupplierVatNumber" UniqueName="SupplierVatNumber"> </telerik:GridBoundColumn> </Columns> <ExpandCollapseColumn Visible="False"> <HeaderStyle Width="19px"></HeaderStyle> </ExpandCollapseColumn> <RowIndicatorColumn Visible="False"> <HeaderStyle Width="20px" /> </RowIndicatorColumn> </MasterTableView> <FilterMenu EnableImageSprites="False"> </FilterMenu> <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default"> </HeaderContextMenu> </telerik:RadGrid>0
Jayesh Goyani
Top achievements
Rank 2
answered on 25 Aug 2011, 07:48 PM
Hello,
Please use Grid / Advanced Data Binding for binding the datasource to RadGrid.
I suggest Grid / Advanced Data Binding because Commands that invoke Rebind() implicitly
If you still have issue then let me know.
Thanks,
Jayesh Goyani
Please use Grid / Advanced Data Binding for binding the datasource to RadGrid.
I suggest Grid / Advanced Data Binding because Commands that invoke Rebind() implicitly
If you still have issue then let me know.
Thanks,
Jayesh Goyani