I have 2 textbox as shown in code below :
<telerik:GridTemplateColumn UniqueName="guarantyAmount" HeaderText="<%$Resources:Strings,amount %>">
<ItemTemplate>
<asp:Label Text='<%# Eval("WARRANTY_AMOUNT")%>' runat="server" id="warrantyAmountText">
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadNumericTextBox runat="server" id="warrantyAmount" ClientEvents-OnValueChanging="warrantyAmount_ValueChanging"></telerik:RadNumericTextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="guarantyRealValue" HeaderText="<%$Resources:Strings,realValue %>">
<ItemTemplate>
<asp:Label Text='<%# Eval("REAL_VALUE")%>' runat="server" id="realValueText">
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadNumericTextBox runat="server" id="realValue"></telerik:RadNumericTextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
what i want is to create " warrantyAmount_ValueChanging " js function that read input value from "warrantyAmount " textbox and put them in "realValue" ..
how can i achieve that ??
Please try with the below code snippet.
function warrantyAmount_ValueChanging(sender, args) {
var SenderId = sender.get_id();
var realValue = $telerik.findTextBox(SenderId.replace("warrantyAmount", "realValue"));
realValue.set_value(args.get_newValue());
}
Related
I'm using CommandItemSettings in MasterTablreView to show Export to Excel button.
The CommandItemSettings section of the grid is displayed when Grid has at least 10 records or when I select less than 10 records using a Pager.
However, with less than 10 records after I click the Search button, the CommandItemSettings section is not there and I cannot export the data into an Excel.
Here is the aspx file:
MOSS2 Merchants Report:
<telerik:RadAjaxManager ID="RadAjaxManager" runat="server" EnableAJAX="true">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="btnSearch">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="grdMoss2Merchants" LoadingPanelID="RadAjaxLoadingPanel2"></telerik:AjaxUpdatedControl>
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
<table class="moss2Search" width="100%">
<tr>
<td colspan="4">
<asp:CustomValidator ID="checkForTwoDates" ClientValidationFunction="AtLeastOneDate_ClientValidate"
EnableClientScript="True" ErrorMessage="At least one date should be selected" runat="server"></asp:CustomValidator> <br />
<asp:CompareValidator ID="CompareValidator2" ControlToCompare="RadDatePicker1" ControlToValidate="RadDatePicker2" Operator="GreaterThanEqual"
ErrorMessage="Date range is not valid" runat="server"></asp:CompareValidator>
</td>
</tr>
<tr>
<td>
<div runat="server">
<asp:Label runat="server" CssClass="dateLabels">Boarding Start Date</asp:Label>
<telerik:RadDatePicker RenderMode="Lightweight" ID="RadDatePicker1" runat="server" onkeydown="keyPress(this, event)">
<Calendar runat="server">
<FastNavigationSettings EnableTodayButtonSelection="true"></FastNavigationSettings>
</Calendar>
</telerik:RadDatePicker>
</div>
</td>
<td>
<div runat="server">
<asp:Label runat="server" CssClass="dateLabels">Boarding End Date</asp:Label>
<telerik:RadDatePicker RenderMode="Lightweight" ID="RadDatePicker2" runat="server" onkeydown="keyPress(this, event)">
<Calendar runat="server">
<FastNavigationSettings EnableTodayButtonSelection="true"></FastNavigationSettings>
</Calendar>
</telerik:RadDatePicker>
</div>
</td>
<td>
<div>
<asp:CheckBox ID="chkMerActive" runat="server" Checked="true" TextAlign="Left"/>Active
</div>
</td>
<td>
<telerik:RadButton RenderMode="Lightweight" runat="server" Text="Search" ID="btnSearch" OnClick="btnSearch_Click"/>
</td>
</tr>
</table>
<asp:Label ID="lblMsg" ForeColor="red" runat="server"></asp:Label>
<br />
</telerik:RadAjaxPanel>
<%----%>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel2" runat="server" Skin="Default">
</telerik:RadAjaxLoadingPanel>
<telerik:RadAjaxPanel ID="RadAjaxPanel2" runat="server" LoadingPanelID="RadAjaxLoadingPanel2">
<telerik:RadGrid
RenderMode="Lightweight"
runat="server"
ID="grdMoss2Merchants"
AllowPaging="True"
AllowSorting="true"
PagerStyle-AlwaysVisible="true"
OnNeedDataSource="BindToDatasource"
OnSortCommand="grdMoss2Merchants_SortCommand"
ViewStateMode="Enabled"
AutoGenerateColumns="false"
OnPageIndexChanged="grdMoss2Merchants_ChangePage"
ClientSettings-Scrolling-ScrollHeight="360px">
<GroupingSettings CaseSensitive="false"/>
<ExportSettings HideStructureColumns="true" ExportOnlyData="true" OpenInNewWindow="true" Excel-Format="Xlsx" IgnorePaging="true" FileName="Moss2Merchants">
<Excel WorksheetName="Moss2Merchants" Format="Xlsx" AutoFitColumnWidth="AutoFitAll" />
</ExportSettings>
<ClientSettings EnableRowHoverStyle="true">
<Scrolling AllowScroll="true" UseStaticHeaders="True"/>
</ClientSettings>
<SortingSettings EnableSkinSortStyles="false" />
<HeaderStyle Width="160px" CssClass="grdHeader" ForeColor="#2E6E9E" />
<MasterTableView AllowNaturalSort="false" CommandItemDisplay="Bottom">
<CommandItemSettings ShowExportToExcelButton="true" ShowAddNewRecordButton="false" ShowRefreshButton="false" />
<CommandItemStyle HorizontalAlign="Right" />
<PagerStyle AlwaysVisible="true" Mode="NextPrevAndNumeric" PageSizes="5,10,25,50,100" />
<Columns>
<telerik:GridBoundColumn DataField="Moss2 MID" HeaderText="MOSS2 MID" AllowSorting="false" DataFormatString="{0:#}"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="DBA" HeaderText="DBA" HeaderStyle-Width="250px">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Original MID" HeaderText="ORIGINAL MID" AllowSorting="false" DataFormatString="{0:#}"></telerik:GridBoundColumn>
<telerik:GridBoundColumn
DataField="BoardingDate"
DataType="System.DateTime"
HtmlEncode="false"
DataFormatString="{0:MM/dd/yyyy}"
SortExpression="BoardingDate"
UniqueName="BoardingDate"
HeaderText="BOARDING DATE"
HeaderStyle-Width="170px"
ShowFilterIcon="false"
/>
<telerik:GridBoundColumn DataField="Status" HeaderText="STATUS" AllowSorting="false"></telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</telerik:RadAjaxPanel>
The Export To Excel button is showing with Grid having
I have a RadComboBox with checkboxes in Radgrid. User is able to select multiple values and data is saved into database. The problem I am having is, how to display already selected values when pulling data from database.
<telerik:RadGrid RenderMode="Lightweight" AutoGenerateColumns="false" ID="grd_incontact_settings" BorderWidth="0" Font-Size="Smaller" Width="100%" ShowFooter="True" AllowPaging="True" runat="server" PageSize="250" PagerStyle-AlwaysVisible="true"
OnNeedDataSource="grd_incontact_settings_NeedDataSource" AllowAutomaticInserts="True" OnInsertCommand="grd_incontact_settings_InsertCommand">
<GroupingSettings CaseSensitive="false"></GroupingSettings>
<MasterTableView AutoGenerateColumns="false" CommandItemDisplay="TopAndBottom" DataKeyNames="Id" EditMode="InPlace" ShowHeader="true">
<Columns>
<telerik:GridBoundColumn DataField="Id" UniqueName = "Id" AllowFiltering="false" Display ="false">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="Days" HeaderStyle-Width="150px" ItemStyle-Width="150px" UniqueName="ScheduleDays">
<ItemTemplate>
<%# Eval("ScheduleDays") %>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadComboBox RenderMode="Lightweight" runat="server" ID="ddl_ScheduleDays" CheckedItemsTexts="DisplayAllInInput" CheckBoxes="true" SelectedValue='<%#Bind("ScheduleDays") %>' >
<Items>
<telerik:RadComboBoxItem Text="None" Value= 0 runat="server" />
<telerik:RadComboBoxItem Text="Monday" Value= 1 runat="server" />
<telerik:RadComboBoxItem Text="Tuesday" Value= 2 runat="server" />
<telerik:RadComboBoxItem Text="Wednesday" Value= 4 runat="server" />
<telerik:RadComboBoxItem Text="Thursday" Value= 8 runat="server" />
<telerik:RadComboBoxItem Text="Friday" Value= 16 runat="server" />
<telerik:RadComboBoxItem Text="Saturday" Value= 32 runat="server" />
<telerik:RadComboBoxItem Text="Sunday" Value= 64 runat="server" />
</Items>
</telerik:RadComboBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
Code Behind:
protected void grd_incontact_settings_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
List<SP_InContactSettings_Get_Result> lst_incontact_settings = new List<SP_InContactSettings_Get_Result>();
using (var db = new data.tarpasql())
{
lst_incontact_settings = db.SP_InContactSettings_Get().ToList();
}
grd_incontact_settings.DataSource = lst_incontact_settings;
}
public partial class SP_InContactSettings_Get_Result
{
public int Id { get; set; }
public List<int> ScheduleDays { get; set; }
}
This is what I am getting:
I'm trying to get RadGrid to conditionally hide or disable a field when it is in edit mode based on the value of another field.
I have been able to get this to work when the grid displays the list of items, but once the grid enters edit mode, the columns display ...
I am using OnItemDataBound to successfully conditionally display during the initial load, but setting the items when the user clicks a row to get it into batch mode is not working.
Note: PValue and CValue and in GridTemplateColumns, as is CardStatus.
public void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
foreach (GridDataItem item in RadGrid1.Items)
{
string BoundColumnValue = item["CardStatus"].Text; // accessing GridBoundColumn value using ColumnUniqueName
string BoundColumnValue2 = item["CValue"].Text;
TextBox txtbx = (TextBox)item.FindControl("CardStatus");
Label numlb = (Label)item.FindControl("CardValue");
if (txtbx.Text.Equals("True"))
{
txtbx.ForeColor = Color.Red;
numlb.Enabled = false;
numlb.BackColor = Color.Yellow;
numlb.ForeColor = Color.Red;
//Just testing to see if it would evaluate
}
else
{
txtbx.ForeColor = Color.Beige;
}
//string TemplateColumnValue = lb.Text;// accessing Label Text.
}
foreach (GridEditableItem item in RadGrid1.EditItems)
{
string BoundColumnValue = item["CardStatus"].Text; // accessing GridBoundColumn value using ColumnUniqueName
string BoundColumnValue2 = item["CValue"].Text;
TextBox txtbx = (TextBox)item.FindControl("CardStatus");
if (txtbx.Text.Equals("True"))
{
txtbx.ForeColor = Color.Red;
//numTxt.BackColor = Color.Yellow;
//numTxt.ForeColor = Color.Red;
}
else
{
txtbx.ForeColor = Color.Beige;
}
}
}
I just need to be able to selectively prevent data entry in a column
The ASPX source is below:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticUpdates="true" Height="930px" DataSourceID="SqlDataSource4" CellSpacing="0" GridLines="None" Width="640px" OnItemDataBound="RadGrid1_ItemDataBound" OnItemCreated="RadGrid1_ItemCreated" OnBatchEditCommand="RadGrid1_BatchEditCommand1" Skin="WebBlue">
<ClientSettings>
<Scrolling AllowScroll="True" UseStaticHeaders="True" />
</ClientSettings>
<MasterTableView AutoGenerateColumns="False" EditMode="Batch" Width="620px" CommandItemDisplay="TopAndBottom" DataSourceID="SqlDataSource4" DataKeyNames="CountKey">
<CommandItemSettings ExportToPdfText="Export to PDF" ShowSaveChangesButton="true" ShowRefreshButton="false" ShowAddNewRecordButton="false"></CommandItemSettings>
<BatchEditingSettings OpenEditingEvent="Click" EditType="Row" />
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
<Columns>
<telerik:GridBoundColumn DataField="Pcolumn" ItemStyle-Width="75px" ReadOnly="true" Visible="false" DataType="System.Int32" FilterControlAltText="Filter Pcolumn column" HeaderText="Pcolumn" SortExpression="Pcolumn" UniqueName="Pcolumn">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Row" ReadOnly="true" Visible="false" DataType="System.Int32" FilterControlAltText="Filter Row column" HeaderText="Row" SortExpression="Row" UniqueName="Row">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn ColumnEditorID="PValue" HeaderText="Pattern" DataField="PValue" UniqueName="PValue" ItemStyle-Width="75px" HeaderStyle-Width="75px">
<EditItemTemplate>
<telerik:RadNumericTextBox ID="PValue" Width="50px" runat="server" MaxLength="1" MaxValue="9" NumberFormat-DecimalDigits="0" Text='<%# Bind("PValue") %>'></telerik:RadNumericTextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="PValue" ErrorMessage="<br/>Required (0-9) Only)!" SetFocusOnError="true"></asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="PValue" Width="50px" runat="server" Text='<%# Bind("PValue") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn ColumnEditorID="CValue" DataField="CValue" HeaderText="Card" UniqueName="CValue" ItemStyle-Width="75px" HeaderStyle-Width="75px">
<EditItemTemplate>
<telerik:RadNumericTextBox ID="CValue" Width="50px" AllowOutOfRangeAutoCorrect="false" runat="server" MaxLength="1" MaxValue="1" NumberFormat-DecimalDigits="0" Text='<%# Bind("CValue") %>'></telerik:RadNumericTextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="CValue" ErrorMessage="<br />Required (0-1 Only)!" SetFocusOnError="true"></asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="CValue" Width="50px" runat="server" Text='<%# Bind("CValue") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="DateEdited" ReadOnly="true" Visible="false" DataType="System.DateTime" FilterControlAltText="Filter DateEdited column" HeaderText="DateEdited" SortExpression="DateEdited" UniqueName="DateEdited">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn UniqueName="CardStatus" DataField="CardStatus" ItemStyle-Width="50px" HeaderStyle-Width="50px">
<ItemTemplate>
<asp:TextBox ID="CardStatus" Width="10px" runat="server" Text='<%# Bind("CardStatus") %>'></asp:TextBox>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="CardStatus" Width="10px" runat="server" Text='<%# Bind("CardStatus") %>'></asp:TextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
<FilterMenu EnableImageSprites="False"></FilterMenu>
</telerik:RadGrid>
Any help / workarounds would be appreciated ... again, "just" need to prevent editing in the CValue column when the CardStatus value is true (bit field) ... using batch mode (using another solution isn't an option now).
Thanks
Larry
Well, this doesn't answer the Telerik question, but ended up doing this with the MS GridView, using the tutorial here: http://msdn.microsoft.com/en-us/library/aa992036(v=vs.90).aspx.
Also was able to customize, and detect hidden grid fields, and hide cells (and disable validators) based on the hidden field's condition.
Added the following code in the RowDataBound event of the gridview:
DataRowView drv = (DataRowView)e.Row.DataItem;
if (drv["Status"].Equals(true))
{
// Find the order of the cell
e.Row.Cells[5].CssClass = "hiddencol"; // using the display: none style
// Find the Validator control in the template column
RequiredFieldValidator reqF = (RequiredFieldValidator)e.Row.Cells[5].FindControl("RequiredFieldValidator1");
reqF.Enabled = false;
}
else
{
}
<ajaxToolkit:Accordion ID="Accordion1" CssClass="accordion" SelectedIndex="0" HeaderCssClass="accordionHeader" HeaderSelectedCssClass="accordionHeaderSelected" AutoSize="None" RequireOpenedPane="false" ContentCssClass="accordionContent" runat="server">
<Panes>
<ajaxToolkit:AccordionPane ID="Pane1" runat="server">
<Header><b>Panel 1</b></Header>
<Content>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<br>
Age: <asp:textbox id="Age1" runat="server" Width="35" Font-Bold="True"/><br>
Attorney: <asp:CheckBox ID="Attorney" runat="server" /><br>
<asp:button ID="Button1" text="Submit" OnClick="Button1_Click"
runat="server"/><br>
<asp:label id="Message1" runat="server" ForeColor="White" Font-Size="Small" Font-Bold="True"/>
</ContentTemplate>
</asp:UpdatePanel>
</Content>
</ajaxToolkit:AccordionPane>
<ajaxToolkit:AccordionPane ID="Pane2" runat="server">
<Header><b>Panel 2</b></Header>
<Content>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<br>
<asp:textbox id="Age2" runat="server" Width="35" Font-Bold="True"/><br>
<asp:button ID="Button2" text="Submit" onclick="Button2_Click"
runat="server"/><br><br>
<asp:label id="Message2" runat="server" ForeColor="White" Font-Size="Small" Font-Bold="True" />
</ContentTemplate>
</asp:UpdatePanel>
</Content>
</ajaxToolkit:AccordionPane>
</Panes>
protected void Button1_Click(object sender, EventArgs e) {
if (Attorney.Checked) {
Pane2.Visible = true;
} else {
Pane2.Visible = false;
}
//Message1.Text = Age1.Text;
}
I have five Accordion Panels. Last Panel should be displayed only if a checkbox is checked in the first panel. Inside each Accordion Panel I have a UpdatePanel and within that I have ContentTemplate with controls and submit button particular to that accordion panel. The reason I added UpdatePanel is so that when i update a particular panel it does not affect other accordion panels.
The problem is I need to toggle last accordion panel display depending upon if a checkbox is checked in the first Panel and submit button is clicked. In Code behind, in the btnSubmit1 event...I have code that says if checkbox is checked....Pane2.Visible = true else Pane2.Visible=false. For some reasons it still shows the LastPanel.
I am not sure where am I going wrong...please advise!
Thanks!
Jini
I fixed the problem by adding an outer update panel...and removed the updatepanel for Panel 2. Haven't tested it thoroughly but so far looks good.
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:UpdatePanel ID="OuterPanel" UpdateMode="Always" ChildrenAsTriggers="true" runat="server">
<ContentTemplate>
<ajaxToolkit:Accordion ID="Accordion1" CssClass="accordion" SelectedIndex="0" HeaderCssClass="accordionHeader"
HeaderSelectedCssClass="accordionHeaderSelected" AutoSize="None" RequireOpenedPane="false" ContentCssClass="accordionContent" runat="server">
<Panes>
<ajaxToolkit:AccordionPane ID="Pane1" runat="server">
<Header><b>Panel 1</b></Header>
<Content>
<br>
Age: <asp:textbox id="Age1" runat="server" Width="35" Font-Bold="True" /><br />
Attorney: <asp:CheckBox ID="Attorney" runat="server" /><br>
<asp:button ID="Button1" text="Submit" OnClick="Button1_Click"
runat="server"/><br>
<asp:label id="Message1" runat="server" ForeColor="White" Font-Size="Small" Font-Bold="True"/>
</Content>
</ajaxToolkit:AccordionPane>
<ajaxToolkit:AccordionPane ID="Pane2" runat="server">
<Header><b>Panel 2</b></Header>
<Content>
<br>
<asp:textbox id="Age2" runat="server" Width="35" Font-Bold="True"/>
<asp:button ID="Button2" text="Submit" onclick="Button2_Click"
runat="server"/><br><br>
<asp:label id="Message2" runat="server" ForeColor="White" Font-Size="Small" Font-Bold="True" />
</Content>
</ajaxToolkit:AccordionPane>
</Panes>
</ajaxToolkit:Accordion>
</ContentTemplate>
I'd like to see your code to be sure, but I'm expecting it's because you have an UpdatePanel in each of the AccordionPanels. Once an event happens in one UpdatePanel, ASP.NET will not run code handling that event that is attached to another UpdatePanel.
First, I'd take out all UpdatePanels to see if your code works as expected. Then, I'd add one UpdatePanel wrapped around the entire Accordion and see if your code still works.
If you really decided you need to have 5 UpdatePanels, look into the <Triggers> portion of the UpdatePanel. You'll be able to provide the CheckBox's ID to force the other associated UpdatePanel to PostBack.
When I try to update a LINQ data source bound to a grid view, I get the following error:
Could not find a row that matches the given keys in the original values stored in ViewState. Ensure that the 'keys' dictionary contains unique key values that correspond to a row returned from the previous Select operation.
I have specified DataKeyNames in the grid view.
Here's the HTML:
<asp:GridView ID="TaskGridView" runat="server" AutoGenerateColumns="False"
DataKeyNames="taskid,statusid,taskdescription" DataSourceID="GridDataSource"
onrowcreated="TaskGridView_RowCreated">
<Columns>
<asp:TemplateField HeaderText="taskid" InsertVisible="False"
SortExpression="taskid">
<ItemTemplate>
<asp:Label ID="TaskId" runat="server" Text='<%# Bind("taskid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="taskdescription"
SortExpression="taskdescription">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("taskdescription") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="TaskDesc" runat="server" Text='<%# Bind("taskdescription") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="url" HeaderText="url" SortExpression="url" />
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:DropDownList runat="server" ID="ddStatus" DataSourceID="DropDownDataSource" DataValueField="statusid" SelectedValue="<%# Bind('Statusid') %>" DataTextField="statusdescription" ></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:LinqDataSource ID="GridDataSource" runat="server"
ContextTypeName="DailyTask.DailyTaskDBDataContext" TableName="tbl_tasks"
EnableUpdate="True">
</asp:LinqDataSource>
<asp:Button ID="btnUpdate" runat="server" onclick="btnUpdate_Click"
Text="Update" />
<asp:LinqDataSource ID="DropDownDataSource" runat="server"
ContextTypeName="DailyTask.DailyTaskDBDataContext" TableName="tbl_status">
</asp:LinqDataSource>
Here's the corresponding code:
protected void btnUpdate_Click(object sender, EventArgs e)
{
ListDictionary keyValues = new ListDictionary();
ListDictionary newValues = new ListDictionary();
ListDictionary oldValues = new ListDictionary();
try
{
keyValues.Add("taskid", ((Label)TaskGridView.Rows[0].FindControl("TaskId")).Text);
oldValues.Add("taskdescription", ((Label)TaskGridView.Rows[0].FindControl("TaskDesc")).Text);
newValues.Add("taskdescription", "New Taskk");
GridDataSource.Update(keyValues, newValues, oldValues);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
I got the problem it was in the code
I just have to use int.Parse() here because taskid is primary key
keyValues.Add("taskid", int.Parse(((Label)TaskGridView.Rows[0].FindControl("TaskId")).Text));