Stored procedure expects parameter that was not supplied - c#

I have a SqlDataSource connected to a GridView and I am trying to get the edit working correctly, but with everything I try I still get that parameters are not supplied.
I have tried naming the parameters with and without the '#', it seems to make no difference. As you can see in the below image, the update parameters exist and even have values!
Example image:
ASPX markup:
<asp:GridView runat="server" ID="JobGV" DataSourceID="JobApprovalsDS"
AutoGenerateColumns="False" AutoGenerateEditButton="true"
OnRowCommand="JobGV_OnRowCommand" OnRowUpdating="JobGV_OnRowUpdating">
<Columns>
<asp:BoundField HeaderText="Function" DataField="FunDesc" ReadOnly="true"/>
<asp:BoundField HeaderText="Employee" DataField="EmpName" ReadOnly="true"/>
<asp:TemplateField>
<EditItemTemplate>
<asp:DropDownList runat="server" ID="ddlEmps" SelectedValue='<%# Eval("appEmpID")%>' DataSourceID="EmpDS" DataTextField="EmpName" DataValueField="EmpID" />
<asp:Label runat="server" ID="data" Text='<%# Eval("appBusinessUnit") +";" + Eval("appFunctID") %>' Visible="False"></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%# Eval("EmpName") %>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="JobApprovalsDS" runat="server"
ConnectionString="<%$ ConnectionStrings:JobClose %>"
SelectCommand="up_JobApprovalsSelect"
SelectCommandType="StoredProcedure"
UpdateCommand="up_JobApprovalsUpdate">
<SelectParameters>
<asp:Parameter Name="ShowAll" DefaultValue="1" />
<asp:Parameter Name="AllPhases" DefaultValue="1" />
<asp:ControlParameter Name="BusinessUnit" ControlID="ddlEditJob" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="#BusinessUnit" Type="String"/>
<asp:Parameter Name="#FunctID" Type="Int32"/>
<asp:Parameter Name="#EmpID" Type="Int32"/>
<asp:Parameter Name="#UpdateDate" Type="DateTime"/>
</UpdateParameters>
</asp:SqlDataSource>
C#:
protected void JobGV_OnRowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("Update"))
{
int empid = 0;
string[] data;
int index = int.Parse(e.CommandArgument.ToString());
GridViewRow row = JobGV.Rows[index];
DropDownList ddlemp = (DropDownList) row.FindControl("ddlEmps");
empid = int.Parse(ddlemp.SelectedValue);
Label lbl = (Label) row.FindControl("data");
data = lbl.Text.Split(';');
JobApprovalsDS.UpdateParameters["#BusinessUnit"].DefaultValue = data[0];
JobApprovalsDS.UpdateParameters["#FunctID"].DefaultValue = data[1];
JobApprovalsDS.UpdateParameters["#EmpID"].DefaultValue = empid.ToString();
//JobApprovalsDS.UpdateParameters.Add("BusinessUnit", data[0]);
//JobApprovalsDS.UpdateParameters.Add("FunctID", data[1]);
//JobApprovalsDS.UpdateParameters.Add("EmpID", empid.ToString());
}
}
protected void JobGV_OnRowUpdating(object sender, GridViewUpdateEventArgs e)
{
JobApprovalsDS.Update();
}

Are you talking about the update process??
Well, in your SqlDataSource, you're not specifying that the UpdateCommand is talking to a stored procedure... you need to specify the UpdateCommandType, too! (not just the SelectCommandType)
<asp:SqlDataSource ID="JobApprovalsDS" runat="server"
ConnectionString="<%$ ConnectionStrings:JobClose %>"
SelectCommand="up_JobApprovalsSelect"
SelectCommandType="StoredProcedure"
UpdateCommand="up_JobApprovalsUpdate"
UpdateCommandType="StoredProcedure" > **** this is missing from your code!

Related

DetailsView OnUpdating TextBox not returning new text ASP.NET C#

I have a DetailsView and a SqlDataSource as below. The NotesTB and the NameTB are not null in the code behind but are not retaining the new values entered in. They are returning the old values binded originally. I have searched the internet and can not find the reason for this and it is perplexing me.
<asp:DetailsView ID="PhotoDetailsDV" runat="server" Height="50px" Width="125px" DefaultMode="Edit" AutoGenerateRows="False" DataKeyNames="PhotoID" DataSourceID="XXXXXXXXXX" OnDataBound="PhotoDetailsDV_DataBound" OnItemUpdating="PhotoDetailsDV_ItemUpdating1" >
<Fields>
<asp:TemplateField HeaderText="Notes" SortExpression="Notes">
<EditItemTemplate>
<asp:TextBox ID="NotesTB" runat="server" Text='<%# Bind("Notes") %>'></asp:TextBox>
<asp:HiddenField runat="server" ID="PhotoIdHF" Value='<%# Bind("PhotoID") %>'/>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="NotesLabel" runat="server" Text='<%# Bind("Notes") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name" SortExpression="Name">
<EditItemTemplate>
<asp:TextBox ID="NameTB" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource runat="server" ID="XXXXX" ConnectionString="<%$ ConnectionStrings:XXXXXXXXXXXXXXX %>" SelectCommand="SELECT [Notes], Photoid, [Name] FROM [XXXXXXXX] WHERE ([FileID] = #FileID)" UpdateCommand="UPDATE [XXXXXXX] SET [Notes] = #Notes, [Name] = #Name WHERE [PhotoID] = #PhotoID">
<SelectParameters>
<asp:Parameter Name="FileID" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Notes" Type="String" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="PhotoID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
My code behind is as follows
protected void PhotoDetailsDV_ItemUpdating1(object sender, DetailsViewUpdateEventArgs e)
{
TextBox NameTB = (TextBox) PhotoDetailsDV.FindControl("NameTB");
TextBox NotesTB = (TextBox) PhotoDetailsDV.FindControl("NotesTB");
e.NewValues["Notes"] = NotesTB.Text;//here NotesTB.Text is "" even when something is entered or it is the old value
e.NewValues["Name"] = NameTB.Text;//here NameTB.Text is "" even when something is entered or it is the old value
}
the code your bind data to your detailview, do you use a not is postback condition to make sure it will not re-bind the data after postback?

Do not bind drop down list if selected value not found in list of items

How do I tell SelectedValue='<%# Bind("AccID") %>' do not perform the binding if AccID is not in the list of items?
<EditItemTemplate>
<asp:ObjectDataSource ID="ObjectDataSourceAccount" runat="server" SelectMethod="GetUsableAccountByUser"
TypeName="t_MT_AccCode" OnSelected="ObjectDataSourceAccount_Selected" OnSelecting="ObjectDataSourceAccount_Selecting">
<SelectParameters>
<asp:Parameter Name="companyCode" />
<asp:Parameter Name="departmentCode" />
<asp:Parameter Name="badgeNumber" />
<asp:Parameter Name="userRole" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:DropDownList ID="DropDownListAccount" runat="server" DataSourceID="ObjectDataSourceAccount"
DataTextField="accountDesc" DataValueField="id"
SelectedValue='<%# Bind("AccID") %>'
ondatabinding="DropDownListAccount_DataBinding"
ondatabound="DropDownListAccount_DataBound">
</asp:DropDownList>
</EditItemTemplate>
This is how I solved this issue.
But I was hoping I can solve it through SelectedValue='<%# Bind("AccID") %>' instead.
protected void DropDownListAccount_DataBound(object sender, EventArgs e)
{
DropDownList dropDownListAccount = (DropDownList)sender;
DataRowView currentDataRowView = (DataRowView)((GridViewRow)dropDownListAccount.Parent.Parent).DataItem;
int currentRowDataKeyItemId = int.Parse(currentDataRowView["ID"].ToString());
int accountId = t_MT_MTItem.GetAccountIdByItemId(currentRowDataKeyItemId);
dropDownListAccount.SelectedValue = accountId.ToString();
}

How to set FilterParameters property of a datasource?

I have two dropdownlists, a checkbox and a gridview that contains images. the asp code looks like this.
<asp:DropDownList ID="dLSubCat" runat="server"
DataSourceID="SubCat" DataTextField="NAME"
DataValueField="SUBCAT_ID"
AutoPostBack="True">
</asp:DropDownList>
<asp:SqlDataSource ID="SubCat" runat="server"
ConnectionString="<%$ ConnectionStrings:GalleryConnectionString %>"
SelectCommand="SELECT * FROM [SubCategory] WHERE ([CAT_ID] = #CAT_ID)">
<SelectParameters>
<asp:ControlParameter ControlID="dLCategory" Name="CAT_ID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
and
<asp:DropDownList ID="dlIconSize" runat="server" AutoPostBack="True">
<asp:ListItem>16x16</asp:ListItem>
<asp:ListItem>24x24</asp:ListItem>
<asp:ListItem>32x32</asp:ListItem>
<asp:ListItem>48x48</asp:ListItem>
<asp:ListItem>64x64</asp:ListItem>
<asp:ListItem>72x72</asp:ListItem>
<asp:ListItem>96x96</asp:ListItem>
<asp:ListItem>128x128</asp:ListItem>
</asp:DropDownList>
<asp:CheckBox ID="chKBtn" runat="server" Text="Black n White" />
and
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID" DataSourceID="SqlDataSource2">
<Columns>
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:Image ID="Image1" runat="server"
ImageUrl='<%# "imagehandler.ashx?ID=" + Eval("ID")%>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:GalleryConnectionString %>"
EnableCaching="True"
SelectCommand="SELECT * FROM [Icon]"
FilterExpression="SUBCAT_ID lIKE '{0}' OR ICON_SIZE Like '{1}' OR BLACKWHITE Like '{2}' ">
<FilterParameters>
<asp:ControlParameter ControlID = "dLSubCat"
PropertyName = "SelectedValue" />
<asp:ControlParameter ControlID = "dlIconSize"
PropertyName = "SelectedValue" />
<asp:ControlParameter ControlID = "chKBtn" PropertyName = "Checked" />
</FilterParameters></asp:SqlDataSource>
but when i try to filter data from dropdownlists it does not filter the data it shows same data Kindly guide me
Shouldn't the ID's match?
<asp:ControlParameter ControlID="dLCategory"
<asp:DropDownList ID="dlIconSize"

Nested DetailsView insert method's parameters

I have DetailsView nested in GridView, and I can't figure out how to pass values(like ID of item in GridView and value from session) to parameters for insert method.
<asp:DetailsView ID="DetailsViewPostLikes" runat="server"
AutoGenerateRows="false" DataSourceID="odsPostLikes"
DataKeyNames="id" GridLines="None">
<Fields>
<asp:CommandField ShowInsertButton="true" InsertText="Like" newtext="Like" />
<asp:TemplateField HeaderText="" SortExpression="Nickname">
<ItemTemplate>
<asp:Label id="nicknamelikesCount" runat="server" Text='<%# Bind("LikeCount") %>'></asp:Label> people likes this.
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
<asp:ObjectDataSource ID="odsPostLikes" runat="server"
TypeName="SocWebApp.Database.PostLikeTable"
SelectMethod="Select" InsertMethod="Insert" UpdateMethod="Update">
<SelectParameters>
<asp:Parameter Name="postId" Type="Int32" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="postId" Type="Int32" />
<asp:SessionParameter Name="userId" SessionField="User_id" Type="Int32" />
</InsertParameters>
</asp:ObjectDataSource>
I've tried to do this same way as for select parameter like this:
protected void posts_ItemDatabound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)//(GridView)e.Row.FindControl("odsComments") != null)
{
ObjectDataSource s1 = (ObjectDataSource)e.Row.FindControl("odsComments");
s1.SelectParameters["postId"].DefaultValue = DataBinder.Eval(e.Row.DataItem, "Id").ToString();
ObjectDataSource s2 = (ObjectDataSource)e.Row.FindControl("odsPostLikes");
s2.InsertParameters["postId"].DefaultValue = DataBinder.Eval(e.Row.DataItem, "Id").ToString();
ObjectDataSource s3 = (ObjectDataSource)e.Row.FindControl("odsPostLikes");
s3.InsertParameters["userId"].DefaultValue = Session["User_id"].ToString();
}
}
but only userId parameter value is set(from Session), postId is always 0.
What is the proper solution?
Thank you.
I've found the solution:
<asp:DetailsView ID="DetailsViewPostLikes" runat="server"
AutoGenerateRows="false" DataSourceID="odsPostLikes"
DataKeyNames="id" GridLines="None" OnDataBound="postLikeInsert_DataBound" OnItemCommand="postLikeInsert_ItemCommand">
<Fields>
<asp:CommandField ShowInsertButton="false" InsertText="Like" newtext="Like" />
<asp:TemplateField HeaderText="" SortExpression="Nickname">
<ItemTemplate>
<asp:LinkButton ID="Like" runat="server" CommandName="Insert" Text="Like" />
<asp:Label id="likesCount" runat="server" Text='<%# Bind("LikeCount") %>'></asp:Label> people likes this.
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
<asp:ObjectDataSource ID="odsPostLikes" runat="server"
TypeName="SocWebApp.Database.PostLikeTable"
SelectMethod="Select" InsertMethod="Insert" UpdateMethod="Update">
<SelectParameters>
<asp:Parameter Name="postId" Type="Int32" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="postId" Type="Int32" />
<asp:SessionParameter Name="userId" SessionField="User_id" Type="Int32" />
</InsertParameters>
</asp:ObjectDataSource>
code-behind:
protected void postLikeInsert_DataBound(object sender, EventArgs e)
{
DetailsView d = (DetailsView)sender;
GridViewRow row = (GridViewRow)d.NamingContainer;
int idx = row.RowIndex;
GridView grid = (GridView)row.NamingContainer;
string strGoalIndicatorID = grid.DataKeys[idx]["id"].ToString();
LinkButton b = (LinkButton)d.FindControl("Like");
b.CommandArgument = strGoalIndicatorID;
}
protected void postLikeInsert_ItemCommand(object sender, DetailsViewCommandEventArgs e)
{
if (e.CommandName == "Insert")
{
DetailsView d = (DetailsView)sender;
d.ChangeMode(DetailsViewMode.Insert);
ObjectDataSource o = (ObjectDataSource)d.NamingContainer.FindControl("odsPostLikes");
o.InsertParameters["postId"].DefaultValue = e.CommandArgument.ToString();
}
}
when data bound, it will find the button and set his command argument to id item of parent gridview, then after hitting the button, insert parameter is set based on that command argument

RadGrid(Gridview) Recursive Checkbox in EditItemTemplate Column for Inserts and Updates

I have a RadGrid with a Checkbox inside an EditItemTemplate for an Active or Inactive status.
This checkbox only shows when the item is being updated or added as new. I have a ControlParameter for the checkbox, but since it is recursive with many of these checkboxes in the list, it throws the good old "Could not find control 'cbActive' in ControlParameter" Error.
I dont have any real CS code other than the Radgrid binding on page load.
ASPX Code:
<telerik:RadGrid ID="RadGrid1" runat="server" Skin="Vista" Width="500px"
GridLines="None" AllowFilteringByColumn="False" AllowSorting="True" OnExportCellFormatting="RadGrid1_ExportCellFormatting"
AllowAutomaticInserts="True" AllowAutomaticDeletes="true" AllowAutomaticUpdates="True" AutoGenerateEditColumn="True" AutoGenerateDeleteColumn="true">
<MasterTableView AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1" ItemStyle-HorizontalAlign="Left" CommandItemDisplay="TopAndBottom">
<Columns>
<telerik:GridBoundColumn DataField="ID" HeaderText="ID" SortExpression="ID"
UniqueName="ID" Visible="False" ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="Active" SortExpression="Active" UniqueName="Active" ItemStyle-Width="100" Visible="false">
<EditItemTemplate>
<asp:CheckBox ID="cbActive" runat="server" Checked='<%# GenerateBindString(Container.DataItem) %>' />
</EditItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:LBCust %>"
SelectCommand="SELECT * FROM [LBX_Portal_AccountNumbers] WHERE ([Site] = #Site) AND (Active=#Active OR #Active = '0') ORDER BY AccountNumber"
DeleteCommand="DELETE FROM [LBX_Portal_AccountNumbers] WHERE [ID] = #ID"
InsertCommand="INSERT INTO [LBX_Portal_AccountNumbers] ([AccountNumber], [Site], [Active]) VALUES (#AccountNumber, #Site, #Active)"
UpdateCommand="UPDATE [LBX_Portal_AccountNumbers] SET [AccountNumber] = #AccountNumber, [Active] = #Active WHERE [ID] = #ID">
<SelectParameters>
<asp:ControlParameter ControlID="dd_Status" Name="Active"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="AccountNumber" Type="String" />
<asp:Parameter Name="Site" Type="String" />
<asp:ControlParameter ControlID="cbActive"
PropertyName="Checked" Type="Boolean" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="AccountNumber" Type="String" />
<asp:ControlParameter ControlID="cbActive"
PropertyName="Checked" Type="Boolean" />
</UpdateParameters>
</asp:SqlDataSource>
You aren't going to be able to set the value through a control parameter; what you can do though, is use an <asp:Parameter> instead, and set the DefaultValue property on the parameter via:
sqlDataSource1.SelectParameters[0].DefaultValue = "X"
Or, with the Grids, I know with the GridView it has a collection of values that it used to perform the update with; you could add an entry representing the checkbox control, which would get pushed into the data source. I know know if the RadGrid has the same option.
So it took a lot of looking around but i couldnt do this without tapping into the commands via the CS. Here is my new Code for it to work:
<telerik:RadGrid ID="RadGrid1" runat="server" Skin="Vista" Width="500px"
GridLines="None" AllowFilteringByColumn="False" AllowSorting="True" OnExportCellFormatting="RadGrid1_ExportCellFormatting"
AllowAutomaticInserts="True" AllowAutomaticDeletes="true" AllowAutomaticUpdates="True" AutoGenerateEditColumn="True" AutoGenerateDeleteColumn="true" OnItemCommand="RadGrid1_ItemCommand">
<MasterTableView AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1" ItemStyle-HorizontalAlign="Left" CommandItemDisplay="TopAndBottom">
<Columns>
<telerik:GridTemplateColumn HeaderText="ID" SortExpression="ID" UniqueName="ID" Visible="false" ReadOnly="true">
<ItemTemplate>
<asp:Label ID="lblIDView" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="ID" SortExpression="IDEdit" UniqueName="IDEdit" Visible="false">
<ItemTemplate />
<EditItemTemplate>
<asp:Label ID="lblID" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="AccountNumber" HeaderText="Sapphire Account Number"
SortExpression="AccountNumber" UniqueName="AccountNumberView" ReadOnly="true" ItemStyle-Width="400">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="Account Number" SortExpression="AccountNumber" UniqueName="AccountNumber" Visible="false">
<ItemTemplate />
<EditItemTemplate>
<asp:Textbox ID="txtAccountNumber" runat="server" Text='<%# Bind("AccountNumber") %>' />
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Active" SortExpression="Active" UniqueName="Active" ItemStyle-Width="100" Visible="false">
<ItemTemplate />
<EditItemTemplate>
<asp:CheckBox ID="cbActive" runat="server" Checked='<%# GenerateBindString(Container.DataItem) %>' />
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Status" SortExpression="Active" UniqueName="Active" ItemStyle-Width="100">
<ItemTemplate>
<asp:Label ID="lblActive" runat="server" Text='<%# Convert.ToBoolean(GenerateBindString(Container.DataItem)) == true ? "Active" : "Inactive" %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:LBCust %>"
SelectCommand="SELECT * FROM [LBX_Portal_AccountNumbers] WHERE ([Site] = #Site) AND (Active=#Active OR #Active = '0') ORDER BY AccountNumber"
DeleteCommand="DELETE FROM [LBX_Portal_AccountNumbers] WHERE [ID] = #ID"
InsertCommand="INSERT INTO [LBX_Portal_AccountNumbers] ([AccountNumber], [Site], [Active]) VALUES (#AccountNumber, #Site, #Active)"
UpdateCommand="UPDATE [LBX_Portal_AccountNumbers] SET [AccountNumber] = #AccountNumber, [Active] = #Active WHERE [ID] = #ID">
<SelectParameters>
<asp:ControlParameter ControlID="dd_Status" Name="Active"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="AccountNumber" Type="String" />
<asp:Parameter Name="Site" Type="String" />
<asp:Parameter Name="Active" Type="Boolean" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="AccountNumber" Type="String" />
<asp:Parameter Name="Active" Type="Boolean" />
</UpdateParameters>
</asp:SqlDataSource>
CS CODE:
protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
{
if (e.CommandName == "PerformInsert")
{
GridEditFormItem gridEditFormItem = (GridEditFormItem)e.Item;
Label lblID = (Label)gridEditFormItem.FindControl("lblID");
TextBox txtAccountNumber = (TextBox)gridEditFormItem.FindControl("txtAccountNumber");
CheckBox cbActive = (CheckBox)gridEditFormItem.FindControl("cbActive");
bool isActive = false;
if (cbActive.Checked)
isActive = true;
else
isActive = false;
string SqlStr = "INSERT INTO [LBX_Portal_AccountNumbers] ([AccountNumber], [Site], [Active])";
SqlStr += " VALUES ('" + txtAccountNumber.Text + "'" + ", '" + SiteName + "'" + ", '" + isActive + "')";
SqlDataSource1.InsertCommand = SqlStr;
SqlDataSource1.Insert();
}
if (e.CommandName == "Update")
{
GridEditFormItem gridEditFormItem = (GridEditFormItem)e.Item;
Label lblID = (Label)gridEditFormItem.FindControl("lblID");
TextBox txtAccountNumber = (TextBox)gridEditFormItem.FindControl("txtAccountNumber");
CheckBox cbActive = (CheckBox)gridEditFormItem.FindControl("cbActive");
bool isActive = false;
if (cbActive.Checked)
isActive = true;
else
isActive = false;
string SqlStr = "UPDATE [LBX_Portal_AccountNumbers] SET [AccountNumber] = '" + txtAccountNumber.Text;
SqlStr += "', [Active] = '" + isActive + "' WHERE [ID] = " + lblID.Text;
SqlDataSource1.UpdateCommand = SqlStr;
SqlDataSource1.Update();
}
}

Categories

Resources