protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "AddRow")
{
GetData();
dt.Rows.Add("", "", "", "", "");
Repeater1.DataSource = dt;
Repeater1.DataBind();
return;
}
if (e.CommandName == "UpdateDatabase")
{
try
{
string SQLIns = "";
string newInvyNum = TxtHInvyNum.Text;
string newInvyDate = InvyDate.Text;
string newSite = Site.Text;
string newItemId = ((TextBox)e.Item.FindControl("ItemId")).Text;
if (newItemId == "")
{
newItemId = ((DropDownList)e.Item.FindControl("ddItemId")).SelectedValue;
}
string newItemName = ((TextBox)e.Item.FindControl("ItemName")).Text;
if (newItemName == "")
{
newItemName = ((DropDownList)e.Item.FindControl("ddItemName")).SelectedValue;
}
string newQty = ((TextBox)e.Item.FindControl("Qnty")).Text;
//if (newQty == "")
//{
// newQty = ((DropDownList)e.Item.FindControl("Qnty")).SelectedValue;
//}
Int32 newNumQty = Convert.ToInt32(newQty);
string newCost = ((TextBox)e.Item.FindControl("Cost")).Text;
if (newCost == "")
{
newCost = ((DropDownList)e.Item.FindControl("ddCost")).SelectedValue;
}
Int32 Orgnl_Qty;
//--- Check for the same item already exists...
string SQL_verify = "";
SQL_verify = "select ItemId,Qty from IC_Inventory_T where Invy_Num = '" + newInvyNum + "' and ItemId = '" + newItemId + "'";
SqlDataReader ResData;
SqlConnection conn = new SqlConnection(ConString);
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
SqlCommand SelCmd = new SqlCommand(SQL_verify, conn);
ResData = SelCmd.ExecuteReader();
if (ResData.Read())
{
Orgnl_Qty = Convert.ToInt32(ResData["Qty"]);
newNumQty = newNumQty + Orgnl_Qty;
SQLIns = "Update IC_Inventory_T set Qty = '" + newNumQty + "' where Invy_Num = '" + newInvyNum + "' and ItemID = '" + newItemId + "'";
}
else
{
SQLIns = "Insert into IC_Inventory_T (Invy_Num,Invy_Date,SiteID,ItemId,ItemName,Qty,Cost) values ('" + newInvyNum + "','" + newInvyDate + "','" + newSite + "','" + newItemId + "','" + newItemName + "','" + newNumQty + "','" + newCost + "')";
}
ResData.Close();
//-- End of Check for the same item already exists...
conn = new SqlConnection(ConString);
SqlCommand cmd = new SqlCommand(SQLIns, conn);
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
string Str1 = newQty;
string Str2 = newCost;
double Num1, Num2;
bool isNum1 = double.TryParse(Str1, out Num1);
bool isNum2 = double.TryParse(Str2, out Num2);
if ((isNum1) && (isNum2))
{
int temp = cmd.ExecuteNonQuery();
}
else
{
MessageBox.Text = "Qty should be numeric";
}
MessageBox.Text = "";
conn.Close();
}
catch (Exception ex)
{
MessageBox.Text = "Qty should be numeric";
}
}
if (e.CommandName == "UpdateRow")
{
string SQLUpdt = "";
string newInvyNum = TxtHInvyNum.Text;
string newItemId = ((TextBox)e.Item.FindControl("ItemId")).Text;
string newItemName = ((TextBox)e.Item.FindControl("ItemName")).Text;
string newQty = ((TextBox)e.Item.FindControl("Qnty")).Text;
string newCost = ((TextBox)e.Item.FindControl("Cost")).Text;
// Update Line item
SQLUpdt = "Update IC_Inventory_T set Qty = '" + newQty + "' where Invy_Num = '" + newInvyNum + "' and ItemID = '" + newItemId + "'";
SqlConnection conn = new SqlConnection(ConString);
SqlCommand cmd = new SqlCommand(SQLUpdt, conn);
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
try
{
int temp = cmd.ExecuteNonQuery();
MessageBox.Text = "";
}
catch (Exception ex)
{
MessageBox.Text = "Qty should be numeric";
}
conn.Close();
}
if (e.CommandName == "DeleteRow")
{
string SQLDel = "";
string newInvyNum = TxtHInvyNum.Text;
string newItemId = ((TextBox)e.Item.FindControl("ItemId")).Text;
// Delete row
SQLDel = "Delete IC_Inventory_T where Invy_Num = '" + newInvyNum + "' and ItemID = '" + newItemId + "'";
SqlConnection conn = new SqlConnection(ConString);
SqlCommand cmd = new SqlCommand(SQLDel, conn);
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
int temp = cmd.ExecuteNonQuery();
conn.Close();
}
GetData();
dt.Rows.Add("", "", "", "", "");
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
When I populate the same in my code, The repeater does not create any text boxes, When I debug the code, the break point does not hit at the event. Please help me in populating the Repeater in the below UI code:
I know there is a lot of code but I am unable to find the exact error reason. The break point at the same code in presentation(.cs code) does not work. Please help me.
When I populate the same in my code, The repeater does not create any text boxes, When I debug the code, the break point does not hit at the event. Please help me in populating the Repeater in the below UI code:
I have not found your Repeater control in that UI , Do you want to dynamically create the textbox table like Repeater ?
The repeater is to be placed in my code and the textboxes need to appear same as the old aspx code, I placed it and tried but the textboxes does not appear I thought I did some mistake so I have removed it before posting it here. That is why I have just
posted headings in my code. You can place a new repeater. Please look into it.
After migrating to new UI , you keep the same markup and code behind event of Repeater ? Then what is the error , have you debug your application to check whether the DataSource is not null (has record)?
Member
168 Points
497 Posts
Repeater control code to work on...
Nov 06, 2016 07:40 AM|acmedeepak|LINK
Hi All,
I am migrating a project and in the new UI, The repeater is not working. Please help me by looking at the code how to make it work.
My server side code is:
When I populate the same in my code, The repeater does not create any text boxes, When I debug the code, the break point does not hit at the event. Please help me in populating the Repeater in the below UI code:
I know there is a lot of code but I am unable to find the exact error reason. The break point at the same code in presentation(.cs code) does not work. Please help me.
Regards,
Deepak
All-Star
52523 Points
15670 Posts
Re: Repeater control code to work on...
Nov 06, 2016 10:42 AM|oned_gk|LINK
What do you mean not working? Where addrow button?
Suwandi - Non Graduate Programmer
All-Star
18815 Points
3831 Posts
Re: Repeater control code to work on...
Nov 08, 2016 05:11 AM|Nan Yu|LINK
Hi acmedeepak,
I have not found your Repeater control in that UI , Do you want to dynamically create the textbox table like Repeater ?
Best Regards,
Nan Yu
Member
168 Points
497 Posts
Re: Repeater control code to work on...
Nov 08, 2016 06:21 AM|acmedeepak|LINK
Hi Nan Yu,
The repeater is to be placed in my code and the textboxes need to appear same as the old aspx code, I placed it and tried but the textboxes does not appear I thought I did some mistake so I have removed it before posting it here. That is why I have just posted headings in my code. You can place a new repeater. Please look into it.
Regards,
Deepak
All-Star
52523 Points
15670 Posts
Re: Repeater control code to work on...
Nov 08, 2016 06:43 AM|oned_gk|LINK
Place the textboxes inside ItemTemplate and set repeater datasource then call databind() to show the textboxes. Ensure you have data in the datasource
Suwandi - Non Graduate Programmer
Member
168 Points
497 Posts
Re: Repeater control code to work on...
Nov 08, 2016 08:08 AM|acmedeepak|LINK
Hi oned_gk,
can you please give me some code for your explanation. That would help me a lot.
Regards,
Deepak
All-Star
52523 Points
15670 Posts
Re: Repeater control code to work on...
Nov 08, 2016 08:43 AM|oned_gk|LINK
You can see in your first post, the textboxes is inside itemtemplate.
Find another c# code there that call Repeater1.DataBind() usualy in page_load event.
Something like this
If any rows in the datatable dt, you will see the textboxes
Suwandi - Non Graduate Programmer
Member
168 Points
497 Posts
Re: Repeater control code to work on...
Nov 16, 2016 10:31 AM|acmedeepak|LINK
Hi oned_gk,
Sorry for late reply. I am sorry to say that even this sis not work. Please help me in this.
All-Star
18815 Points
3831 Posts
Re: Repeater control code to work on...
Nov 29, 2016 06:51 AM|Nan Yu|LINK
Hi acmedeepak,
After migrating to new UI , you keep the same markup and code behind event of Repeater ? Then what is the error , have you debug your application to check whether the DataSource is not null (has record)?
Best Regards,
Nan Yu
Member
168 Points
497 Posts
Re: Repeater control code to work on...
Nov 29, 2016 07:17 AM|acmedeepak|LINK
Yes, I have checked that. But now, I have placed two repeater controls one to fetch data and the other to insert values. This is working fine for me.
Thanks,
Deepak