I am trying to add a column of the link button in DataGrid. When I click button an event (method) should call. Please help as I am new to it. Thanks
<asp:DataGrid ID="grdNipr" runat="server" CssClass="dataTable" AllowPaging="true"
<Columns>
<asp:ButtonColumn Text="Approve" ButtonType="PushButton" HeaderText="Approve"
CommandName="ApproveButton" />
</Columns>
</asp:DataGrid>
Related
I am working through an ASP.NET C# tutorial. I have a simple Gridview with the auto-created Edit & Delete Commandfields. So I've converted the Delete command field to a Templatefield and now I am trying to access the RowDataBound event of the Datagrid to add some code.
When I view the Gridview properties and click on the Events, I can see the RowDataBound event, but when I double-click on that event nothing happens. How do I create my event code? (in fact, I can't double-click on any of the events - they are all disabled).
Here is the top section of code for my gridview:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="colorID"
DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" ShowFooter="True">
<AlternatingRowStyle BackColor="White" />
<Columns>
<%-- Edit Button --%>
<asp:CommandField ShowEditButton="True" />
<%-- Delete Button --%>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
Thanks for your help.
John
When I create a gridview, the turn-on of edits, deletes, and inserts as commandfields works fine. Also if I immediately convert the delete commandfield to a templatefield before I do anything else, then the RowDataBound event (and all of the other events) are active and I can build codebehind content.
So, for now, something in the tutorial I am using is changing the character of the gridview events. Mostly, I was trying to dialog "Are you sure you want to delete Item XYZ?" as a validating Eval of the row I am deleting. But for now, with too many other things to learn, I'll just live with the stock OnClientClick="return confirm('Are you sure?'); and move on to something else that's more important.
I new to telerik and fighting my way up the learning curve.
I have a RadGrid that I'm populating with a linq query. I'm using a
GridTemplateColumn with a ComboBox for new and edit of one of the fields. The problem is the ComboBox doesn't show on the insert or edit screen. The fields set as GridDropDownColumn do show on the insert or edit. I need GridTemplateColumn solution because I need to run some code once the dropdown list has been selected.
What am I missing here? I'm trying to work from a Telerik example. It's the Release field that is giving me the problem.
<telerik:RadGrid RenderMode="Lightweight" ID="grdData" runat="server"
AllowPaging="true"
AllowSorting="true"
AutoGenerateColumns="false"
AllowAutomaticInserts="true"
AllowAutomaticUpdates="true"
OnNeedDataSource="grdData_OnNeededDataSource"
OnItemDataBound="grdData_OnItemDataBound"
OnUpdateCommand="grdData_OnUpdateCommand" >
<ClientSettings>
<Selecting AllowRowSelect="True" />
<Scrolling AllowScroll="True" UseStaticHeaders="True" />
</ClientSettings>
<SelectedItemStyle BackColor="LightYellow" />
<MasterTableView Width="100%"
DataKeyNames="TID"
EditMode="EditForms"
AutoGenerateColumns="false"
InsertItemDisplay="Top"
CommandItemDisplay="Top"
InsertItemPageIndexAction="ShowItemOnFirstPage">
<Columns>
<telerik:GridEditCommandColumn></telerik:GridEditCommandColumn>
<telerik:GridBoundColumn DataField="TID" UniqueName="TID"
HeaderText="TID" ReadOnly="true"></telerik:GridBoundColumn>
<telerik:GridDropDownColumn UniqueName="Employee" ListDataMember="Employee"
SortExpression="Employee" ListTextField="Employee" ListValueField="Employee"
HeaderText="Employee" DataField="Employee"
DropDownControlType="RadComboBox"
EnableEmptyListItem="true" EmptyListItemText="Make a choice" EmptyListItemValue=""
/>
<telerik:GridDropDownColumn UniqueName="Job" ListDataMember="Job"
SortExpression="Job" ListTextField="Job" ListValueField="Job"
HeaderText="Job" DataField="Job"
DropDownControlType="RadComboBox"
EnableEmptyListItem="true" EmptyListItemText="Make a choice" EmptyListItemValue=""
/>
<telerik:GridTemplateColumn UniqueName="Release"
HeaderText="Release"
HeaderStyle-HorizontalAlign="Center"
SortExpression="Release"
ItemStyle-Width="170px" HeaderStyle-Width="80px"
DataField="Release" >
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem, "Release")%>
</ItemTemplate>
<telerik:EditItemTemplate>
<telerik:RadComboBox runat="server" ID="rcbRelease"
AutoPostBack="true"
EnableLoadOnDemand="true"
DataTextField="Release"
DataValueField="Release"
Text='<% #Bind("Release")%>'
EnableEmptyListItem="true"
EmptyListItemText="Make a choice"
EmptyListItemValue="NR"
OnDataBinding="rcbRelease_OnDataBinding"
></telerik:RadComboBox>
</telerik:EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="ComponentJob" UniqueName="ComponentJob" HeaderText="ComponentJob"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Operation" UniqueName="Operation" HeaderText="Operation"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Quantity" UniqueName="Quantity" HeaderText="Quantity"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Priority" UniqueName="Priority" HeaderText="Priority"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Status" UniqueName="Status" HeaderText="Status"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="LastEdit" UniqueName="LastEdit" HeaderText="LastEdit"></telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
I think your having trouble with the ComboBox because you have EnableLoadOnDemand=true but you have not subscribed to the ItemsRequested event. See Load On Demand Overview for details.
Since you mention your new to the controls, you might want to get the ComboBox LoadOnDemand working outside of the grid first.
Try removing the telerik namespace/prefix from the EditItemTemplate declaration:
Change this:
<telerik:EditItemTemplate>
<%-- RadComboBox --%>
</telerik:EditItemTemplate>
To this:
<EditItemTemplate>
<%-- RadComboBox --%>
</EditItemTemplate>
Also, please share with us which documentation were you following so that we can double check and report the documentation error.
Good Day!
I'm having a hard time with my Gridview. I'm using C#.net and sql server. I want to update my gridview rows with the data from the column of radio button list with a button outside gridview. Here's my gridview;
I want to update column[rating] with the selected value from radio button list on a single button click.
Currently, I update the gridview column rating by clicking the rate button and getting the rating value from the dropdown list above the gridview.
Now, I'm wondering if there's a way to do it on one click and get it's value from the radio button list inside the gridview. My gridview code is here;
<p>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" onrowcommand="delete_enroll"
DataSourceID="training" Width="826px" AllowPaging="True" Visible="False"
style="text-align: center">
<Columns>
<asp:ButtonField ButtonType="Button" CommandName="deleterow" Text="CANCEL" />
<asp:ButtonField ButtonType="Button" CommandName="RATE" Text="RATE" />
<asp:BoundField DataField="Training_id" HeaderText="Training_id"
SortExpression="Training_id" />
<asp:BoundField DataField="User_id" HeaderText="User_id"
SortExpression="User_id" />
<asp:BoundField DataField="User_name" HeaderText="User_name"
SortExpression="User_name" />
<asp:BoundField DataField="Date_enrolled" HeaderText="Date_enrolled"
SortExpression="Date_enrolled" />
<asp:BoundField DataField="Rating" HeaderText="Rating"
SortExpression="Rating" />
<asp:TemplateField HeaderText="Rate">
<ItemTemplate>
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Text="Passed" Value="Passed"></asp:ListItem>
<asp:ListItem Text="Failed" Value="Failed"></asp:ListItem>
</asp:RadioButtonList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</p>
Any help would be appreciated. Thanks!
You can loop through the rows of gridview in you button click event handler and update the respective row like this:-
protected void btnUpdate_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
RadioButtonList RadioButtonList1 = row.FindControl("RadioButto nList1")
as RadioButtonList;
row.Cells[6].Text = RadioButtonList1.SelectedValue;
}
}
I want to add a link button in grid view that will navigate to the next form in the website. but i want to know how to insert that button into the grid view column? please help me..
You can add Link buttons in the Item template of a gridview.
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="Link" runat="server" PostBackUrl="MyNextPage.aspx">Edit</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<Columns>
<asp:TemplateField>
<HeaderTemplate>
// TEXT FOR COLUMN NAME
</HeaderTemplate>
<ItemTemplate>
// ADD LINK BUTTON HERE.
</ItemTemplate>
</asp:TemplateField>
</Columns>
Add this inside grid view.
try this
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:ButtonField ButtonType="Link" HeaderText="LinkButton"/>
</Columns>
</asp:GridView>
Make Sure your GridViews datasource is bound. Set Auto-Generate Columns to false.
Open GridViewTask , add new column with Hyperlink Field proper name and path . You are done.
I have a grid view control with Template Field containing Item Template as Checkbox control
and the Header Template is containing the label with column header name.
I want to click the coulmn header label and all the check boxes must be checked once.
Please provide me some examples or ideas how i can achieve this
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None" >
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField HeaderText="" >
<ItemTemplate>
<asp:CheckBox ID="val_id" runat="server" />
</ItemTemplate>
<HeaderTemplate>
<label>
Rise Needed
</label>
</HeaderTemplate>
</asp:TemplateField>
<Columns>
Change your HeaderTemplate label to be a LinkButton and assign the Click event.
<HeaderTemplate>
<asp:LinkButton ID="btnRiseNeeded" runat="server" Text="Rise Needed" OnClick="btnRiseNeeded_Click" />
</HeaderTemplate>
Then when the button is clicked loop through you GridView rows and check the box.
foreach(var row in GridView2.Rows)
{
var cbx = (CheckBox)row.FindControl("val_id");
cbx.Checked = true;
}
This code is off the top of my head so might need some modifying. Also, I'm not sure if the checkboxes will stay checked on PostBack. Give it a try.